/////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, 0.0f, viewZ); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0); glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_FLOOR]); floorBatch.Draw(); glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_CEILING]); ceilingBatch.Draw(); glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_BRICK]); leftWallBatch.Draw(); rightWallBatch.Draw(); modelViewMatrix.PopMatrix(); // Buffer swap glutSwapBuffers(); }
// Called to draw scene void RenderScene(void) { // Clear the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); modelViewMatix.PushMatrix(viewFrame); GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f }; GLfloat vGray[] = { 0.75f, 0.75f, 0.75f, 1.0f }; shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vRed); tubeBatch.Draw(); shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vGray); innerBatch.Draw(); modelViewMatix.PopMatrix(); glutSwapBuffers(); }
void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); modelViewMatrix.PushMatrix(); { modelViewMatrix.Translate(0.0f, 0.0f, viewZ); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeLine.GetModelViewProjectionMatrix(), 0); glBindTexture(GL_TEXTURE_2D, uiTextures[TEXTURE_FLOOR]); floorBatch.Draw(); glBindTexture(GL_TEXTURE_2D, uiTextures[TEXTURE_CEILING]); ceilingBatch.Draw(); glBindTexture(GL_TEXTURE_2D, uiTextures[TEXTURE_BRICK]); leftWallBatch.Draw(); rightWallBatch.Draw(); } modelViewMatrix.PopMatrix(); glutSwapBuffers(); }
/////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); M3DMatrix44f mObjectFrame; objectFrame.GetMatrix(mObjectFrame); modelViewMatrix.MultMatrix(mObjectFrame); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBlack); switch(nStep) { case 0: glPointSize(4.0f); pointBatch.Draw(); glPointSize(1.0f); break; case 1: glLineWidth(2.0f); lineBatch.Draw(); glLineWidth(1.0f); break; case 2: glLineWidth(2.0f); lineStripBatch.Draw(); glLineWidth(1.0f); break; case 3: glLineWidth(2.0f); lineLoopBatch.Draw(); glLineWidth(1.0f); break; case 4: DrawWireFramedBatch(&triangleBatch); break; case 5: DrawWireFramedBatch(&triangleStripBatch); break; case 6: DrawWireFramedBatch(&triangleFanBatch); break; } modelViewMatrix.PopMatrix(); // Flush drawing commands glutSwapBuffers(); }
/////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { static CStopWatch timer; // Clear the window glClear(GL_COLOR_BUFFER_BIT); // Everything is white GLfloat vWhite [] = { 1.0f, 1.0f, 1.0f, 1.0f }; glBindTexture(GL_TEXTURE_2D, starTexture); glUseProgram(starFieldShader); glUniformMatrix4fv(locMVP, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); glUniform1i(locStarTexture, 0); // Draw small stars glPointSize(4.0f); smallStarBatch.Draw(); // Draw medium sized stars glPointSize(8.0f); mediumStarBatch.Draw(); // Draw largest stars glPointSize(12.0f); largeStarBatch.Draw(); // Draw distant horizon shaderManager.UseStockShader(GLT_SHADER_FLAT, viewFrustum.GetProjectionMatrix(), vWhite); glLineWidth(3.5); mountainRangeBatch.Draw(); // Draw the "moon" glBindTexture(GL_TEXTURE_2D_ARRAY, moonTexture); glUseProgram(moonShader); glUniformMatrix4fv(locMoonMVP, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); glUniform1i(locMoonTexture, 0); // fTime goes from 0.0 to 28.0 and recycles float fTime = timer.GetElapsedSeconds(); fTime = fmod(fTime, 28.0f); glUniform1f(locTimeStamp, fTime); moonBatch.Draw(); // Swap buffers glutSwapBuffers(); glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // Draw the scene // void DrawWorld() { modelViewMatrix.Translate(0.0f, 0.8f, 0.0f); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(-0.3f, 0.f, 0.0f); modelViewMatrix.Scale(0.40, 0.8, 0.40); modelViewMatrix.Rotate(50.0, 0.0, 10.0, 0.0); glSampleMaski(0, 0x02); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtYellow); glass1Batch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.4f, 0.0f, 0.0f); modelViewMatrix.Scale(0.5, 0.8, 1.0); modelViewMatrix.Rotate(-20.0, 0.0, 1.0, 0.0); glSampleMaski(0, 0x04); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtGreen); glass2Batch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(1.0f, 0.0f, -0.6f); modelViewMatrix.Scale(0.3, 0.9, 1.0); modelViewMatrix.Rotate(-40.0, 0.0, 1.0, 0.0); glSampleMaski(0, 0x08); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtMagenta); glass3Batch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(-0.8f, 0.0f, -0.60f); modelViewMatrix.Scale(0.6, 0.9, 0.40); modelViewMatrix.Rotate(60.0, 0.0, 1.0, 0.0); glSampleMaski(0, 0x10); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtBlue); glass4Batch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.1f, 0.0f, 0.50f); modelViewMatrix.Scale(0.4, 0.9, 0.4); modelViewMatrix.Rotate(205.0, 0.0, 1.0, 0.0); glSampleMaski(0, 0x20); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtPink); glass4Batch.Draw(); modelViewMatrix.PopMatrix(); }
/////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { static GLfloat vLightPos [] = { 1.0f, 1.0f, 0.0f }; static GLfloat vWhite [] = { 1.0f, 1.0f, 1.0f, 1.0f }; // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); M3DMatrix44f mObjectFrame; objectFrame.GetMatrix(mObjectFrame); modelViewMatrix.MultMatrix(mObjectFrame); glBindTexture(GL_TEXTURE_2D, textureID); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vLightPos, vWhite, 0); pyramidBatch.Draw(); modelViewMatrix.PopMatrix(); // Flush drawing commands glutSwapBuffers(); }
void RenderScene() { static GLfloat vSunColor[] = { 1.0f, 0.0f, 0.0f, 1.0f }; static GLfloat vEarthColor[] = { 0.0f, 0.0f, 1.0f, 1.0f }; static GLfloat vMoonColor[] = { 1.0f, 1.0f, 0.0f, 1.0f }; static GLfloat vFloorColor[] = { 0.0f, 1.0f, 0.0f, 1.0f}; static CStopWatch rotTimer; float yRot = rotTimer.GetElapsedSeconds() * 60.0f; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.PushMatrix(mCamera); M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f }; M3DVector4f vLightEyePos; m3dTransformVector4(vLightEyePos, vLightPos, mCamera); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vFloorColor); floorBatch.Draw(); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); modelViewMatrix.Translate(0.0f, 0.0f, -3.5f); modelViewMatrix.PushMatrix(); modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vSunColor); sunSphereBatch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.Rotate(yRot * -2.0f, 0.0f, 1.0f, 0.0f); modelViewMatrix.Translate(0.8f, 0.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vEarthColor); earthSphereBatch.Draw(); modelViewMatrix.Rotate(yRot * -4.0f, 0.0f, 1.0f, 0.0f); modelViewMatrix.Translate(0.4f, 0.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vMoonColor); moonSphereBatch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
// Called to draw scene void RenderScene(void) { static CStopWatch timer; // Clear the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT); // Turn on additive blending glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); // Let the vertex program determine the point size glEnable(GL_PROGRAM_POINT_SIZE); // Bind to our shader, set uniforms glUseProgram(starFieldShader); glUniformMatrix4fv(locMVP, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); glUniform1i(locTexture, 0); // fTime goes from 0.0 to 999.0 and recycles float fTime = timer.GetElapsedSeconds() * 10.0f; fTime = fmod(fTime, 999.0f); glUniform1f(locTimeStamp, fTime); // Draw the stars starsBatch.Draw(); glutSwapBuffers(); glutPostRedisplay(); }
void MyGLWidget::paintGL() { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 0.8f }; shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed); squareBatch.Draw(); swapBuffers(); }
void RenderScene(GLFWwindow* window) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(myIdentityShader); triangleBatch.Draw(); glfwSwapBuffers(window); }
/////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(myIdentityShader); triangleBatch.Draw(); // Perform the buffer swap to display back buffer glutSwapBuffers(); }
// Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); M3DMatrix44f identityMatrix; m3dLoadIdentity44(identityMatrix); shaderManager.UseStockShader(GLT_SHADER_SHADED, identityMatrix); triangleBatch.Draw(); // Perform the buffer swap to display back buffer glutSwapBuffers(); //glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // Render the floor void RenderFloor(void) { GLfloat vBrown [] = { 0.55f, 0.292f, 0.09f, 1.0f}; GLfloat vFloor[] = { 1.0f, 1.0f, 1.0f, 0.6f }; switch(nStep) { // Wire frame case 0: glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBrown); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glDisable(GL_CULL_FACE); break; // Wire frame, but not the back side.. and only where stencil == 0 case 1: glEnable(GL_BLEND); glEnable(GL_LINE_SMOOTH); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_EQUAL, 0, 0xff); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBrown); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break; // Solid case 2: case 3: shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBrown); break; // Textured case 4: case 5: default: glBindTexture(GL_TEXTURE_2D, textures[0]); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vFloor, 0); break; } // Draw the floor floorBatch.Draw(); // Put everything back glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_CULL_FACE); glDisable(GL_BLEND); glDisable(GL_LINE_SMOOTH); glDisable(GL_STENCIL_TEST); }
/////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f }; shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed); triangleBatch.Draw(); // Perform the buffer swap to display back buffer glutSwapBuffers(); }
/////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Everything is white GLfloat vWhite [] = { 1.0f, 1.0f, 1.0f, 1.0f }; shaderManager.UseStockShader(GLT_SHADER_FLAT, viewFrustum.GetProjectionMatrix(), vWhite); // Draw small stars glPointSize(1.0f); smallStarBatch.Draw(); // Draw medium sized stars glPointSize(4.0f); mediumStarBatch.Draw(); // Draw largest stars glPointSize(8.0f); largeStarBatch.Draw(); // Draw the "moon" moonBatch.Draw(); // Draw distant horizon glLineWidth(3.5); mountainRangeBatch.Draw(); moonBatch.Draw(); // Swap buffers glutSwapBuffers(); }
//开始渲染 void RenderScene(void) { //清除一个或一组特定的缓冲区 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //设置一组浮点数来表示红色 GLfloat vRed[] = {1.0f,0.0f,0.0f,1.0f}; //传递到存储着色器,即GLT_SHADER_IDENTITY着色器,这个着色器只是使用指定颜色以默认笛卡尔坐标第在屏幕上渲染几何图形 shaderManager.UseStockShader(GLT_SHADER_IDENTITY,vRed); //提交着色器 triangleBatch.Draw(); //将在后台缓冲区进行渲染,然后在结束时交换到前台 glutSwapBuffers(); }
/////////////////////////////////////////////////////////////////////////////// // Render a frame. The owning framework is responsible for buffer swaps, // flushes, etc. void RenderScene(void) { static CStopWatch animationTimer; float yRot = animationTimer.GetElapsedSeconds() * 60.0f; // first, draw to FBO at full FBO resolution // Bind FBO with 8b attachment glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName); glViewport(0, 0, hdrTexturesWidth[curHDRTex], hdrTexturesHeight[curHDRTex]); glClear(GL_COLOR_BUFFER_BIT); // Bind texture with HDR image glBindTexture(GL_TEXTURE_2D, hdrTextures[curHDRTex]); // Render pass, downsample to 8b using selected program projectionMatrix.LoadMatrix(fboOrthoMatrix); SetupHDRProg(); fboQuad.Draw(); // Then draw the resulting image to the screen, maintain image proportions glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glViewport(0, 0, screenWidth, screenHeight); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // Attach 8b texture with HDR image glBindTexture(GL_TEXTURE_2D, fboTextures[0]); // draw screen sized, proportional quad with 8b texture projectionMatrix.LoadMatrix(orthoMatrix); SetupStraightTexProg(); screenQuad.Draw(); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }
void DrawGround() { glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, groundTexture); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); static GLfloat vFloorColor[] = { 1.0f, 1.0f, 1.0f, REFLECTING_ALPHA}; if (reflecting) vFloorColor[3] = REFLECTING_ALPHA; else vFloorColor[3] = NONREFLECTING_ALPHA; shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vFloorColor, 0); groundBatch.Draw(); glDisable(GL_BLEND); }
/////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f }; shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed); squareBatch.Draw(); // Flush drawing commands glutSwapBuffers(); BounceFunction(); glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(myTexturedIdentityShader); glBindTexture(GL_TEXTURE_2D, textureID); GLint iTextureUniform = glGetUniformLocation(myTexturedIdentityShader, "colorMap"); glUniform1i(iTextureUniform, 0); triangleBatch.Draw(); // Perform the buffer swap to display back buffer glutSwapBuffers(); }
/////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Everything is white GLfloat vWhite [] = { 1.0f, 1.0f, 1.0f, 1.0f }; #ifndef OPENGL_ES shaderManager.UseStockShader(GLT_SHADER_FLAT, viewFrustum.GetProjectionMatrix(), vWhite); // Draw small stars glPointSize(1.0f); #else glUseProgram(pointSizeShader); GLint iTransform, iColor, iPointSize; iTransform = glGetUniformLocation(pointSizeShader, "mvpMatrix"); glUniformMatrix4fv(iTransform, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); iColor = glGetUniformLocation(pointSizeShader, "vColor"); glUniform4fv(iColor, 1, vWhite); iPointSize = glGetUniformLocation(pointSizeShader, "fPointSize"); glUniform1f(iPointSize, 1.0f); #endif smallStarBatch.Draw(); // Draw medium sized stars #ifdef OPENGL_ES iPointSize = glGetUniformLocation(pointSizeShader, "fPointSize"); glUniform1f(iPointSize, 4.0f); #else glPointSize(4.0f); #endif mediumStarBatch.Draw(); // Draw largest stars #ifdef OPENGL_ES iPointSize = glGetUniformLocation(pointSizeShader, "fPointSize"); glUniform1f(iPointSize, 8.0f); #else glPointSize(8.0f); #endif largeStarBatch.Draw(); // Draw the "moon" moonBatch.Draw(); // Draw distant horizon glLineWidth(3.5); mountainRangeBatch.Draw(); moonBatch.Draw(); // Swap buffers glutSwapBuffers(); }
// Called to draw scene void RenderScene(void) { static CStopWatch rotTimer; float yRot = rotTimer.GetElapsedSeconds() * 60.0f; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); // Draw the world upside down modelViewMatrix.PushMatrix(); modelViewMatrix.Scale(1.0f, -1.0f, 1.0f); // Flips the Y Axis modelViewMatrix.Translate(0.0f, 0.8f, 0.0f); // Scootch the world down a bit... glFrontFace(GL_CW); DrawSongAndDance(yRot); glFrontFace(GL_CCW); modelViewMatrix.PopMatrix(); // Draw the solid ground glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, uiTextures[0]); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); static GLfloat vFloorColor[] = { 1.0f, 1.0f, 1.0f, 0.75f}; shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vFloorColor, 0); floorBatch.Draw(); glDisable(GL_BLEND); DrawSongAndDance(yRot); modelViewMatrix.PopMatrix(); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f }; glUseProgram(myIdentityShader); GLint iColorLocation = glGetUniformLocation(myIdentityShader, "vColor"); GLfloat vColor[4] = { 1.0f, 0.0f, 0.0f, 1.0f }; glUniform4fv(iColorLocation, 1, vColor); triangleBatch.Draw(); // Perform the buffer swap to display back buffer glutSwapBuffers(); }
void RenderScene() { // Clear the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); { ScopedMatrix m(modelViewMatrix); modelViewMatrix.MultMatrix(viewFrame); glUseProgram(texturedIdentity); glBindTexture(GL_TEXTURE_2D, stoneTexture); locTextureUniform = glGetUniformLocation(texturedIdentity, "colorMap"); glUniform1i(locTextureUniform, 0); triangleBatch.Draw(); } glutSwapBuffers(); }
// Called to draw scene void RenderScene(void) { // Color values static GLfloat vFloorColor[] = { 0.0f, 1.0f, 0.0f, 1.0f}; static GLfloat vTorusColor[] = { 1.0f, 0.0f, 0.0f, 1.0f }; // Time Based animation static CStopWatch rotTimer; float yRot = rotTimer.GetElapsedSeconds() * 60.0f; // Clear the color and depth buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Save the current modelview matrix (the identity matrix) modelViewMatrix.PushMatrix(); // Draw the ground shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vFloorColor); floorBatch.Draw(); // Draw the spinning Torus modelViewMatrix.Translate(0.0f, 0.0f, -2.5f); modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vTorusColor); torusBatch.Draw(); // Restore the previous modleview matrix (the idenity matrix) modelViewMatrix.PopMatrix(); // Do the buffer Swap glutSwapBuffers(); // Tell GLUT to do it again glutPostRedisplay(); }
void SceneShader() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); GLfloat VColor[] = {0.25f,0.25f,0.25f,1.0f}; M3DMatrix44f RotationMatrix; Rot += 1.0f; //get the Rotation Matrix //m3dDegToRad: translate angle to radian m3dRotationMatrix44(RotationMatrix, m3dDegToRad(Rot), 0.0f, 0.0f, 1.0f); //use the flat shader shaderManager.UseStockShader(GLT_SHADER_FLAT, RotationMatrix ,VColor); SquareRotationBatch.Draw(); // Swap buffers, and immediately refresh glutSwapBuffers(); glutPostRedisplay(); }
// Called to draw scene void RenderScene(void) { // Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); M3DMatrix44f mCamera; M3DMatrix44f mCameraRotOnly; M3DMatrix44f mInverseCamera; viewFrame.GetCameraMatrix(mCamera, false); viewFrame.GetCameraMatrix(mCameraRotOnly, true); m3dInvertMatrix44(mInverseCamera, mCameraRotOnly); modelViewMatrix.PushMatrix(); // Draw the sphere modelViewMatrix.MultMatrix(mCamera); glUseProgram(reflectionShader); glUniformMatrix4fv(locMVPReflect, 1, GL_FALSE, transformPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(locMVReflect, 1, GL_FALSE, transformPipeline.GetModelViewMatrix()); glUniformMatrix3fv(locNormalReflect, 1, GL_FALSE, transformPipeline.GetNormalMatrix()); glUniformMatrix4fv(locInvertedCamera, 1, GL_FALSE, mInverseCamera); glUniform1i(locCubeMap, 0); glUniform1i(locTarnishMap, 1); glEnable(GL_CULL_FACE); sphereBatch.Draw(); glDisable(GL_CULL_FACE); modelViewMatrix.PopMatrix(); modelViewMatrix.PushMatrix(); modelViewMatrix.MultMatrix(mCameraRotOnly); glUseProgram(skyBoxShader); glUniformMatrix4fv(locMVPSkyBox, 1, GL_FALSE, transformPipeline.GetModelViewProjectionMatrix()); cubeBatch.Draw(); modelViewMatrix.PopMatrix(); // Do the buffer Swap glutSwapBuffers(); }
/////////////////////////////////////////////////////////////////////////////// // Render a frame. The owning framework is responsible for buffer swaps, // flushes, etc. void RenderScene(void) { static CStopWatch animationTimer; static float totalTime = 6; // To go back and forth static float halfTotalTime = totalTime/2; float seconds = animationTimer.GetElapsedSeconds() * speedFactor; float xPos = 0; // Calculate the next postion of the moving object // First perform a mod-like operation on the time as a float while(seconds > totalTime) seconds -= totalTime; // Move object position, if it's gone half way across // start bringing it back if(seconds < halfTotalTime) xPos = seconds -halfTotalTime*0.5f; else xPos = totalTime - seconds -halfTotalTime*0.5f; // First draw world to screen modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0); floorBatch.Draw(); DrawWorld(0.0f, xPos); modelViewMatrix.PopMatrix(); if(bUsePBOPath) { #ifndef OPENGL_ES // First bind the PBO as the pack buffer, then read the pixels directly to the PBO glBindBuffer(GL_PIXEL_PACK_BUFFER, pixBuffObjs[0]); glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); // Next bind the PBO as the unpack buffer, then push the pixels straight into the texture glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixBuffObjs[0]); // Setup texture unit for new blur, this gets imcremented every frame glActiveTexture(GL_TEXTURE0+GetBlurTarget0() ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); #endif } else { // Grab the screen pixels and copy into local memory glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, pixelData); // Push pixels from client memory into texture // Setup texture unit for new blur, this gets imcremented every frame glActiveTexture(GL_TEXTURE0+GetBlurTarget0() ); #ifndef OPENGL_ES glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, pixelData); #else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, pixelData); #endif } // Draw full screen quad with blur shader and all blur textures projectionMatrix.PushMatrix(); projectionMatrix.LoadIdentity(); projectionMatrix.LoadMatrix(orthoMatrix); modelViewMatrix.PushMatrix(); modelViewMatrix.LoadIdentity(); glDisable(GL_DEPTH_TEST); SetupBlurProg(); screenQuad.Draw(); glEnable(GL_DEPTH_TEST); modelViewMatrix.PopMatrix(); projectionMatrix.PopMatrix(); // Move to the next blur texture for the next frame AdvanceBlurTaget(); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); UpdateFrameCount(); }
void RenderScene(void) { static CStopWatch rotTimer; float yRot = rotTimer.GetElapsedSeconds() * 60.0f; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); modelViewMatrix.PushMatrix(); { //反向 modelViewMatrix.Scale(1.0f, -1.0f, 1.0f); //因为是反向,所以正数是向下 modelViewMatrix.Translate(0.0f, 0.8f, 0.0f); // Scootch the world down a bit... //三维中其中一维反向之后,缠绕方向也会呈相反,所以重新定义缠绕正方向为顺时针方向; glFrontFace(GL_CW); DrawSongAndDance(yRot); glFrontFace(GL_CCW); } modelViewMatrix.PopMatrix(); // Draw the solid ground glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D, uiTextures[0]); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); static GLfloat vFloorColor[] = { 1.0f, 1.0f, 1.0f, 0.75f }; shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeLine.GetModelViewProjectionMatrix(), vFloorColor, 0); floorBatch.Draw(); glDisable(GL_BLEND); DrawSongAndDance(yRot); modelViewMatrix.PopMatrix(); // Render the overlay // Creating this matrix really doesn't need to be done every frame. I'll leave it here // so all the pertenant code is together M3DMatrix44f mScreenSpace; m3dMakeOrthographicMatrix(mScreenSpace, 0.0f, 800.0f, 0.0f, 600.0f, -1.0f, 1.0f); // Turn blending on, and depth testing off glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glUseProgram(sphereWolrdShader); glUniform1i(locTexture, 0); glUniformMatrix4fv(locMVP, 1, GL_FALSE, mScreenSpace); glBindTexture(GL_TEXTURE_RECTANGLE, uiTextures[3]); logoBatch.Draw(); // Restore no blending and depth test glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }