#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
HWND hWnd = NULL;
WNDCLASSEX wnd;
MSG msg;
HDC hdc = NULL;
HGLRC hrc = NULL;
LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM);
bool initWindow(HINSTANCE, char *, char *, int, int, int, int);
bool initGL(void);
void killWindow(void);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd)
{
char szClassName[] = TEXT("RZ");
if( !initWindow(hInstance,szClassName,"OpenGL keren euy!!",800,600,16,nShowCmd))
return 0;
while(true)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE) )
{
if(msg.message == WM_QUIT)
{
MessageBox(NULL,"hehe","hahaha",MB_ICONERROR);
::killWindow();
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
//MessageBox(NULL,"hehe","hehe",MB_ICONERROR);
return 0;
}
LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
switch(msg)
{
case WM_KEYDOWN :
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,msg,wparam,lparam);
}
bool initWindow(HINSTANCE hInstance, char *szClassName, char *title, int width, int height, int bits, int nShowCmd)
{
DWORD dwstyle;
DWORD dwExstyle;
RECT winrect;
winrect.top = (long)0;
winrect.bottom = (long)height;
winrect.left = (long)0;
winrect.right =(long)width;
wnd.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wnd.lpfnWndProc = wndProc;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hInstance = hInstance;
wnd.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wnd.hCursor = LoadCursor(NULL,IDC_ARROW);
wnd.hbrBackground = NULL; //(HBRUSH) GetStockObject(WHITE_BRUSH);
wnd.lpszMenuName = NULL;
wnd.lpszClassName = szClassName;
wnd.cbSize = sizeof(WNDCLASSEX);
wnd.hIconSm = NULL;
if( !RegisterClassEx(&wnd) )
{
MessageBox(NULL,"hahaha","gagal men!!",MB_ICONERROR);
return false;
}
DEVMODE dm;
memset(&dm,0,sizeof(dm));
dm.dmSize = sizeof(dm);
dm.dmPelsWidth = width;
dm.dmPelsHeight = height;
dm.dmBitsPerPel = bits;
dm.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if(ChangeDisplaySettings(&dm,CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL )
{
MessageBox(NULL,"hohoho","gagal maning....",MB_ICONERROR);
return false;
}
dwstyle = WS_POPUP;
dwExstyle = WS_EX_APPWINDOW;
AdjustWindowRectEx(&winrect,dwstyle,FALSE,dwExstyle);
hWnd = CreateWindowEx(dwExstyle,szClassName,"openGL keren euy",WS_CLIPSIBLINGS|WS_CLIPCHILDREN|dwstyle,
0,0,winrect.right-winrect.left,winrect.bottom-winrect.top,NULL,NULL,
hInstance,NULL);
if( !hWnd )
{
killWindow();
MessageBox(NULL,"hehehe","gagal lagi men!!!",MB_ICONERROR);
return false;
}
static PIXELFORMATDESCRIPTOR pfd=
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
hdc = GetDC(hWnd);
if( !hdc )
{
killWindow();
MessageBox(NULL,"huahahaha","gagal lagi nih....huaaaaaaaaa....",MB_ICONERROR);
return false;
}
GLuint pixelformat;
pixelformat = ChoosePixelFormat(hdc,&pfd);
if( !pixelformat )
{
killWindow();
MessageBox(NULL,"hihihihi","gagal mulu hiks....",MB_ICONERROR);
return false;
}
if( !SetPixelFormat(hdc,pixelformat,&pfd) )
{
killWindow();
MessageBox(NULL,"hoekhokehoekh....","gagal....",MB_ICONERROR);
return false;
}
hrc = wglCreateContext(hdc);
if( !hrc )
{
killWindow();
MessageBox(NULL,"huhuhuhuhu....","gagal....",MB_ICONERROR);
return false;
}
if( !wglMakeCurrent(hdc,hrc) )
{
killWindow();
MessageBox(NULL,"yeeeeeee....","gagal....",MB_ICONERROR);
return false;
}
ShowWindow(hWnd,SW_SHOW);
SetFocus(hWnd);
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
initGL();
return true;
}
bool initGL(void)
{
//MessageBox(NULL,"tes","testing",MB_ICONERROR);
glShadeModel(GL_SMOOTH);
glClearColor(1.0f,1.0f,0.0f,0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
return true;
}
void killWindow(void)
{
ChangeDisplaySettings(NULL,0);
if( hrc )
{
if(!wglMakeCurrent(NULL,NULL))
{
MessageBox(NULL,"gagal","gagal ah...cape....",MB_ICONERROR);
}
if(!wglDeleteContext(hrc))
{
MessageBox(NULL,"gagal","gagal ah...cape deh....",MB_ICONERROR);
}
hrc = NULL;
}
if( !ReleaseDC(hWnd,hdc))
{
MessageBox(NULL,"gagal","gagal...cape deh ah....",MB_ICONERROR);
hdc = NULL;
}
if( !DestroyWindow(hWnd) )
{
MessageBox(NULL,"huahahaha","gagal men...hiks....",MB_ICONERROR);
hWnd = NULL;
}
}
I wonder if I miss or forget something?
thanks before.
glClear won't work on my program
I just re-started again my openGL study lately, since I haven't touched it for a long time I decided to study it all over again
and I found an annoying problem....I just can't clear the screen buffer with the color I already selected.....(I use fullscreen mode)
here's my code :
being young is a treasure that can''t be valued
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement