/* * BOUCLE D'AFFICHAGE */ bool SceneManager::execute(SDL_Window* window, unsigned int w, unsigned int h) { init3D(w,h); init2D(); initSounds(); unsigned int debut ,fin; /* VARIABLES DE GESTION DU TEMPS */ float period = 1.0 / FPS_LIMIT,fps,time; while(!m_input.terminer()) /* BOUCLE D'EXECUTION */ { debut = SDL_GetTicks(); /* ON RELEVE LE TEMPS DE DEBUT DE BOUCLE */ onPreRender(); /* ON MET À JOUR LES MODELES DYNAMIQUES */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* NETTOYAGE DE LA FENETRE */ m_input.update(); /* MISE A JOUR DES EVENEMENTS */ updateCameras(); /* MISE À JOUR DES CAMERAS */ if(m_input.getKey(SDL_SCANCODE_ESCAPE)) break; /* QUITTER EN APPUYANT SUR ESPACE */ if(m_input.getKeyRelease(SDL_SCANCODE_V)) changeCamera(); /* CHANGER DE CAMERA EN APPUYANT SUR ESPACE */ if(m_input.getKeyRelease(SDL_SCANCODE_SPACE)) m_soundMgr.playEffect("laser",127/2); drawAll(); /* AFFICHAGE DE TOUS LES MODELES DU MONDE 3D */ SDL_GL_SwapWindow(window); /* RAFRAICHISSEMENT DE LA FENETRE */ fin = SDL_GetTicks(); /* ON RELEVE LE TEMPS DE FIN DE BOUCLE */ time = (float)(fin - debut); /* ON CALCULE LE TEMPS D'EXECUTION DE LA BOUCLE */ fps = 1000.0/time; /* ON CALCULE LA FREQUENCE MAXIMALE */ std::ostringstream streamTitle; streamTitle << "fps: " << fps; SDL_SetWindowTitle(window,streamTitle.str().c_str()); /* ON AFFICHE LA FREQUENCE COMME TITRE DE LA FENETRE */ if(time < period) SDL_Delay((unsigned int)(period - time)); /* ON LIMITE LA FREQUENCE A 60 FPS */ } printf("toto\n"); return true; }
void RenderPreview::drawPreview() { if (_renderingInProgress) return; // avoid double-entering this method util::ScopedBoolLock lock(_renderingInProgress); glViewport(0, 0, _previewWidth, _previewHeight); // Set up the render and clear the drawing area in any case glDepthMask(GL_TRUE); glClearColor(0.3f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set up the camera Matrix4 projection = getProjectionMatrix(0.1f, 10000, PREVIEW_FOV, _previewWidth, _previewHeight); // Keep the modelview matrix in the volumetest class up to date _volumeTest.setModelView(getModelViewMatrix()); _volumeTest.setProjection(projection); // Pre-Render event if (!onPreRender()) { // a return value of false means to cancel rendering drawTime(); return; } // Front-end render phase, collect OpenGLRenderable objects from the scene getScene()->foreachVisibleNodeInVolume(_volumeTest, _sceneWalker); RenderStateFlags flags = getRenderFlagsFill(); // Launch the back end rendering _renderSystem->render(flags, _volumeTest.GetModelview(), projection); // Give subclasses an opportunity to render their own on-screen stuff onPostRender(); // Draw the render time drawTime(); }