/////////////////////////////////////////////////////////////////////////////////////// // Get Window coordinates, discard Z... void m3dProjectXY(M3DVector2f vPointOut, const M3DMatrix44f mModelView, const M3DMatrix44f mProjection, const int iViewPort[4], const M3DVector3f vPointIn) { M3DVector4f vBack, vForth; memcpy(vBack, vPointIn, sizeof(float)*3); vBack[3] = 1.0f; m3dTransformVector4(vForth, vBack, mModelView); m3dTransformVector4(vBack, vForth, mProjection); if(!m3dCloseEnough(vBack[3], 0.0f, 0.000001f)) { float div = 1.0f / vBack[3]; vBack[0] *= div; vBack[1] *= div; //vBack[2] *= div; } vPointOut[0] = float(iViewPort[0])+(1.0f+float(vBack[0]))*float(iViewPort[2])/2.0f; vPointOut[1] = float(iViewPort[1])+(1.0f+float(vBack[1]))*float(iViewPort[3])/2.0f; // This was put in for Grand Tour... I think it's right. // .... please report any bugs if(iViewPort[0] != 0) // Cast to float is expensive... avoid if posssible vPointOut[0] -= float(iViewPort[0]); if(iViewPort[1] != 0) vPointOut[1] -= float(iViewPort[1]); }
/////////////////////////////////////////////////////////////////////////////////////// // Get window coordinates, we also want Z.... void m3dProjectXYZ(M3DVector3f vPointOut, const M3DMatrix44f mModelView, const M3DMatrix44f mProjection, const int iViewPort[4], const M3DVector3f vPointIn) { M3DVector4f vBack, vForth; memcpy(vBack, vPointIn, sizeof(float)*3); vBack[3] = 1.0f; m3dTransformVector4(vForth, vBack, mModelView); m3dTransformVector4(vBack, vForth, mProjection); if(!m3dCloseEnough(vBack[3], 0.0f, 0.000001f)) { float div = 1.0f / vBack[3]; vBack[0] *= div; vBack[1] *= div; vBack[2] *= div; } vPointOut[0] = float(iViewPort[0])+(1.0f+float(vBack[0]))*float(iViewPort[2])/2.0f; vPointOut[1] = float(iViewPort[1])+(1.0f+float(vBack[1]))*float(iViewPort[3])/2.0f; if(iViewPort[0] != 0) // Cast to float is expensive... avoid if posssible vPointOut[0] -= float(iViewPort[0]); if(iViewPort[1] != 0) vPointOut[1] -= float(iViewPort[1]); vPointOut[2] = vBack[2]; }
/////////////////////////////////////////////////////////////////////////////////////// // Get window coordinates, we also want Z.... void m3dProjectXYZ(const M3DMatrix44f mModelView, const M3DMatrix44f mProjection, const int iViewPort[4], const M3DVector3f vPointIn, M3DVector3f vPointOut) { M3DVector4f vBack, vForth; memcpy(vBack, vPointIn, sizeof(float)*3); vBack[3] = 1.0f; m3dTransformVector4(vForth, vBack, mModelView); m3dTransformVector4(vBack, vForth, mProjection); if(!m3dCloseEnough(vBack[3], 0.0f, 0.000001f)) { float div = 1.0f / vBack[3]; vBack[0] *= div; vBack[1] *= div; vBack[2] *= div; } vPointOut[0] = vBack[0] * 0.5f + 0.5f; vPointOut[1] = vBack[1] * 0.5f + 0.5f; vPointOut[2] = vBack[2] * 0.5f + 0.5f; /* Map x,y to viewport */ vPointOut[0] = (vPointOut[0] * iViewPort[2]) + iViewPort[0]; vPointOut[1] = (vPointOut[1] * iViewPort[3]) + iViewPort[1]; }
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(); }
/////////////////////////////////////////////////////////////////////////////// // 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 DrawScene() { modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); // Transform the light position into eye coordinates M3DVector4f vLightPos = { LIGHT_POSITION[0], LIGHT_POSITION[1], LIGHT_POSITION[2], LIGHT_POSITION[3] }; M3DVector4f vLightEyePos; m3dTransformVector4(vLightEyePos, vLightPos, mCamera); /* ------------ */ /* FERRIS WHEEL */ modelViewMatrix.PushMatrix(); /* Position the ferris wheel appropriately. */ modelViewMatrix.Translate(FERRIS_WHEEL_POSITION[0], FERRIS_WHEEL_POSITION[1], FERRIS_WHEEL_POSITION[2]); /* Apply the Translation to this entire block of objects */ modelViewMatrix.PushMatrix(); //theWheel.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos, capTexture, wheelTexture, wallTexture, carTexture, currentTextureIndex); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); /* -------------- */ /* ROLLER COASTER */ modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0, 0.0, -10.0); //track.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); modelViewMatrix.PopMatrix(); /* -------- */ /* CAROUSEL */ modelViewMatrix.PushMatrix(); //modelViewMatrix.Translate(3.0f, 0.0f, -3.0f); modelViewMatrix.Translate(0.0f, 0.0f, -3.0f); //carousel.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); modelViewMatrix.PopMatrix(); modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, 0.0f, -2.0f); //unicorn.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); //ostrich.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); turtle.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos); modelViewMatrix.PopMatrix(); 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(); }
/////////////////////////////////////////////////////////////////////////////// // 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); if(bUseFBO) UseProcessProgram(vLightPos, vWhite, -1); else 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.PushMatrix(); modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f); modelViewMatrix.Translate(0.0, (GLfloat)-0.60, 0.0); modelViewMatrix.Scale((GLfloat)0.02, (GLfloat)0.006, (GLfloat)0.02); glBindTexture(GL_TEXTURE_2D, ninjaTex[0]); if(bUseFBO) { UseProcessProgram(vLightTransformed, vWhite, 0); } else { shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0); } ninja.Render(0,0); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); }
void Shader::bind(GLMatrixStack *pMVM, GLGeometryTransform *pGLGTin){ //default lighting M3DVector4f vEyeLight,vLight = { 128.0f, 128.0f, -128.0f ,1.0f}; M3DMatrix44f *mx; mx = theCam->getMx(); m3dTransformVector4(vEyeLight, vLight, *mx); GLfloat vAmbC[] = { 0.4f, 0.4f, 0.4f, 1.0f }; GLfloat vDifC[] = { 1.0f, 1.0f, 1.0f, 1.0f}; GLfloat vSpecC[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glBindTexture(GL_TEXTURE_2D,myTex[0]); glUseProgram(me); glUniform4fv(locAmbient, 1, vAmbC); glUniform4fv(locDiffuse, 1, vDifC); glUniform4fv(locSpecular, 1, vSpecC); glUniform3fv(locLight, 1, vEyeLight); glUniformMatrix4fv(locMVP, 1, GL_FALSE, pGLGTin->GetModelViewProjectionMatrix()); glUniformMatrix4fv(locMV, 1, GL_FALSE, pGLGTin->GetModelViewMatrix()); glUniformMatrix3fv(locNM, 1, GL_FALSE, pGLGTin->GetNormalMatrix()); glUniform1i(locTexture, 0); }
/////////////////////////////////////////////////////////////////////////////// // 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; // MoveCamera(); modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); GLfloat vFloorColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; if(bUseFBO) { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName); #ifndef OPENGL_ES glDrawBuffers(3, fboBuffs); #endif glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Need light position relative to the Camera M3DVector4f vLightTransformed; m3dTransformVector4(vLightTransformed, vLightPos, mCamera); UseProcessProgram(vLightTransformed, vFloorColor, 0); } else { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); #ifndef OPENGL_ES glDrawBuffers(1, windowBuff); #endif glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vFloorColor, 0); } glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble floorBatch.Draw(); DrawWorld(yRot); modelViewMatrix.PopMatrix(); if(bUseFBO) { // Direct drawing to the window glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); #ifndef OPENGL_ES glDrawBuffers(1, windowBuff); #endif glViewport(0, 0, screenWidth, screenHeight); #ifndef OPENGL_ES // Source buffer reads from the framebuffer object glBindFramebuffer(GL_READ_FRAMEBUFFER, fboName); // Copy greyscale output to the left half of the screen glReadBuffer(GL_COLOR_ATTACHMENT1); glBlitFramebuffer(0, 0, screenWidth/2, screenHeight, 0, 0, screenWidth/2, screenHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST ); // Copy the luminance adjusted color to the right half of the screen glReadBuffer(GL_COLOR_ATTACHMENT2); glBlitFramebuffer(screenWidth/2, 0, screenWidth, screenHeight, screenWidth/2, 0, screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST ); // Scale the unaltered image to the upper right of the screen glReadBuffer(GL_COLOR_ATTACHMENT0); glBlitFramebuffer(0, 0, screenWidth, screenHeight, (int)(screenWidth *(0.8)), (int)(screenHeight*(0.8)), screenWidth, screenHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR ); glBindTexture(GL_TEXTURE_2D, 0); #endif } // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }
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 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(); }
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(); }
void renderScene() { //Colours: static GLfloat vDarkRed[] = {0.0f, 0.396f, 0.702f, 1.0f}; static GLfloat vDarkGrey[] = {0.2f, 0.2f, 0.2f, 1.0f}; static CStopWatch inputTimer; //Clear buffers glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); //Beginning push: modelViewStack.PushMatrix(); //Camera matrix: M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewStack.PushMatrix(mCamera); modelViewStack.Rotate(-15.0f, 1.0f, 0.0f, 0.0f); if (screenshot) { cameraFrame.SetForwardVector(0, 0, -1); cameraFrame.SetUpVector(0, 1, 0); cameraFrame.GetCameraMatrix(mCamera); modelViewStack.PushMatrix(mCamera); } //Light source: static M3DVector4f vAmbient = {0.1f, 0.1f, 0.1f, 1.0f}; static M3DVector4f vLightPos = {4.0f, -6.5f, 10.0f, 1.0f}; static M3DVector4f vLightEyePos; m3dTransformVector4(vLightEyePos, vLightPos, mCamera); //Draw floor and grid: glEnable(GL_MULTISAMPLE); cRoom.draw(shaderManager, tPipeline, modelViewStack); // Highlight grid hlGrid.draw(shaderManager, tPipeline, modelViewStack); //Draw desks: stuDesks.drawAll(shaderManager, tPipeline, vLightEyePos, modelViewStack, vAmbient); //Draw polygon version of desks glDisable(GL_MULTISAMPLE); //Disable multisampling (to use AA) glEnable(GL_BLEND); //Enable blending glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPolygonOffset(-1.0f, -1.0f); glEnable(GL_POLYGON_OFFSET_LINE); //Render wireframe in front of polygon glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); //Wireframe mode glEnable(GL_LINE_SMOOTH); //Enable AA stuDesks.drawAll(shaderManager, tPipeline, vLightEyePos, modelViewStack, vAmbient, vDarkGrey); //Draw wireframe version of desks //Reset stuff as they were before: glDisable(GL_LINE_SMOOTH); glDisable(GL_POLYGON_OFFSET_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_BLEND); //End cam push: modelViewStack.PopMatrix(); //End pop: modelViewStack.PopMatrix(); if (!screenshot) { newDeskButton.draw(W_WIDTH, W_HEIGHT); removeDeskButton.draw(W_WIDTH, W_HEIGHT); exportButton.draw(W_WIDTH, W_HEIGHT); } glutSwapBuffers(); if (screenshot) { char name[38]; sprintf(name, "Exports/screenshot%d.tga", expCounter); gltWriteTGA(name); counterSaver(); modelViewStack.PopMatrix(); screenshot = false; } glutPostRedisplay(); handleInput(inputTimer); }
/** * @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; } }
/////////////////////////////////////////////////////////////////////////////// // 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(); }