virtual void RenderSceneCB() { m_pGameCamera->OnRender(); m_pipeline.SetCamera(*m_pGameCamera); GeometryPass(); SSAOPass(); BlurPass(); LightingPass(); RenderFPS(); CalcFPS(); OgldevBackendSwapBuffers(); }
virtual void RenderSceneCB() { CalcFPS(); m_scale += 0.05f; m_pGameCamera->OnRender(); DSGeometryPass(); BeginLightPasses(); DSPointLightsPass(); DSDirectionalLightPass(); RenderFPS(); glutSwapBuffers(); }
virtual void RenderSceneCB() { CalcFPS(); m_scale += 0.005f; m_pGameCamera->OnRender(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); m_pEffect->Enable(); m_pEffect->SetEyeWorldPos(m_pGameCamera->GetPos()); Pipeline p; p.SetCamera(m_pGameCamera->GetPos(), m_pGameCamera->GetTarget(), m_pGameCamera->GetUp()); p.SetPerspectiveProj(m_persProjInfo); p.Rotate(0.0f, 90.0f, 0.0f); p.Scale(0.005f, 0.005f, 0.005f); Matrix4f WVPMatrics[NUM_INSTANCES]; Matrix4f WorldMatrices[NUM_INSTANCES]; for (unsigned int i = 0 ; i < NUM_INSTANCES ; i++) { Vector3f Pos(m_positions[i]); Pos.y += sinf(m_scale) * m_velocity[i]; p.WorldPos(Pos); WVPMatrics[i] = p.GetWVPTrans().Transpose(); WorldMatrices[i] = p.GetWorldTrans().Transpose(); } m_pMesh->Render(NUM_INSTANCES, WVPMatrics, WorldMatrices); RenderFPS(); glutSwapBuffers(); }
void Update() { CalcFPS(); switch (g_iGameState) { case 1: { g_pInput->Update(); g_pStartUI->Update(g_iGameState,g_dElapsedTime); } break; case 2: { if (g_iGameState != g_iOldState) { Init(); g_iOldState = g_iGameState; } else { g_pInput->Update(); g_pScene->Update(g_dElapsedTime,g_iFPS); } } break; default: break; } if (g_pInput->KeyDown(DIK_Z)) { if (g_bFillMode) g_bFillMode = false; else g_bFillMode = true; } }
/** \brief Initialize the game core. * * Initialize SDL, load required files, start the main game loop. */ int GameCore::Init(int w, int h) { bool Escape = false; width = w; height = h; if (SDL_Init(SDL_INIT_EVERYTHING) == -1) return 1; // TODO: This might need to be changed to SDL_SWSURFACE for speed. screen = SDL_SetVideoMode(w, h, 0, SDL_HWSURFACE | SDL_DOUBLEBUF); if (screen == NULL) return 1; SDL_WM_SetCaption("The Adventures Of Knil", NULL); GameDraw::screen = screen; ga.Init(); ga.PlayMusic("Sounds/Tank Battle.mp3"); GamePlayer gp; gp.loadKCA("CharAnis\\modernbody.kca"); gp.setPos(368, 528); GameDialog dialog; // Test load a map gm.Init(&gp, &dialog); if (!gm.LoadMap("Maps\\HouseMap.map")) { return ErrorScreen(); } gm.drawMap(); while (!quit) { // Update GameInput. Check if we should quit. gi.Update(); if (gi.GetKeyState(SDLK_ESCAPE)) { if (!Escape && dialog.isActive()) { Escape = true; dialog.Close(); } } else { Escape = false; } if (gi.GetQuit() || (gi.GetKeyState(SDLK_ESCAPE) && !Escape)) { quit = true; break; } if (!dialog.isActive() && gi.GetKeyState(SDLK_F1)) { dialog.clearPages(); dialog.addPage(HELPTEXT1); dialog.addPage(HELPTEXT2); dialog.addPage(HELPTEXT3); dialog.addPage(HELPTEXT4); dialog.ShowPage(0); } // Calculate FPS and frame time int dt = CalcFPS(); gp.tick(dt); if (!dialog.isActive()) gp.handleInput(&gi, &gm); gm.handleInput(&gi); gm.runScripts(dt); dialog.handleInput(&gi); // Move screen with player if (gp.getX() > (width / 2)) { mapOffX = gp.getX() - (width / 2); if ((mapOffX + width) > (gm.GetWidth() * 16) ) { mapOffX = gm.GetWidth() * 16 - width; } } else mapOffX = 0; if (gp.getY() > (height / 2)) { mapOffY = gp.getY() - (height / 2); if ((mapOffY + height) > (gm.GetHeight() * 16) ) { mapOffY = gm.GetHeight() * 16 - height; } } else mapOffY = 0; SDL_Rect clip; clip.x = mapOffX; clip.y = mapOffY; clip.w = width; clip.h = height; GameDraw::SurfaceClear(screen, SDL_MapRGB(screen->format, 0, 0, 0)); GameDraw::RenderToSurface(0, 0, gm.GetMapBottom(), screen, &clip); // Render NPCs on Layer 0 vector<GameNPC*>* mapNPC = gm.getNPCList(); for (unsigned int i = 0; i < mapNPC->size(); i++) { if (mapNPC->at(i)->GetLayer()) continue; if (!mapNPC->at(i)->GetSurface()) continue; SDL_Rect r = mapNPC->at(i)->GetBlock(); r.x -= mapOffX; r.y -= mapOffY; int npcx = mapNPC->at(i)->GetX() - mapOffX; int npcy = mapNPC->at(i)->GetY() - mapOffY; GameDraw::RenderToSurface(npcx, npcy, mapNPC->at(i)->GetSurface(), screen, &mapNPC->at(i)->GetSurface()->clip_rect); } // Render Player GameDraw::RenderToSurface(gp.getX() - mapOffX, gp.getY() - mapOffY, gp.getSurface(), screen, &gp.getSurface()->clip_rect); // Render NPCs on Layer != 0 for (unsigned int i = 0; i < mapNPC->size(); i++) { if (!mapNPC->at(i)->GetLayer()) continue; if (!mapNPC->at(i)->GetSurface()) continue; SDL_Rect r = mapNPC->at(i)->GetBlock(); r.x -= mapOffX; r.y -= mapOffY; int npcx = mapNPC->at(i)->GetX() - mapOffX; int npcy = mapNPC->at(i)->GetY() - mapOffY; GameDraw::RenderToSurface(npcx, npcy, mapNPC->at(i)->GetSurface(), screen, &mapNPC->at(i)->GetSurface()->clip_rect); } // If there is an active dialog, draw it in the middle of the screen, at the bottom. if (dialog.isActive()) GameDraw::RenderToSurface(width / 2 - GameDialog::DIALOGWIDTH / 2, height - GameDialog::DIALOGHEIGHT - 30, dialog.getSurface(), screen, &dialog.getSurface()->clip_rect); GameDraw::FlipToScreen(screen); } return 0; }
int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { MSG msg; // Windows Message Structure BOOL done=FALSE; // Bool Variable To Exit Loop // Ask The User Which Screen Mode They Prefer if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO) { fullscreen=FALSE; // Windowed Mode } // Create Our OpenGL Window if (!CreateGLWindow("JelloPhysic Test",800,600,16,fullscreen)) { return 0; // Quit If Window Was Not Created } while(!done) // Loop That Runs While done=FALSE { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting? { if (msg.message==WM_QUIT) // Have We Received A Quit Message? { done=TRUE; // If So done=TRUE } else // If Not, Deal With Window Messages { TranslateMessage(&msg); // Translate The Message DispatchMessage(&msg); // Dispatch The Message } } else // If There Are No Messages { // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene() if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received? { done=TRUE; // ESC or DrawGLScene Signalled A Quit } else // Not Time To Quit, Update Screen { SwapBuffers(hDC); // Swap Buffers (Double Buffering) } if(keys[VK_F2]) { if(springy == true) { //add pressure body SpringBody *sBody = new SpringBody(springI, 1.0f, 150.0f, 5.0f, 300.0f, 15.0f, Vector2(-5.0f, -5.0f), 0.0f, Vector2::One,false); sBody->addInternalSpring(0, 14, 300.0f, 10.0f); sBody->addInternalSpring(1, 14, 300.0f, 10.0f); sBody->addInternalSpring(1, 15, 300.0f, 10.0f); sBody->addInternalSpring(1, 5, 300.0f, 10.0f); sBody->addInternalSpring(2, 14, 300.0f, 10.0f); sBody->addInternalSpring(2, 5, 300.0f, 10.0f); sBody->addInternalSpring(1, 5, 300.0f, 10.0f); sBody->addInternalSpring(14, 5, 300.0f, 10.0f); sBody->addInternalSpring(2, 4, 300.0f, 10.0f); sBody->addInternalSpring(3, 5, 300.0f, 10.0f); sBody->addInternalSpring(14, 6, 300.0f, 10.0f); sBody->addInternalSpring(5, 13, 300.0f, 10.0f); sBody->addInternalSpring(13, 6, 300.0f, 10.0f); sBody->addInternalSpring(12, 10, 300.0f, 10.0f); sBody->addInternalSpring(13, 11, 300.0f, 10.0f); sBody->addInternalSpring(13, 10, 300.0f, 10.0f); sBody->addInternalSpring(13, 9, 300.0f, 10.0f); sBody->addInternalSpring(6, 10, 300.0f, 10.0f); sBody->addInternalSpring(6, 9, 300.0f, 10.0f); sBody->addInternalSpring(6, 8, 300.0f, 10.0f); sBody->addInternalSpring(7, 9, 300.0f, 10.0f); // polygons! sBody->addTriangle(0, 15, 1); sBody->addTriangle(1, 15, 14); sBody->addTriangle(1, 14, 5); sBody->addTriangle(1, 5, 2); sBody->addTriangle(2, 5, 4); sBody->addTriangle(2, 4, 3); sBody->addTriangle(14, 13, 6); sBody->addTriangle(14, 6, 5); sBody->addTriangle(12, 11, 10); sBody->addTriangle(12, 10, 13); sBody->addTriangle(13, 10, 9); sBody->addTriangle(13, 9, 6); sBody->addTriangle(6, 9, 8); sBody->addTriangle(6, 8, 7); sBody->finalizeTriangles(); mWorld->addBody(sBody); springBodies.push_back(sBody); springy = false; } } if(keys[VK_F3]) { if(pressure == true) { PressureBody * pressureBody = new PressureBody(ball, 1.0f, 50.0f, 10.0f, 1.0f, 300.0f, 20.0f, Vector2(0, -10), 0, Vector2(0.5f,0.5f),false); mWorld->addBody(pressureBody); pressureBodies.push_back(pressureBody); pressure = false; } } if(keys[VK_F4]) { if(boxy == true) { FallingBody *fBody = new FallingBody(shape,1.0f, 300.0f, 10.0f,Vector2(0.0f, -5.0f),0.0f , Vector2(2.0f,2.0f),false); fBody->addInternalSpring(0, 2, 400.0f, 12.0f); fBody->addInternalSpring(1, 3, 400.0f, 12.0f); mWorld->addBody(fBody); fallingBodies.push_back(fBody); boxy = false; } } //calc fps CalcFPS(); } } // Shutdown KillGLWindow(); // Kill The Window return (msg.wParam); // Exit The Program }
//############################################################################################# // Render de la scene //############################################################################################# bool C_ARX_Carte::Render(void) { if(!this->background) return false; CalcFPS(); GRenderer->Clear(Renderer::ColorBuffer | Renderer::DepthBuffer); GRenderer->BeginScene(); int depx = (int)(this->posx * this->background->Xmul); if(depx<0) depx=0; int depz=(int)(this->posz*this->background->Zmul); if(depz<0) depz=0; int endx=this->widthrender/this->nbpixels; int endz=this->heightrender/this->nbpixels; endx+=depx; if(endx>this->background->Xsize) endx=this->background->Xsize; endz+=depz; if(endz>this->background->Zsize) endz=this->background->Zsize; float yecran=0.f; float zsub=((float)depz)*this->background->Zdiv; for(int j=depz; j<endz; j++) { float xecran=0.f; float xsub=((float)depx)*this->background->Xdiv; for(int i=depx; i<endx; i++) { EERIE_BKG_INFO *eg=&this->background->Backg[i+j*this->background->Xsize]; for(int lll=0; lll<eg->nbpoly; lll++) { EERIEPOLY *ep=&eg->polydata[lll]; if (ep) { if(ep->type&POLY_IGNORE) continue; if(ep->type&POLY_TRANS) continue; int nb; if(ep->type&POLY_QUAD) nb=4; else nb=3; for(int k=0; k<nb; k++) { ep->tv[k].p.x=xecran+(ep->v[k].p.x-xsub)*this->ecx; ep->tv[k].p.y=yecran+(ep->v[k].p.z-zsub)*this->ecz; ep->tv[k].rhw=(1.f/ep->v[k].p.y); if (ep->tv[k].rhw<0.f) ep->tv[k].rhw=0.f; if (ep->tv[k].rhw>1.f) ep->tv[k].rhw=1.f; ep->tv[k].p.z=1.f-ep->tv[k].rhw; if (ep->tv[k].p.z<0.f) ep->tv[k].p.z=0.f; if (ep->tv[k].p.z>1.f) ep->tv[k].p.z=1.f; ep->tv[k].color = 0xFFFFFFFF; ep->tv[k].uv = ep->v[k].uv; } if(ep->tex) GRenderer->SetTexture(0, ep->tex); else GRenderer->ResetTexture(0); EERIEDRAWPRIM(Renderer::TriangleStrip, ep->tv, nb, true); } } xsub+=this->background->Xdiv; xecran+=(float)this->nbpixels; } zsub+=this->background->Zdiv; yecran+=(float)this->nbpixels; } return true; }
void CMyWindow::OnIdle() { static float rotate = 0.0f; static DWORD prev = GetTickCount(); DWORD time, span; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(1, 1, 1, 1); glEnable(GL_DEPTH_TEST); //glEnable(GL_CULL_FACE); //glCullFace(GL_CW); glEnable(GL_BLEND); glEnable(GL_POLYGON_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glShadeModel(GL_SMOOTH); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBegin(GL_TRIANGLES); { glColor3f(0.3f, 0.3f, 0.3f); glVertex3f(0.0f, 1.0f, 0.8f); glColor3f(0.3f, 0.3f, 0.3f); glVertex3f(-0.7f, -0.87f, 0.8f); glColor3f(0.3f, 0.3f, 0.3f); glVertex3f(0.7f, -0.87f, 0.8f); } glEnd(); glRotatef(rotate, 0.8f, 1, 0.5f); time = GetTickCount(); span = time - prev; if (span >= 100) { rotate += 0.0125f * (span / 100); prev += span % 100; } struct Vertex { float vertex[3]; float color[4]; }; static Vertex data[] = { { { -0.5f, 0.5f, -0.5f }, { 0.0f, 0.0f, 1.0f, 0.6f } }, { { 0.5f, 0.5f, -0.5f }, { 0.0f, 1.0f, 0.0f, 0.6f } }, { { 0.5f, 0.5f, 0.5f }, { 0.0f, 1.0f, 1.0f, 0.6f } }, { { -0.5f, 0.5f, 0.5f }, { 1.0f, 0.0f, 0.0f, 0.6f } }, { { -0.5f, -0.5f, -0.5f }, { 1.0f, 0.0f, 1.0f, 0.6f } }, { { 0.5f, -0.5f, -0.5f }, { 1.0f, 1.0f, 0.0f, 0.6f } }, { { 0.5f, -0.5f, 0.5f }, { 1.0f, 1.0f, 1.0f, 0.6f } }, { { -0.5f, -0.5f, 0.5f }, { 0.0f, 0.0f, 0.0f, 0.6f } } }; static int index[][3] = { { 3, 1, 0 }, { 2, 1, 3 }, { 0, 5, 4 }, { 1, 5, 0 }, { 3, 4, 7 }, { 0, 4, 3 }, { 1, 6, 5 }, { 2, 6, 1 }, { 2, 7, 6 }, { 3, 7, 2 }, { 6, 4, 5 }, { 7, 4, 6 } }; for (int *ar : index) { glBegin(GL_TRIANGLES); { for (int *p = ar; p < ar + 3; p++) { glColor4fv(data[*p].color); glVertex3fv(data[*p].vertex); } } glEnd(); } SwapBuf(); TCHAR buf[1024]; wsprintf(buf, L"FPS : %u", GetFPS()); HDC hdc = GetDC(*this); TextOut(hdc, 0, 0, buf); ReleaseDC(*this, hdc); unsigned fps = CalcFPS(); //if (fps >= 300) // Sleep(1); }
void FullDraw() { if(need_reload_volume_data) { UploadVD(CT::GetCurDataID()); need_reload_volume_data=0; } CalcFPS(); InitGL(); if(IsFastView())cam.SetupProjection(CAMERA_ANGLE,Z_NEAR,Z_FAR,0,0,width/fast_res,height/fast_res); else cam.SetupProjection(CAMERA_ANGLE,Z_NEAR,Z_FAR,0,0,width,height); //InitInterlace(); if(need_InitInterlace)InitInterlace_(); //SetLight(cam.GetPosition()); switch(stereo_on) { case 0: { CT::gl_back_buffer_target = GL_BACK; // if(IsFastView())rtt_Begin(0); //glClearColor(0,0,0,0); if(need_rerender)glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // if(IsFastView())rtt_End(); DrawScene(); } break; case 1: CT::gl_back_buffer_target = GL_BACK; { //vec3 ps = cam.GetCenter(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(CT::RenderingType==2) { is_left=!is_left; DrawScene(); glFlush(); }else { glClear(GL_ACCUM_BUFFER_BIT); is_left=0; DrawScene(); //glFlush(); glAccum(GL_LOAD, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); is_left=1; DrawScene(); //glFlush(); glAccum(GL_ACCUM, 1.0f); glAccum(GL_RETURN, 1.0f); } } break; case 2: { CT::gl_back_buffer_target = GL_BACK; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(CT::RenderingType==2) { is_left=!is_left; cam.SetupProjection(CAMERA_ANGLE,Z_NEAR,Z_FAR,is_left*width/2,0,width/2,height); DrawScene(); glFlush(); }else { glClear(GL_ACCUM_BUFFER_BIT); is_left=0; cam.SetupProjection(CAMERA_ANGLE,Z_NEAR,Z_FAR,is_left*width/2,0,width/2,height); DrawScene(); //glFlush(); glAccum(GL_LOAD, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); is_left=1; cam.SetupProjection(CAMERA_ANGLE,Z_NEAR,Z_FAR,is_left*width/2,0,width/2,height); DrawScene(); //glFlush(); glAccum(GL_ACCUM, 1.0f); glAccum(GL_RETURN, 1.0f); } /* glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); vec3 ps = cam.GetCenter(); cam.SetCenter(ps-cam.GetLeft()*stereo_step); cam.SetupProjection(CAMERA_ANGLE,Z_NEAR,Z_FAR,0,0,width/2,height); DrawScene(); cam.SetCenter(ps+cam.GetLeft()*stereo_step); cam.SetupProjection(CAMERA_ANGLE,Z_NEAR,Z_FAR,width/2,0,width/2,height); DrawScene(); cam.SetCenter(ps); */ } break; case 3: { CT::gl_back_buffer_target = GL_BACK; glEnable(GL_STENCIL_TEST); glStencilFunc(GL_EQUAL, 0, 1); is_left=0; DrawScene(); glStencilFunc(GL_EQUAL, 1, 1); is_left=1; DrawScene(); glDisable(GL_STENCIL_TEST); } break; case 4: { is_left=0; CT::gl_back_buffer_target = GL_BACK_LEFT; glDrawBuffer(CT::gl_back_buffer_target); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear color and depth buffers DrawScene(); is_left=1; CT::gl_back_buffer_target = GL_BACK_RIGHT; glDrawBuffer(CT::gl_back_buffer_target); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear color and depth buffers DrawScene(); } break; } }
bool Main::loop() { WindowDesc mainWindowDesc = WindowDesc::getDefault(); mainWindowDesc.title = cfgWindowTitle; mainWindowDesc.width = cfgWindowWidth; mainWindowDesc.height = cfgWindowHeight; mainWindowDesc.posX = cfgWindowPosX; mainWindowDesc.posY = cfgWindowPosY; mainWindowDesc.debug_context = cfgDebugContext ? 1 : 0; mainWindowDesc.forward_compat = cfgFwdCompatContext ? 1 : 0; mainWindowDesc.major_version = cfgOpenglMajorVersion; mainWindowDesc.minor_version = cfgOpenglMinorVersion; mainWindowDesc.red_bits = cfgOpenglBackbufferRedBits; mainWindowDesc.green_bits = cfgOpenglBackbufferGreenBits; mainWindowDesc.blue_bits = cfgOpenglBackbufferBlueBits; mainWindowDesc.alpha_bits = cfgOpenglBackbufferAlphaBits; mainWindowDesc.depth_bits = cfgOpenglBackbufferDepthBits; mainWindowDesc.stencil_bits = cfgOpenglBackbufferStencilBits; mainWindowDesc.accum_bits = 0; mainWindowDesc.aux_buffers = 0; mainWindowDesc.samples = 1; mainWindowDesc.refresh_rate = 0; //create a window Window * mainWindow = m_WindowSystem->openWindow(mainWindowDesc); if (!mainWindow) return false; //read back values m_RenderSystem->attachWindow(mainWindow); // /// INPUT EXAMPLE int32 inputIndex = m_InputSystem->attachWindow(mainWindow); if (inputIndex == -1) return false; InputDevice inputDevice; inputDevice.connectDevice(m_InputSystem->getKeyboard()); inputDevice.connectDevice(m_InputSystem->getMouse()); //device.connectDevice(m_InputSystem->getJoystick()); /* Trigger::ID trggrReturn = device.addTrigger(&Key::WentUp<Keyboard::Code::key_RETURN>); Trigger::ID trggrLeftClick = device.addTrigger(&MouseButton::WentUp<Mouse::Button::Left>); //Trigger::ID trggrXPressed = device.addTrigger(&JoystickButton::WentDown<Joystick::Button::Button1>); Trigger::ID trggrConfigKey = device.addTrigger(&ConfigKey::WentDown<&cfgActionKey>); Trigger::ID trggrChoord = device.addTrigger( &And< &Or< &Key::IsPressed<Keyboard::Code::key_LSHIFT>, &Key::IsPressed<Keyboard::Code::key_RSHIFT> >, &And< &Key::IsReleased<Keyboard::Code::key_LCONTROL>, &Key::IsReleased<Keyboard::Code::key_RCONTROL> >, &Key::WentDown<Keyboard::Code::key_A> >); */ /* trggrChoord = device.addTrigger( &Map< &Key::IsPressed<Keyboard::Code::key_LSHIFT>, &Key::IsPressed<Keyboard::Code::key_RSHIFT> > ); //*/ ///END INPUT EXAMPLE // /// build a simple game object GameObject* obj = m_ObjectSystem->createObject(); obj->addComponent<InputWASDComponent>(inputDevice); obj->setPosition(glm::vec3()); obj->lookInDirection(GameObject::FORWARD_DIRECTION, GameObject::UP_DIRECTION); //create a camera and attach it to the object Camera cam; cam.attachToObject(obj); cam.setViewportSize(glm::uvec2(cfgWindowWidth, cfgWindowHeight)); m_RenderSystem->getScene()->setCamera(&cam); cam.update(); glm::mat4 viewMatrix = cam.getViewMatrix(); # if DEBUG_BUILD || SHOW_DEBUG_TITLE const ansichar* dbg_WindowTitleTemplate = "DEBUG: CurrentFPS (%.3f)"; ansichar dbg_WindowTitle[128]; float32 accumDt = 0.0, lastTitleUpdate = 0.0; # endif typedef std::chrono::high_resolution_clock clock; typedef clock::time_point time_point; typedef clock::duration time_duration; time_point start = clock::now(), current = start, last = start; while (m_Running) { current = clock::now(); float32 dt = float32(std::chrono::duration_cast<std::chrono::microseconds>(current - last).count()); float32 fps = CalcFPS(dt); //get the fps estimation # if DEBUG_BUILD || SHOW_DEBUG_TITLE accumDt += dt; if (accumDt - lastTitleUpdate > oneSecond / 2) { std::sprintf(dbg_WindowTitle, dbg_WindowTitleTemplate, fps); lastTitleUpdate = accumDt; mainWindow->setTitle(dbg_WindowTitle); } # endif m_PackageSystem->tick(dt); //tick the package system (may reimport new packages) if (!m_WindowSystem->tick(dt)) { m_Running = false; } if (!m_InputSystem->tick(dt)) { m_Running = false; } if(!m_ObjectSystem->tick(dt)){ m_Running = false; } if(!m_PhysicsSystem->tick(dt)){ m_Running = false; } if (!m_RenderSystem->tick(dt)) { //Rendering failed -> shutdown m_Running = false; } mainWindow->swapBuffers(); m_Running = m_Running && !mainWindow->isClosed(); last = current; } return false; }
void renderScene(void) { glViewport (0, 0, width, height ); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho( m_Ortho[0], m_Ortho[1], m_Ortho[2], m_Ortho[3], m_Ortho[4], m_Ortho[5] ); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(test_mode == 1) { glPointSize(5.0f); glColor4f(0.0,0.0,1.0,1.0 ); glEnableClientState(GL_VERTEX_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, vboVertex); glVertexPointer(3,GL_FLOAT,0,0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboList); if(test_type ==1) { if(point_type == 2) { glEnable( GL_POINT_SMOOTH ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glPointSize( 6.0 ); } glDrawElements(GL_POINTS, number_elements, GL_UNSIGNED_INT, NULL); } else if(test_type ==2) { if(edge_type == 1) { glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); } glDrawElements(GL_LINES, number_elements*2, GL_UNSIGNED_INT, NULL); } else if(test_type ==3) { if(triangle_type == 1) { glPolygonMode(GL_FRONT, GL_LINE); glPolygonMode(GL_BACK, GL_LINE); } else { glPolygonMode(GL_FRONT, GL_FILL); glPolygonMode(GL_BACK, GL_FILL); } glDrawElements(GL_TRIANGLES, number_elements*3, GL_UNSIGNED_INT, NULL); } glDisableClientState(GL_VERTEX_ARRAY); } else if(test_mode ==2) { if(test_type == 1) glCallList(DLpoint); else if(test_type == 2) glCallList(DLedge); else if(test_type == 3) glCallList(DLtriangle); } CalcFPS(); glutSwapBuffers(); }
//############################################################################################# // Render de la scene //############################################################################################# BOOL C_ARX_Carte::Render(void) { if((!this->device)||(!this->background)) return E_FAIL; CalcFPS(); device->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,0x00000000,1.0f,0L); if(!danaeApp.DANAEStartRender()) return E_FAIL; int depx = (int)(this->posx * this->background->Xmul); if(depx<0) depx=0; int depz=(int)(this->posz*this->background->Zmul); if(depz<0) depz=0; int endx=this->widthrender/this->nbpixels; int endz=this->heightrender/this->nbpixels; endx+=depx; if(endx>this->background->Xsize) endx=this->background->Xsize; endz+=depz; if(endz>this->background->Zsize) endz=this->background->Zsize; float yecran=0.f; float zsub=((float)depz)*this->background->Zdiv; for(int j=depz;j<endz;j++) { float xecran=0.f; float xsub=((float)depx)*this->background->Xdiv; for(int i=depx;i<endx;i++) { EERIE_BKG_INFO *eg=&this->background->Backg[i+j*this->background->Xsize]; for(int lll=0;lll<eg->nbpoly;lll++) { EERIEPOLY *ep=&eg->polydata[lll]; if (ep) { if(ep->type&POLY_IGNORE) continue; if(ep->type&POLY_TRANS) continue; int nb; if(ep->type&POLY_QUAD) nb=4; else nb=3; for(int k=0;k<nb;k++) { ep->tv[k].sx=xecran+(ep->v[k].sx-xsub)*this->ecx; ep->tv[k].sy=yecran+(ep->v[k].sz-zsub)*this->ecz; ep->tv[k].rhw=(1.f/ep->v[k].sy); if (ep->tv[k].rhw<0.f) ep->tv[k].rhw=0.f; if (ep->tv[k].rhw>1.f) ep->tv[k].rhw=1.f; ep->tv[k].sz=1.f-ep->tv[k].rhw; if (ep->tv[k].sz<0.f) ep->tv[k].sz=0.f; if (ep->tv[k].sz>1.f) ep->tv[k].sz=1.f; ep->tv[k].color=0xFFFFFFFF; ep->tv[k].tu=ep->v[k].tu; ep->tv[k].tv=ep->v[k].tv; } if(ep->tex) device->SetTexture(0,ep->tex->m_pddsSurface); else device->SetTexture(0,NULL); EERIEDRAWPRIM( device, D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX|D3DFVF_DIFFUSE, ep->tv, nb, 0, EERIE_NOCOUNT ); } } xsub+=this->background->Xdiv; xecran+=(float)this->nbpixels; } zsub+=this->background->Zdiv; yecran+=(float)this->nbpixels; } return S_OK; }