//Includes and Define's: #include #include #include #define TGGL_WINDOW_CAPTION "OpenGL Template" #define TGGL_WINDOW_CLASS_NAME "TheGeek_OpenGL" #define TGGL_WIDTH 800 #define TGGL_HEIGHT 600 //Function Definitions: LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM); //Globals: char g_szClassName[] = TGGL_WINDOW_CLASS_NAME; HGLRC g_hrc; HDC g_hdc; //Functions: int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ WNDCLASSEX wndclassex; MSG msg; HWND hwnd; PIXELFORMATDESCRIPTOR pfd; int iFormat; RECT rcClient; ZeroMemory(&wndclassex, sizeof(wndclassex)); wndclassex.cbSize = sizeof(WNDCLASSEX); wndclassex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wndclassex.lpfnWndProc = WindowProc; wndclassex.hInstance = hInstance; wndclassex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclassex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wndclassex.hCursor = LoadCursor(NULL, IDC_ARROW); wndclassex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wndclassex.lpszClassName = g_szClassName; if(!RegisterClassEx(&wndclassex)){ char szError[150] = "Line %d: Class registration failed."; sprintf(&szError, szError, __LINE__ - 2); MessageBox(NULL, szError, "Fatal Error", MB_OK | MB_ICONERROR); return 0; } hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, TGGL_WINDOW_CAPTION, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, TGGL_WIDTH, TGGL_HEIGHT, NULL, NULL, hInstance, NULL); if(hwnd == NULL){ char szError[150] = "Line %d: Window creation failed."; sprintf(&szError, szError, __LINE__ - 3); MessageBox(NULL, szError, "Fatal Error", MB_OK | MB_ICONERROR); return 0; } g_hdc = GetDC(hwnd); ZeroMemory(&pfd, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 24; pfd.cDepthBits = 32; pfd.iLayerType = PFD_MAIN_PLANE; iFormat = ChoosePixelFormat(g_hdc, &pfd); SetPixelFormat(g_hdc, iFormat, &pfd); GetClientRect(hwnd, &rcClient); g_hrc = wglCreateContext(g_hdc); wglMakeCurrent(g_hdc, g_hrc); /*glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0, (double)rcClient.right/(double)rcClient.bottom, 1.0, 10.0); glViewport(0, 0, rcClient.right, rcClient.bottom);*/ ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0) > 0){ TranslateMessage(&msg); DispatchMessage(&msg); } wglMakeCurrent(NULL, NULL); wglDeleteContext(g_hrc); ReleaseDC(hwnd, g_hdc); return msg.wParam; } LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){ switch(msg){ case WM_DESTROY: PostQuitMessage(0); break; case WM_PAINT: glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClear(GL_COLOR_BUFFER_BIT); glBegin( GL_TRIANGLES ); glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f ); glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f ); glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f ); glEnd(); SwapBuffers(g_hdc); break; /*case WM_ERASEBKGND: return TRUE; break;*/ } }