void renderLoop(sf::Window & window) { sf::Clock time; WorldState state; while (state.isRunning()) { this->handleEvents(window, state); state.timeStep( time.getElapsedTime().asSeconds() ); engine.display(state); window.display(); } window.close(); }
GLBox() { //sf::err().rdbuf(NULL); //hide errors #ifdef __APPLE__ //int nullFD = open("/dev/null", O_WRONLY); //int oldFD = dup(2); // Duplicate the old file descriptor, so it can be restored //dup2(nullFD, 2); // Redirect #endif sf::VideoMode mode(RESOLUTION, RESOLUTION, 32); #ifdef __linux__ sf::ContextSettings settings(32, 0, 0, 3, 3); #else sf::ContextSettings settings(0, 0, 0, 3, 3); #endif sf::Window window(mode, "glver", sf::Style::Default, settings); float ver = getVer(); #ifdef __APPLE__ //dup2(oldFD, 2); // Redirect back //close(oldFD); // Not needed anymore #endif if( ver < 1.0f ) { printf("OpenGL is not supported.\n"); exit(1); } printf("OpenGL version %.1f is supported.\n", ver); sf::Clock time; WorldState state; graphicsInit(); while (state.isRunning()) { this->handleEvents(window, state); state.timeStep( time.getElapsedTime().asSeconds() ); display(state); window.display(); } window.close(); }
Program4() { getWindowContext(); WorldState state; render.init(state); previousPos = glm::vec2(0); buttonDown[0]=false; buttonDown[1]=false; buttonDown[2]=false; sf::Clock c; float lastFrame = c.restart().asSeconds(); float lastPrint = lastFrame; float targetFrameTime = 1.0f/(float)TARGET_FPS; while (state.isRunning()) { App->setActive(); float currentTime = c.getElapsedTime().asSeconds(); float sinceLastFrame = currentTime - lastFrame; float sleepTime = targetFrameTime - sinceLastFrame; if(sleepTime > 0) sf::sleep(sf::seconds(sleepTime)); currentTime = c.getElapsedTime().asSeconds(); lastFrame = currentTime; float sinceLastPrint = currentTime - lastPrint; handleEvents(state, render); state.timeStep(currentTime); if(sinceLastPrint > PRINT_FPS_INTERVAL) { lastPrint = currentTime; state.printFPS(); } render.display(state); App->display(); } }