#include #include #include #include LRESULT CALLBACK WinRun(HWND, UINT, WPARAM, LPARAM); void EnableOpenGL(HWND); char szClassName[] = "W12"; int WINAPI WinMain(HINSTANCE inst, HINSTANCE instPrev, LPSTR lArg, int showConst) { HWND win; MSG messages; WNDCLASSEX wincl; wincl.hInstance = inst; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WinRun; wincl.style = CS_HREDRAW | CS_VREDRAW; wincl.cbSize = sizeof (WNDCLASSEX); wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND; if (!RegisterClassEx(&wincl)) { return 0; } win = CreateWindowEx( 0, szClassName, "Hello, 3D!", WS_POPUPWINDOW, 0, 0, 640, 480, HWND_DESKTOP, NULL, inst, NULL ); SendMessage(win, WM_SYSCOMMAND, SC_MAXIMIZE, 0); ShowWindow(win, showConst); while (GetMessage(&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); } return messages.wParam; } LRESULT CALLBACK WinRun(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_PAINT: EnableOpenGL(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; } void EnableOpenGL(HWND hWnd) { HDC *hDC; HGLRC *hRC; PIXELFORMATDESCRIPTOR pfd; int iFormat; *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 = 16; pfd.iLayerType = PFD_MAIN_PLANE; iFormat = ChoosePixelFormat(*hDC, &pfd); SetPixelFormat(*hDC, iFormat, &pfd); *hRC = wglCreateContext(*hDC); wglMakeCurrent(*hDC, *hRC); } void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC) { wglMakeCurrent(NULL, NULL); wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); }