void Game::Create() { // Set the platform ApConfig::SetPlatform( ApPlatform_WinGL ); ApConfig::SetDevice( ApDevice_WIN ); GLFWvidmode dvm; // Initialise GLFW if(!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); } glfwGetDesktopMode(&dvm); project->Init(); // Frame counter and window settings variables int frame = 0; int redBits = 8, greenBits = 8, blueBits = 8; int alphaBits = 8, depthBits = 24, stencilBits = 8; m_width = RsUtil::GetWidth(); m_height = RsUtil::GetHeight(); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); // Create a window if(!glfwOpenWindow(m_width, m_height, redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits, GLFW_WINDOW)) { fprintf(stderr, "Failed to open GLFW window\n"); glfwTerminate(); exit(EXIT_FAILURE); } // Set listeners glfwSetWindowCloseCallback(windowCloseListener); int width, height; GetDesktopResolution(width, height); glfwSetWindowPos((width / 2) - (RsUtil::GetWidth() / 2), (height / 2) - (RsUtil::GetHeight() / 2)); // Cache the window handle int handle = glfwGetWindowParam( -1 ); // Create the game mouse m_gameMouse.Setup( (HWND)handle ); m_gameMouse.CreateOnDevice(); // Create the render system RsImpl::pInstance()->Create(); SdSoundWinGL::CreateManager(); BtTimeDX11::Init(); //glfwOpenWindowHint( GLFW_REFRESH_RATE, 1.0f / 30.0f ); glfwSetWindowTitle( ApConfig::GetTitle() ); // Ensure we can capture the escape key being pressed below glfwEnable(GLFW_STICKY_KEYS); // Enable vertical sync (on cards that support it) glfwSwapInterval(1); // Hide the cursor glfwDisable(GLFW_MOUSE_CURSOR); project->Create(); project->Reset(); do { // Get window size (may be different than the requested size) glfwGetWindowSize(&m_width, &m_height); // Set the window size glViewport(0, 0, m_width, m_height); BtFloat dt = BtTime::GetTick(); BtFloat elapsedTime = BtTime::GetElapsedTimeInSeconds(); BtFloat deltaTime = elapsedTime - m_lastGameLogic; m_lastGameLogic = elapsedTime; // Add the excess m_frameRemainder += deltaTime; // Cap the frame m_frameRemainder = BtClamp(m_frameRemainder, (BtFloat)0, 1.0f); BtBool isExiting = BtFalse; //while( m_frameRemainder >= dt ) { // Update the keys input.Update(); // Update the game logic GameUpdate(); // Remove the dt from the frame remainder m_frameRemainder -= dt; } if((isClosing == BtFalse) && (project->IsClosing() == BtFalse)) { // Render project->Render(); // Render RsImpl::pInstance()->Render(); } // Swap buffers glfwSwapBuffers(); } // Check if the ESC key was pressed or the window was closed while(project->IsClosed() == BtFalse); // Destroy the renderer RsImpl::pInstance()->Destroy(); // Destroy the sound SdSoundWinGL::DestroyManager(); // Remove the game mouse m_gameMouse.RemoveFromDevice(); // Destroy the project project->Destroy(); // Close OpenGL window and terminate GLFW glfwTerminate(); }