void CApp::Run( ) { while( w_Window.isOpen( ) ) { sf::Event event; while( w_Window.pollEvent( event ) ) { switch( event.type ) { case sf::Event::Closed: { w_Window.close( ); break; } } } if( !FrameFunc( ) ) break; RenderFunc( ); w_Window.display( ); } }
//================================================================================================== int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) //================================================================================================== { WNDCLASSEX windowClass; // window class HWND hwnd; // window handle MSG msg; // message bool done; // flag saying when our app is complete // MessageBox(NULL, "LeftButton+Mouse Move : zoom\nRightButton+Mouse Move : pan\nLeftButton+RightButton+Mouse Move : rotate\nESC : Exit\n\nAuthor: Dongsoo Han\nDate:2/20/08\nemail:[email protected]", "How to control camera", MB_OK); g_hInstance = hInstance; // fill out the window class structure windowClass.cbSize = sizeof(WNDCLASSEX); windowClass.style = CS_HREDRAW | CS_VREDRAW; windowClass.lpfnWndProc = WndProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // default icon windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // default arrow windowClass.hbrBackground = NULL; // don't need background windowClass.lpszMenuName = NULL; // no menu windowClass.lpszClassName = g_ClassName; windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // windows logo small icon // register the windows class if (!RegisterClassEx(&windowClass)) return 0; //////////////////////////////////////////////////// // For fullscreen mode //////////////////////////////////////////////////// // if we're in fullscreen mode, set the display up for it if (g_isFullscreen) { // set up the device mode structure DEVMODE screenSettings; memset(&screenSettings,0,sizeof(screenSettings)); screenSettings.dmSize = sizeof(screenSettings); screenSettings.dmPelsWidth = width; // screen width screenSettings.dmPelsHeight = height; // screen height screenSettings.dmBitsPerPel = bits; // bits per pixel screenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; // attempt to switch to the resolution and bit depth we've selected if (ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { // if we can't get fullscreen, let them choose to quit or try windowed mode if (MessageBox(NULL, "Cannot run in the fullscreen mode at the selected resolution\n" "on your video card. Try windowed mode instead?", "OpenGL Game Programming", MB_YESNO | MB_ICONEXCLAMATION) == IDYES) { g_isFullscreen = FALSE; } else { return FALSE; } } } DWORD dwExStyle; DWORD dwStyle; // if we're still in fullscreen mode, set the window style appropriately if (g_isFullscreen) { dwExStyle = WS_EX_APPWINDOW; dwStyle = WS_POPUP; // simple window with no borders or title bar //ShowCursor(FALSE); // hide the cursor for now } else { dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; //dwStyle = WS_POPUP; width = 900; height = 700; } // set up the window we're rendering to so that the top left corner is at (0,0) // and the bottom right corner is (height,width) RECT windowRect; windowRect.left = 0; windowRect.right = (LONG) width; windowRect.top = 0; windowRect.bottom = (LONG) height; // change the size of the rect to account for borders, etc. set by the style AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle); hwnd = CreateWindowEx(dwExStyle, // extended style (LPCTSTR)g_ClassName, // class name (LPCTSTR)g_WindowName, // app name dwStyle | // window style WS_CLIPCHILDREN | // required for WS_CLIPSIBLINGS, // using OpenGL 0, 0, // x,y coordinate windowRect.right - windowRect.left, // width windowRect.bottom - windowRect.top, // height NULL, // handle to parent NULL, // handle to menu hInstance, // application instance NULL); // no extra params if (!hwnd) { KillGLWindow(); MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } if (!(g_hDC = GetDC(hwnd))) { KillGLWindow(); MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; } SetupPixelFormat(g_hDC); // call our pixel format setup function // create rendering context and make it current g_hRC = wglCreateContext(g_hDC); wglMakeCurrent(g_hDC, g_hRC); g_hWnd = hwnd; ShowWindow(hwnd, SW_SHOW); // display the window UpdateWindow(hwnd); // update the window done = false; // intialize the loop condition variable Initialize(); // main message loop while (!done) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) // do we receive a WM_QUIT message? { done = TRUE; // if so, time to quit the application } else { TranslateMessage(&msg); // translate and dispatch to event queue DispatchMessage(&msg); } } else { if(g_bEnd) done = TRUE; if(g_active) RenderFunc(); // display Frame/Second rate.. GetFPS(); glFlush(); SwapBuffers(g_hDC); // bring backbuffer to foreground } } KillGLWindow(); return msg.wParam; }