//************************************************************************************************************* void UninitGL() { if( !uninited ) { uninited = true; // release context if( hrc ) { UninitScene(); if( !wglMakeCurrent(hdc, NULL) ) MYERROR("Could not release context"); if( !wglDeleteContext(hrc) ) MYERROR("Could not delete context"); hrc = NULL; } if( hdc && !ReleaseDC(hwnd, hdc) ) MYERROR("Could not release device context"); hdc = NULL; DestroyWindow(hwnd); } }
//************************************************************************************************************* int main(int argc, char* argv[]) { ReadResolutionFile(); LARGE_INTEGER qwTicksPerSec = { 0, 0 }; LARGE_INTEGER qwTime; LONGLONG tickspersec; double last, current; double delta, accum = 0; WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_OWNDC, (WNDPROC)WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, LoadCursor(0, IDC_ARROW), NULL, NULL, "TestClass", NULL }; RegisterClassEx(&wc); SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0); RECT rect = { 0, 0, screenwidth, screenheight }; DWORD style = WS_CLIPCHILDREN|WS_CLIPSIBLINGS; // windowed mode style |= WS_SYSMENU|WS_BORDER|WS_CAPTION; Adjust(rect, screenwidth, screenheight, style, 0); hwnd = CreateWindowA("TestClass", TITLE, style, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, wc.hInstance, NULL); if( !hwnd ) { MYERROR("Could not create window"); goto _end; } if( FAILED(InitDirect3D(hwnd)) ) { MYERROR("Failed to initialize Direct3D"); goto _end; } if( FAILED(InitScene()) ) { MYERROR("Failed to initialize scene"); goto _end; } ShowWindow(hwnd, SW_SHOWDEFAULT); UpdateWindow(hwnd); MSG msg; ZeroMemory(&msg, sizeof(msg)); POINT p; GetCursorPos(&p); ScreenToClient(hwnd, &p); // timer QueryPerformanceFrequency(&qwTicksPerSec); tickspersec = qwTicksPerSec.QuadPart; QueryPerformanceCounter(&qwTime); last = (qwTime.QuadPart % tickspersec) / (double)tickspersec; while( msg.message != WM_QUIT ) { QueryPerformanceCounter(&qwTime); current = (qwTime.QuadPart % tickspersec) / (double)tickspersec; if (current < last) delta = ((1.0 + current) - last); else delta = (current - last); last = current; accum += delta; mousedx = mousedy = 0; while( accum > 0.0333f ) { accum -= 0.0333f; while( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) ) { TranslateMessage(&msg); DispatchMessage(&msg); } Update(0.0333f); } if( msg.message != WM_QUIT ) Render((float)accum / 0.0333f, (float)delta); } _end: UninitScene(); if( device ) { ULONG rc = device->Release(); if( rc > 0 ) MYERROR("You forgot to release something"); } if( direct3d ) direct3d->Release(); UnregisterClass("TestClass", wc.hInstance); _CrtDumpMemoryLeaks(); #ifdef _DEBUG system("pause"); #endif return 0; }