/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES2Glass::RenderScene() { if (PVRShellIsKeyPressed(PVRShellKeyNameLEFT)) m_iEffect -= 1; if (PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) m_iEffect += 1; m_iEffect = (m_iEffect + g_iNumEffects) % g_iNumEffects; UpdateScene(); DrawIntoParaboloids(PVRTVec3(0, 0, 0)); // Clear the color and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw the ball DrawBall(); // Draw the balloons DrawBalloons(&m_DefaultProgram, m_mProjection, m_mView, m_mModels, 2); // Draw the skybox DrawSkybox(); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("Glass", g_aszEffectNames[m_iEffect], ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
void EngineRunningBase::DoCameraWork() { Assert(GetCamera().GetPtr()); // Commenting this out caused jerky camera movement in v.1.1. // TODO Work out why - and is the camera now being updated twice per frame ?? GetCamera()->Update(); // Skybox: this should be rotated as the camera changes its orientation, // but the distance should always be fixed. // NB The scene moves w.r.t. the skybox. If the skybox is not big enough, // it will 'clip' the scene far from the player! // (not if we turn off depth buffer writing) AmjuGL::PushMatrix(); GetCamera()->DrawRotation(); DrawSkybox(); // Undo the skybox rotation. AmjuGL::PopMatrix(); // "Draw" the camera, i.e. transform the view. GetCamera()->Draw(); }
void Screen::Draw() { CalculateFps(); // Reset screen buffer memset(buffer, 0, width * height * sizeof(uint)); DrawSkybox(); renderer->Render(); DrawHud(); if (core->menu) core->menu->Draw(drawer); // Debug sprintf(debug, "fps: %d", frameRate); drawer->Draw(debug, 10, 10, 0xffffff); if (showMessageTime) { drawer->Fill(0, 0, width, height - core->art->gamepanel->h, Color::Black); drawer->Draw(message, width / 2 - drawer->TextWidth(message) / 2, (height - core->art->gamepanel->h) / 2, 0xffff80); --showMessageTime; } BufferToScreen(); }
void DrawRendered(PostProcessState state, float time = 0.0f) { DrawSkybox(); if (state == PPS_RENDER_SCENE) DrawStones(GtextureID[0], time); else if (state == PPS_RENDER_GLOWED) DrawStones(0, time); }
void Renderer::RenderScene() { glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); DrawSkybox(); DrawHeightMap(); DrawWater(); SwapBuffers(); }
// Display callback for rendering void Display() { // Clear the display and define a colour glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Do model rotatations and translations float lookZ = sin(g_verticalAngle * PI / 180.0) * cos(g_horizontalAngle * PI / 180.0); float lookX = sin(g_verticalAngle * PI / 180.0) * sin(g_horizontalAngle * PI / 180.0); float lookY = cos(g_verticalAngle * PI / 180.0); gluLookAt(g_camX, g_camY, g_camZ, g_camX + lookX, g_camY + lookY, g_camZ + lookZ, 0, 1, 0); while(g_camX < g_xOffset) {g_xOffset -= 1900;} while(g_camX > g_xOffset + 1900) {g_xOffset += 1900;} while(g_camZ < g_zOffset) {g_zOffset -= 2000;} while(g_camZ > g_zOffset + 2000) {g_zOffset += 2000;} for(int j = g_xOffset - (1900 * g_cityMultiplier); j <= g_xOffset + (1900 * g_cityMultiplier); j += 1900) { for(int k = g_zOffset - (2000 * g_cityMultiplier); k <= g_zOffset + (2000 * g_cityMultiplier); k += 2000) { for(unsigned int i = 0; i < g_city.buildings.size(); i++) { glPushMatrix(); glTranslatef(g_city.buildings[i].tx + j, g_city.buildings[i].ty, g_city.buildings[i].tz + k); glScalef(g_city.buildings[i].sx, g_city.buildings[i].sy, g_city.buildings[i].sz); glRotatef(g_city.buildings[i].rz, 0, 0, 1); glRotatef(g_city.buildings[i].ry, 0, 1, 0); glRotatef(g_city.buildings[i].rx, 1, 0, 0); g_city.buildings[i].model.RenderModel(); glPopMatrix(); } } } // Skybox 5000 ups DrawSkybox(); // Render my name and student number RenderText(); glutSwapBuffers(); }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occurred @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevant OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES3Skybox2::RenderScene() { unsigned int i, j; // Clears the colour and depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Calculates the frame number to animate in a time-based manner. Uses the shell function PVRShellGetTime() to get the time in milliseconds. */ unsigned long iTime = PVRShellGetTime(); if(!bPause) { // Calculate the model view matrix turning around the balloon ComputeViewMatrix(); if(iTime > m_iTimePrev) { float fDelta = (float) (iTime - m_iTimePrev) * g_fFrameRate; m_fFrame += fDelta; fDemoFrame += fDelta; fBurnAnim += fDelta * 0.02f; if(fBurnAnim >= 1.0f) fBurnAnim = 1.0f; } } m_iTimePrev = iTime; /* KeyBoard input processing */ if(PVRShellIsKeyPressed(PVRShellKeyNameACTION1)) bPause=!bPause; if(PVRShellIsKeyPressed(PVRShellKeyNameACTION2)) fBurnAnim = 0.0f; /* Keyboard Animation and Automatic Shader Change over time */ if(!bPause && (fDemoFrame > 500 || (m_i32Effect == 2 && fDemoFrame > 80))) { if(++m_i32Effect >= (int) g_ui32NoOfEffects) { m_i32Effect = 1; m_fFrame = 0.0f; } fDemoFrame = 0.0f; fBurnAnim = 0.0f; } /* Change Shader Effect */ if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT)) { if(++m_i32Effect >= (int) g_ui32NoOfEffects) m_i32Effect = 1; fDemoFrame = 0.0f; fBurnAnim = 0.0f; m_fFrame = 0.0f; } if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT)) { if(--m_i32Effect < 1) m_i32Effect = g_ui32NoOfEffects - 1; fDemoFrame = 0.0f; fBurnAnim = 0.0f; m_fFrame = 0.0f; } /* Change Skybox Texture */ if(PVRShellIsKeyPressed(PVRShellKeyNameUP)) { for(i = 0; i < g_ui32NoOfEffects; ++i) ChangeSkyboxTo(m_ppEffects[i], m_ui32TextureIDs[4]); fBurnAnim = 0.0f; } if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN)) { for(i = 0; i < g_ui32NoOfEffects; ++i) ChangeSkyboxTo(m_ppEffects[i], m_ui32TextureIDs[3]); fBurnAnim = 0.0f; } /* Setup Shader and Shader Constants */ int location; glDisable(GL_CULL_FACE); DrawSkybox(); glEnable(GL_CULL_FACE); m_ppEffects[m_i32Effect]->Activate(); for(i = 0; i < m_Scene.nNumMeshNode; i++) { SPODNode* pNode = &m_Scene.pNode[i]; // Gets pMesh referenced by the pNode SPODMesh* pMesh = &m_Scene.pMesh[pNode->nIdx]; // Gets the node model matrix PVRTMat4 mWorld, mWORLDVIEW; mWorld = m_Scene.GetWorldMatrix(*pNode); mWORLDVIEW = m_mView * mWorld; glBindBuffer(GL_ARRAY_BUFFER, m_aiVboID[i]); const CPVRTArray<SPVRTPFXUniform>& Uniforms = m_ppEffects[m_i32Effect]->GetUniformArray(); for(j = 0; j < Uniforms.GetSize(); ++j) { switch(Uniforms[j].nSemantic) { case ePVRTPFX_UsPOSITION: { glVertexAttribPointer(Uniforms[j].nLocation, 3, GL_FLOAT, GL_FALSE, pMesh->sVertex.nStride, pMesh->sVertex.pData); glEnableVertexAttribArray(Uniforms[j].nLocation); } break; case ePVRTPFX_UsNORMAL: { glVertexAttribPointer(Uniforms[j].nLocation, 3, GL_FLOAT, GL_FALSE, pMesh->sNormals.nStride, pMesh->sNormals.pData); glEnableVertexAttribArray(Uniforms[j].nLocation); } break; case ePVRTPFX_UsUV: { glVertexAttribPointer(Uniforms[j].nLocation, 2, GL_FLOAT, GL_FALSE, pMesh->psUVW[0].nStride, pMesh->psUVW[0].pData); glEnableVertexAttribArray(Uniforms[j].nLocation); } break; case ePVRTPFX_UsWORLDVIEWPROJECTION: { PVRTMat4 mMVP; /* Passes the model-view-projection matrix (MVP) to the shader to transform the vertices */ mMVP = m_mProjection * mWORLDVIEW; glUniformMatrix4fv(Uniforms[j].nLocation, 1, GL_FALSE, mMVP.f); } break; case ePVRTPFX_UsWORLDVIEW: { glUniformMatrix4fv(Uniforms[j].nLocation, 1, GL_FALSE, mWORLDVIEW.f); } break; case ePVRTPFX_UsWORLDVIEWIT: { PVRTMat4 mWORLDVIEWI, mWORLDVIEWIT; mWORLDVIEWI = mWORLDVIEW.inverse(); mWORLDVIEWIT= mWORLDVIEWI.transpose(); PVRTMat3 WORLDVIEWIT = PVRTMat3(mWORLDVIEWIT); glUniformMatrix3fv(Uniforms[j].nLocation, 1, GL_FALSE, WORLDVIEWIT.f); } break; case ePVRTPFX_UsVIEWIT: { PVRTMat4 mViewI, mViewIT; mViewI = m_mView.inverse(); mViewIT = mViewI.transpose(); PVRTMat3 ViewIT = PVRTMat3(mViewIT); glUniformMatrix3fv(Uniforms[j].nLocation, 1, GL_FALSE, ViewIT.f); } break; case ePVRTPFX_UsLIGHTDIREYE: { PVRTVec4 vLightDirectionEyeSpace; // Passes the light direction in eye space to the shader vLightDirectionEyeSpace = m_mView * PVRTVec4(1.0,1.0,-1.0,0.0); glUniform3f(Uniforms[j].nLocation, vLightDirectionEyeSpace.x, vLightDirectionEyeSpace.y, vLightDirectionEyeSpace.z); } break; case ePVRTPFX_UsTEXTURE: { // Set the sampler variable to the texture unit glUniform1i(Uniforms[j].nLocation, Uniforms[j].nIdx); } break; } } location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "myEyePos"); if(location != -1) glUniform3f(location, vCameraPosition.x, vCameraPosition.y, vCameraPosition.z); //set animation location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "fAnim"); if(location != -1) glUniform1f(location, fBurnAnim); location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "myFrame"); if(location != -1) glUniform1f(location, m_fFrame); if(g_bBlendShader[m_i32Effect]) { glEnable(GL_BLEND); // Correct render order for alpha blending through culling // Draw Back faces glCullFace(GL_FRONT); location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "bBackFace"); glUniform1i(location, 1); DrawMesh(pMesh); glUniform1i(location, 0); glCullFace(GL_BACK); } else { location = glGetUniformLocation(m_ppEffects[m_i32Effect]->GetProgramHandle(), "bBackFace"); if(location != -1) glUniform1i(location, 0); glDisable(GL_BLEND); } /* Everything should now be setup, therefore draw the mesh*/ DrawMesh(pMesh); glBindBuffer(GL_ARRAY_BUFFER, 0); for(j = 0; j < Uniforms.GetSize(); ++j) { switch(Uniforms[j].nSemantic) { case ePVRTPFX_UsPOSITION: { glDisableVertexAttribArray(Uniforms[j].nLocation); } break; case ePVRTPFX_UsNORMAL: { glDisableVertexAttribArray(Uniforms[j].nLocation); } break; case ePVRTPFX_UsUV: { glDisableVertexAttribArray(Uniforms[j].nLocation); } break; } } } // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools if(!bPause) m_Print3D.DisplayDefaultTitle("Skybox2", "", ePVRTPrint3DSDKLogo); else m_Print3D.DisplayDefaultTitle("Skybox2", "Paused", ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
void Animate(void) { // limpa a janela glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset the matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); if (!arcCam){ //MOVIMENTO E ROTAÇÃO DA CAMARA COM TECLADO E RATO // Move the camera to our location in space glRotatef(cam->getXRot(), 1.0f, 0.0f, 0.0f); // Rotate our camera on the x-axis (looking up and down) glRotatef(cam->getYRot(), 0.0f, 1.0f, 0.0f); // Rotate our camera on the y-axis (looking left and right) // Translate the ModelView matrix to the position of our camera - everything should now be drawn relative // to this position! glTranslatef(-cam->getXPos(), -cam->getYPos(), -cam->getZPos()); } else{ //Camara orbital arcCamX = arcCamRadius * sin(arcCamAngle); arcCamZ = arcCamRadius * cos(arcCamAngle); gluLookAt(arcCamX, 30, arcCamZ, 0, 0, 0, 0, 1, 0); arcCamAngle += 0.01; if (arcCamAngle > 2 * PI){ arcCamAngle = 0; } } if (spinMode) { //Controla a velocidade da simulação if (holdingMoreSimulationSpeed && simulationSpeed > 15){ simulationSpeed -= simulationSpeedChangeAcceleration; simulationSpeedChangeAcceleration += 0.1; } if (holdingLessSimulationSpeed){ simulationSpeed += simulationSpeedChangeAcceleration; simulationSpeedChangeAcceleration += 0.1; if (simulationSpeed > 5000){ spinMode = false; simulationSpeed = 5000; } } //Atualiza a posição dos planetas e luas UpdatePlanetas(); UpdateLuas(); } applyLights(); glViewport(0, 0, width, height); ResizeWindow(width, height); glEnable(GL_TEXTURE_2D); //Desenha os planetas e luas DrawPlanetas(false); DrawLuas(); //Desenhar displayLists de estrelas glCallList(displayListIndex); glPushMatrix(); //Mover oara posição da camara if (!arcCam){ glTranslatef(cam->getXPos(), 0, cam->getZPos()); } else{ glTranslatef(arcCamX, arcCamY, arcCamZ); } //Desenhar a skybox na posição da camara - a skybox acompanha o movimento da camara DrawSkybox(); glPopMatrix(); //Desenhar anéis de saturno DrawRings(); //Desenhar minimap DrawMinimap(); glfwSwapBuffers(); // Swap the buffers to display the scene (so we don't have to watch it being drawn!) }
void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); // 设置视图变换 CMatrix3D view_mat; camera.GetViewMatrix(view_mat); glMultMatrixf((GLfloat *)&view_mat); // 设置光源位置 GLfloat light_pos[4]={10.0, 8.0, 12.0, 0.0}; glLightfv(GL_LIGHT0, GL_POSITION, light_pos); // 绘制天空盒 2 glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); glRotatef(-90.0, 1.0, 0.0, 0.0); // 绘制天空盒 1 glEnable(GL_TEXTURE_CUBE_MAP); glBindTexture(GL_TEXTURE_CUBE_MAP, env_texture); DrawSkybox(); glDisable(GL_TEXTURE_CUBE_MAP); glEnable(GL_TEXTURE_2D); // 绘制天空盒 2 glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); // 绘制模型 GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_specular[] = { 0.0, 0.0, 0.0, 1.0 }; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialf(GL_FRONT, GL_SHININESS, 0.0); glBindTexture(GL_TEXTURE_2D, ground_texture); ground_model.Draw(); // 绘制其它模型 GLfloat mat_specular2[] = { 0.6, 0.6, 0.6, 1.0 }; glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular2); glMaterialf(GL_FRONT, GL_SHININESS, 64.0); glBindTexture(GL_TEXTURE_2D, model_textures[0]); glPushMatrix(); glTranslatef(-4.0f, -4.0f, 0.5f); models[0].Draw(); glPopMatrix(); glBindTexture(GL_TEXTURE_2D, model_textures[1]); glPushMatrix(); glTranslatef(4.0f, -4.0f, 1.0f); models[1].Draw(); glPopMatrix(); glBindTexture(GL_TEXTURE_2D, model_textures[2]); glPushMatrix(); glTranslatef(4.0f, 4.0f, 1.0f); models[2].Draw(); glPopMatrix(); glBindTexture(GL_TEXTURE_2D, model_textures[3]); glPushMatrix(); glTranslatef(-4.0f, 4.0f, 1.0f); glRotatef(90.0f, 0.0f, 1.0f, 0.0f); models[3].Draw(); glPopMatrix(); // 绘制水面 glDisable(GL_CULL_FACE); glDepthMask(GL_FALSE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GLfloat water_diffuse[] = { 0.7, 0.7, 1.0, 0.8 }; GLfloat water_specular[] = { 0.0, 0.0, 0.0, 0.8 }; glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, water_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, water_specular); glMaterialf(GL_FRONT, GL_SHININESS, 64.0); glPushMatrix(); glTranslatef(0.0, 0.0, water_surface_height); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); glRotatef(-90.0, 1.0, 0.0, 0.0); glEnable(GL_TEXTURE_CUBE_MAP); glBindTexture(GL_TEXTURE_CUBE_MAP, env_texture); water_surface.Draw(); glDisable(GL_TEXTURE_CUBE_MAP); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glDepthMask(GL_TRUE); glDisable(GL_BLEND); glEnable(GL_CULL_FACE); glFlush (); glutSwapBuffers(); }