void render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(shader); updateCamera(); GLGeometryTransform geometryPipeline; GLMatrixStack modelViewStack; GLMatrixStack projectionStack; geometryPipeline.SetMatrixStacks(modelViewStack, projectionStack); projectionStack.LoadMatrix(frustum.GetProjectionMatrix()); M3DMatrix44f cameraMatrix; frame.GetCameraMatrix(cameraMatrix); modelViewStack.PushMatrix(cameraMatrix); glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, geometryPipeline.GetProjectionMatrix()); glUniformMatrix4fv(modelViewMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewMatrix()); glUniformMatrix4fv(normalMatrixLocation, 1, GL_FALSE, geometryPipeline.GetNormalMatrix()); modelViewStack.PushMatrix(); modelViewStack.Translate(0.0, 1.0, 0.0); glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, geometryPipeline.GetProjectionMatrix()); glUniformMatrix4fv(modelViewMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewMatrix()); glUniformMatrix4fv(normalMatrixLocation, 1, GL_FALSE, geometryPipeline.GetNormalMatrix()); glDrawElements(GL_TRIANGLES, 3 * n_faces, GL_UNSIGNED_INT, 0); modelViewStack.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
void Display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); static CStopWatch timer; GLfloat yRot = timer.GetElapsedSeconds()*20.0f; GLfloat vWhite[] = {1.0f,1.0f,1.0f,1.0f}; GLfloat vLightPos[] = {0.0f,2.0f,2.0f}; GLfloat vAmbient[] = {0.3f,0.3f,1.0f,1.0f}; modelViewMatrix.PushMatrix(); //move to camera view M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); modelViewMatrix.PushMatrix(); modelViewMatrix.Rotate(yRot,1.0,1.0,1.0); glBindTexture(GL_TEXTURE_2D,fbxTexture); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, transformPipeLine.GetModelViewMatrix(), transformPipeLine.GetProjectionMatrix(), vLightPos, vWhite, 0); //*/shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeLine.GetModelViewProjectionMatrix(),vWhite); modelViewMatrix.Scale(0.05,0.05,0.05); rTest.DrawReader(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // 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(); }
/////////////////////////////////////////////////////////////////////////////// // Enable and setup the GLSL program used for // flushes, etc. void UseProcessProgram(M3DVector4f vLightPos, M3DVector4f vColor, int textureUnit) { glUseProgram(processProg); // Set Matricies for Vertex Program glUniformMatrix4fv(glGetUniformLocation(processProg, "mvMatrix"), 1, GL_FALSE, transformPipeline.GetModelViewMatrix()); glUniformMatrix4fv(glGetUniformLocation(processProg, "pMatrix"), 1, GL_FALSE, transformPipeline.GetProjectionMatrix()); // Set the light position glUniform3fv(glGetUniformLocation(processProg, "vLightPos"), 1, vLightPos); // Set the vertex color for rendered pixels glUniform4fv(glGetUniformLocation(processProg, "vColor"), 1, vColor); // Set the texture unit for the texBO fetch glUniform1i(glGetUniformLocation(processProg, "lumCurveSampler"), 1); // If this geometry is textured, set the texture unit if(textureUnit != -1) { glUniform1i(glGetUniformLocation(processProg, "bUseTexture"), 1); glUniform1i(glGetUniformLocation(processProg, "textureUnit0"), textureUnit); } else { glUniform1i(glGetUniformLocation(processProg, "bUseTexture"), 0); } gltCheckErrors(processProg); }
void SetupOITResolveProg() { glUseProgram(oitResolve); // Set projection matrix glUniformMatrix4fv(glGetUniformLocation(oitResolve, "pMatrix"), 1, GL_FALSE, transformPipeline.GetProjectionMatrix()); // Set MVP matrix glUniformMatrix4fv(glGetUniformLocation(oitResolve, "mvMatrix"), 1, GL_FALSE, transformPipeline.GetModelViewMatrix()); // Now setup the right textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msTexture[0]); glUniform1i(glGetUniformLocation(oitResolve, "origImage"), 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, depthTextureName); glUniform1i(glGetUniformLocation(oitResolve, "origDepth"), 1); glUniform1f(glGetUniformLocation(oitResolve, "sampleCount"), 8); glActiveTexture(GL_TEXTURE0); gltCheckErrors(oitResolve); }
/////////////////////////////////////////////////////////////////////////////// // Draw the scene // void DrawWorld(GLfloat yRot) { M3DMatrix44f mCamera; modelViewMatrix.GetMatrix(mCamera); // Need light position relative to the Camera M3DVector4f vLightTransformed; m3dTransformVector4(vLightTransformed, vLightPos, mCamera); // Draw the light source as a small white unshaded sphere modelViewMatrix.PushMatrix(); modelViewMatrix.Translatev(vLightPos); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vWhite); sphereBatch.Draw(); modelViewMatrix.PopMatrix(); // Draw stuff relative to the camera modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, 0.2f, -2.5f); modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeline.GetProjectionMatrix(), vLightTransformed, vGreen, 0); torusBatch.Draw(); modelViewMatrix.PopMatrix(); }
void drawTorus(GLfloat yRot) { M3DMatrix44f mCamera; M3DVector4f vLightTransform; modelViewMatrix.GetMatrix(mCamera); m3dTransformVector4(vLightTransform,vLightPosition,mCamera); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0,0.5,-1.0); modelViewMatrix.Rotate(yRot,0.0,1.0,0.0); shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeline.GetProjectionMatrix(), vLightTransform,vGreen,0); torusBatch.Draw(); modelViewMatrix.PopMatrix(); }
void SetupFlatColorProg(GLfloat *vLightPos, GLfloat *vColor) { glUseProgram(flatColorProg); // Set projection matrix glUniformMatrix4fv(glGetUniformLocation(flatColorProg, "pMatrix"), 1, GL_FALSE, transformPipeline.GetProjectionMatrix()); // Set MVP matrix glUniformMatrix4fv(glGetUniformLocation(flatColorProg, "mvMatrix"), 1, GL_FALSE, transformPipeline.GetModelViewMatrix()); // Set Light Pos glUniform3fv(glGetUniformLocation(flatColorProg, "vLightPos"), 1, vLightPos); // Set Color glUniform4fv(glGetUniformLocation(flatColorProg, "vColor"), 1, vColor); gltCheckErrors(flatColorProg); }
void SetupHDRProg() { glUseProgram(hdrResolve); // Set projection matrix glUniformMatrix4fv(glGetUniformLocation(hdrResolve, "pMatrix"), 1, GL_FALSE, transformPipeline.GetProjectionMatrix()); // Set MVP matrix glUniformMatrix4fv(glGetUniformLocation(hdrResolve, "mvMatrix"), 1, GL_FALSE, transformPipeline.GetModelViewMatrix()); // Set user controled uniforms glUniform1fv(glGetUniformLocation(hdrResolve, "exposure"), 1, &exposure); // Set texture uniforms glUniform1i(glGetUniformLocation(hdrResolve, "origImage"), 0); glUniform1i(glGetUniformLocation(hdrResolve, "sampleWeightSampler"), 1); // Setup MS sepcific uniforms glUniform1i(glGetUniformLocation(hdrResolve, "sampleCount"), sampleCount); glUniform1i(glGetUniformLocation(hdrResolve, "useWeightedResolve"), useWeightedResolve); // Now setup the right textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, hdrTextures[0]); // Check if sample weight buffer needs to be updated if (sampleCount != lastSampleCount) { glBindBuffer(GL_TEXTURE_BUFFER_ARB, sampleWeightBuf); void *data = glMapBufferRange(GL_TEXTURE_BUFFER_ARB, 0, sizeof(float)*8, (GL_MAP_WRITE_BIT |GL_MAP_INVALIDATE_RANGE_BIT)); memcpy(data, (void*)sampleWeights[sampleCount],sizeof(float)*8); glUnmapBuffer(GL_TEXTURE_BUFFER_ARB); lastSampleCount = sampleCount; } gltCheckErrors(hdrResolve); }
void SetupTexReplaceProg(GLfloat *vLightPos, GLfloat *vColor) { glUseProgram(texReplaceProg); // Set projection matrix glUniformMatrix4fv(glGetUniformLocation(texReplaceProg, "pMatrix"), 1, GL_FALSE, transformPipeline.GetProjectionMatrix()); // Set MVP matrix glUniformMatrix4fv(glGetUniformLocation(texReplaceProg, "mvMatrix"), 1, GL_FALSE, transformPipeline.GetModelViewMatrix()); // Set Light Pos glUniform3fv(glGetUniformLocation(texReplaceProg, "vLightPos"), 1, vLightPos); // Set Color glUniform4fv(glGetUniformLocation(texReplaceProg, "vColor"), 1, vColor); // Set Tex Unit glUniform1i(glGetUniformLocation(texReplaceProg, "textureUnit0"), 0); gltCheckErrors(texReplaceProg); }
void DrawSongAndDance(GLfloat yRot) // Called to draw dancing objects { static GLfloat vWhite[] = { 1.0f, 1.0f, 1.0f, 1.0f }; static GLfloat vLightPos[] = { 0.0f, 3.0f, 0.0f, 1.0f }; // Get the light position in eye space M3DVector4f vLightTransformed; M3DMatrix44f mCamera; modelViewMatrix.GetMatrix(mCamera); m3dTransformVector4(vLightTransformed, vLightPos, mCamera); // Draw the light source modelViewMatrix.PushMatrix(); modelViewMatrix.Translatev(vLightPos); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeLine.GetModelViewProjectionMatrix(), vWhite); sphereBatch.Draw(); modelViewMatrix.PopMatrix(); glBindTexture(GL_TEXTURE_2D, uiTextures[2]); for (int i = 0; i < NUM_SPHERES; i++) { modelViewMatrix.PushMatrix(); modelViewMatrix.MultMatrix(spheres[i]); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeLine.GetProjectionMatrix(), vLightTransformed, vWhite, 0); sphereBatch.Draw(); modelViewMatrix.PopMatrix(); } // Song and dance modelViewMatrix.Translate(0.0f, 0.2f, -2.5f); modelViewMatrix.PushMatrix(); // Saves the translated origin modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f); // Draw stuff relative to the camera glBindTexture(GL_TEXTURE_2D, uiTextures[1]); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeLine.GetProjectionMatrix(), vLightTransformed, vWhite, 0); torusBatch.Draw(); modelViewMatrix.PopMatrix(); // Erased the rotate modelViewMatrix.Rotate(yRot * -2.0f, 0.0f, 1.0f, 0.0f); modelViewMatrix.Translate(0.8f, 0.0f, 0.0f); glBindTexture(GL_TEXTURE_2D, uiTextures[2]); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeLine.GetProjectionMatrix(), vLightTransformed, vWhite, 0); sphereBatch.Draw(); }
// 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(); }
/** * @brief Called to draw scene */ void RenderScene() { // Color values 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, 0.64f, 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(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.PushMatrix(mCamera); // Transform the light position into eye coordinates M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f }; M3DVector4f vLightEyePos; m3dTransformVector4(vLightEyePos, vLightPos, mCamera); // Draw the floor shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vFloorColor); floorBatch.Draw(); // Draw the spinning Sun modelViewMatrix.Translate(0.0f, 0.0f, -3.5f); // Save the Translation modelViewMatrix.PushMatrix(); // Apply a rotation and draw the Sun modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vLightEyePos, vSunColor); sunSphereBatch.Draw(); modelViewMatrix.PopMatrix(); // "Erase" the Rotation from before // Apply another rotation, followed by a translation, then draw the Earth modelViewMatrix.Rotate(yRot * -2.0f, 0.0f, 1.0f, 0.0f); modelViewMatrix.Translate(0.8f, 0.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vLightEyePos, vEarthColor); earthSphereBatch.Draw(); // Apply another rotation, followed by a translation, then draw the Moon modelViewMatrix.Rotate(yRot * -4.0f, 0.0f, 1.0f, 0.0f); modelViewMatrix.Translate(0.4f, 0.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vLightEyePos, vMoonColor); moonSphereBatch.Draw(); // Restore the previous modleview matrix (the identity matrix) modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); // Do the buffer Swap glutSwapBuffers(); // Tell GLUT to do it again glutPostRedisplay(); }
// main rendering loop void RenderScene(void){ static CStopWatch rotTimer; float yRot = rotTimer.GetElapsedSeconds() * 60.0f; GLfloat vBarColor[] = {1.0f, 0.0f, 0.0f, 1.0f}; currentFrame = getLatestBufferIndex(); if(mapper.getSimpleArg('c')){ vBarColor[0] = .7; vBarColor[1] = .2 + sharedBuffer[currentFrame].averageAmp * 60; vBarColor[2] = 1.0; b = sharedBuffer[currentFrame].averageAmp; g = 0; r = 0; glClearColor(r, g, b, 1.0f); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.PushMatrix(mCamera); if(mapper.getCompoundArg('r') == "auto"){ cameraFrame.RotateWorld(.01, 0.0, 0.0, 1.0); cameraFrame.MoveForward(-.1 * sin(yRot * .05)); } // set up light source M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f }; M3DVector4f vLightEyePos; m3dTransformVector4(vLightEyePos, vLightPos, mCamera); for(int m = 0; m < NUM_MACROS; m++){ if(mapper.getSimpleArg('m')){ modelViewMatrix.PushMatrix(); macros[m].refFrame.RotateLocalY(.01 * macros[m].multiplier); macros[m].refFrame.RotateLocalX(.5 * sharedBuffer[currentFrame].averageAmp); modelViewMatrix.MultMatrix(macros[m].refFrame); } for(int i = 0; i < PACKET_SIZE; i++){ modelViewMatrix.PushMatrix(); GLfloat y = 5 * fabs(sharedBuffer[currentFrame].frames[i][0]); modelViewMatrix.MultMatrix(bars[i]); modelViewMatrix.Scale(barWidth, y, sharedBuffer[currentFrame].averageAmp * 4); if(mapper.getSimpleArg('t')){ modelViewMatrix.Translate(0.0, sharedBuffer[currentFrame].averageAmp, 0.0); } shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vLightEyePos, vBarColor); cubeBatch.Draw(); modelViewMatrix.PopMatrix(); } if(mapper.getSimpleArg('m')){ modelViewMatrix.PopMatrix(); } } // draw prisms for amplitudes modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); if(currentFrame != -1){ sharedBuffer[currentFrame].free = true; } }
// called to draw dancing objects static void DrawSongAndDance(GLfloat yRot) { static GLfloat vWhite[] = { 1.0f, 1.0f, 1.0f, 1.0f }; static GLfloat vLightPos[] = { 0.0f, 3.0f, 0.0f, 1.0f }; // get the light position in eye space M3DMatrix44f mCamera; modelViewMatrix.GetMatrix(mCamera); M3DVector4f vLightTransformed; m3dTransformVector4(vLightTransformed, vLightPos, mCamera); // draw the light source modelViewMatrix.push(); modelViewMatrix.moveTo(vLightPos); shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vWhite); sphereBatch.draw(); modelViewMatrix.pop(); glBindTexture(GL_TEXTURE_2D, uiTextures[2]); for (int i = 0; i < NUM_SPHERES; ++i) { modelViewMatrix.push(); modelViewMatrix.MultMatrix(spheres[i]); shaderManager.useStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeline.GetProjectionMatrix(), vLightTransformed, vWhite, 0); sphereBatch.draw(); modelViewMatrix.pop(); } // song and dance modelViewMatrix.moveTo(0.0f, 0.2f, -2.5f); modelViewMatrix.push(); // save the translated origin modelViewMatrix.rotateTo(yRot, 0.0f, 1.0f, 0.0f); // draw stuff relative to the camera glBindTexture(GL_TEXTURE_2D, uiTextures[1]); shaderManager.useStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeline.GetProjectionMatrix(), vLightTransformed, vWhite, 0); torusBatch.draw(); modelViewMatrix.pop(); // erased the rotate modelViewMatrix.rotateTo(yRot * -2.0f, 0.0f, 1.0f, 0.0f); modelViewMatrix.moveTo(0.8f, 0.0f, 0.0f); glBindTexture(GL_TEXTURE_2D, uiTextures[2]); shaderManager.useStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeline.GetProjectionMatrix(), vLightTransformed, vWhite, 0); sphereBatch.draw(); }
// Called to draw scene void RenderScene(void) { // Clear the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Turn culling on if flag is set if(iCull) glEnable(GL_CULL_FACE); else glDisable(GL_CULL_FACE); // Enable depth testing if flag is set if(iDepth) glEnable(GL_DEPTH_TEST); else glDisable(GL_DEPTH_TEST); modelViewMatix.PushMatrix(viewFrame); GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f }; //shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vRed); shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vRed); torusBatch.Draw(); modelViewMatix.PopMatrix(); 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; M3DVector3f vCameraPos; M3DVector3f vCameraForward; M3DVector3f vMirrorPos; M3DVector3f vMirrorForward; cameraFrame.GetOrigin(vCameraPos); cameraFrame.GetForwardVector(vCameraForward); // Set position of mirror frame (camera) vMirrorPos[0] = 0.0; vMirrorPos[1] = 0.1f; vMirrorPos[2] = -6.0f; // view pos is actually behind mirror mirrorFrame.SetOrigin(vMirrorPos); // Calculate direction of mirror frame (camera) // Because the position of the mirror is known relative to the origin // find the direction vector by adding the mirror offset to the vector // of the viewer-origin vMirrorForward[0] = vCameraPos[0]; vMirrorForward[1] = vCameraPos[1]; vMirrorForward[2] = (vCameraPos[2] + 5); m3dNormalizeVector3(vMirrorForward); mirrorFrame.SetForwardVector(vMirrorForward); // first render from the mirrors perspective glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName); glDrawBuffers(1, fboBuffs); glViewport(0, 0, mirrorTexWidth, mirrorTexHeight); // Draw scene from the perspective of the mirror camera modelViewMatrix.PushMatrix(); M3DMatrix44f mMirrorView; mirrorFrame.GetCameraMatrix(mMirrorView); modelViewMatrix.MultMatrix(mMirrorView); // Flip the mirror camera horizontally for the reflection modelViewMatrix.Scale(-1.0f, 1.0f, 1.0f); 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(yRot); // Now draw a cylinder representing the viewer M3DVector4f vLightTransformed; modelViewMatrix.GetMatrix(mMirrorView); m3dTransformVector4(vLightTransformed, vLightPos, mMirrorView); modelViewMatrix.Translate(vCameraPos[0],vCameraPos[1]-0.8f,vCameraPos[2]-1.0f); modelViewMatrix.Rotate(-90.0f, 1.0f, 0.0f, 0.0f); shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(), transformPipeline.GetProjectionMatrix(), vLightTransformed, vBlue, 0); cylinderBatch.Draw(); modelViewMatrix.PopMatrix(); // Reset FBO. Draw world again from the real cameras perspective glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glDrawBuffers(1, windowBuff); glViewport(0, 0, screenWidth, screenHeight); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); 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(yRot); // Now draw the mirror surfaces modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, -0.4f, -5.0f); if(vCameraPos[2] > -5.0) { glBindTexture(GL_TEXTURE_2D, mirrorTexture); // Reflection shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0); } else { // If the camera is behind the mirror, just draw black shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBlack); } mirrorBatch.Draw(); shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vGrey); mirrorBorderBatch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }
void renderScene() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); modelViewM.PushMatrix(); M3DMatrix44f cameraM; cameraFrame.GetCameraMatrix(cameraM); modelViewM.MultMatrix(cameraM); M3DVector4f lightPos = {0.0f, 10.0f, 5.0f, 1.0f}; M3DVector4f lightEyePos; m3dTransformVector4(lightEyePos, lightPos, cameraM); GLfloat whiteLight[] = {1.0f, 1.0f, 1.0f, 1.0f}; modelViewM.PushMatrix(); modelViewM.Translate(0, 0, -3); M3DMatrix44f objectM; objectFrame.GetMatrix(objectM); modelViewM.MultMatrix(objectM); glBindTexture(GL_TEXTURE_2D, textureID[0]); #if 0 shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, pipelineTransform.GetModelViewMatrix(), pipelineTransform.GetProjectionMatrix(), lightEyePos, whiteLight, 0); #else shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, pipelineTransform.GetModelViewProjectionMatrix(), 0); #endif cuboidBatch.Draw(); modelViewM.PopMatrix(); static CStopWatch timer; float angle = timer.GetElapsedSeconds() * 120; modelViewM.Translate(0.5f, 0.6f, -5); modelViewM.Rotate(angle, 1, 1, 1); modelViewM.Scale(0.5/cuboidLength, 0.3/cuboidHeigth, 0.4/cuboidWidth); glBindTexture(GL_TEXTURE_2D, textureID[1]); #if 0 shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, pipelineTransform.GetModelViewMatrix(), pipelineTransform.GetProjectionMatrix(), lightEyePos, whiteLight, 0); #else shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, pipelineTransform.GetModelViewProjectionMatrix(), 0); #endif cuboidBatch.Draw(); modelViewM.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }