void render_scene(void) { float angle = timer.GetElapsedSeconds() * 3.14f / 10.0f; location[0] = -8.0f * cos(angle / 2.0f); location[1] = -8.0f * sin(angle / 2.0f); location[2] = 5.0f; light_0.position[0] = 10.0f * cos(-angle); light_0.position[1] = 10.0f * sin(-angle); light_0.position[2] = 3.0f; look_at(camera_frame, location, target, up_dir); camera_frame.GetCameraMatrix(camera_matrix); p_stack.LoadMatrix(view_frustum.GetProjectionMatrix()); mv_stack.LoadMatrix(camera_matrix); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //-- glUseProgram(shader_color); mv_stack.PushMatrix(); mv_stack.Translate(light_0.position[0], light_0.position[1], light_0.position[2]); mv_stack.Scale(0.25f, 0.25f, 0.25f); glUniformMatrix4fv(mvp_matrix_location_shader_color, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix()); draw_light(); mv_stack.PopMatrix(); //-- glUseProgram(shader_light); glUniformMatrix3fv(normal_matrix_location, 1, GL_FALSE, geometry_pipeline.GetNormalMatrix()); glUniformMatrix4fv(v_matrix_location, 1, GL_FALSE, camera_matrix); glUniform3fv(intensity_ambient_component_location, 1, intensity_ambient_component); glUniform3fv(light_0_position_location, 1, light_0.position); glUniform3fv(light_0_intensity_diffuse_location, 1, light_0.intensity_diffuse); glUniform3fv(light_0_intensity_specular_location, 1, light_0.intensity_specular); glUniform3fv(light_0_attenuation_location, 1, light_0.attenuation); glUniform1f(material_0_ka_location, material_0.ka); glUniform1f(material_0_kd_location, material_0.kd); glUniform1f(material_0_ks_location, material_0.ks); glUniform1f(material_0_alpha_location, material_0.alpha); //-- for(int i = -10; i <= 10; i += 3) for(int j = -10; j <= 10; j += 3) { mv_stack.PushMatrix(); mv_stack.Translate(i, j, 0.0f); glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix()); glDrawElements(GL_TRIANGLES, faces.size(), GL_UNSIGNED_INT, 0); mv_stack.PopMatrix(); } //-- glUseProgram(0); glutSwapBuffers(); glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // Window has changed size, or has just been created. In either case, we need // to use the window dimensions to set the viewport and the projection matrix. void ChangeSize(int w, int h) { glViewport(0, 0, w, h); viewFrustum.SetPerspective(35.0f, float(w) / float(h), 1.0f, 500.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); }
/** * @fn void ScreenRepaint::render(GLMatrixStack &modelViewStack, GLMatrixStack &projectionStack, * GLShaderManager &shaderManager); * * @brief Renders the quad. Note! THis should be called *after* all 3D drawing (i.e. after postDraw3D()), but *before* draw2D() * The steps are as follows: * First bind the PBO as the pack buffer, then read the pixels directly to the PBO and unbind * Next bind the PBO as the unpack buffer, then push the pixels straight into the texture * Setup texture unit for the render surface * switch to the GL_TEXTURE* value that we are using as our screen texture holder * write the pixels * unbind * Draw full screen quad with screen textures, calling setupScreenRenderProg() to access the chaders for the effect desired. * * * * @author Phil * @date 3/15/2012 * * @param [in,out] modelViewStack modelviewMatrix stack * @param [in,out] projectionStack projection matrix stack * @param [in,out] shaderManager Manager of default shaders */ void ScreenRepaint::render(GLMatrixStack &modelViewStack, GLMatrixStack &projectionStack, GLShaderManager &shaderManager){ // First bind the PBO as the pack buffer, then read the pixels directly to the PBO glBindBuffer(GL_PIXEL_PACK_BUFFER, pixBuffObjs[0]); // bind glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, NULL); // act glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); // unbind // Next bind the PBO as the unpack buffer, then push the pixels straight into the texture glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixBuffObjs[0]); // bind // Setup texture unit for the render surface glActiveTexture(screenTextureID); // switch to the GL_TEXTURE* value that we are using as our screen texture holder glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); // write the pixels glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); // unbind // Draw full screen quad with screen textures projectionStack.PushMatrix(); projectionStack.LoadMatrix(orthoMatrix); modelViewStack.PushMatrix(); modelViewStack.LoadIdentity(); glDisable(GL_DEPTH_TEST); setupScreenRenderProg(projectionStack.GetMatrix()); screenQuad.Draw(); glEnable(GL_DEPTH_TEST); modelViewStack.PopMatrix(); projectionStack.PopMatrix(); }
/////////////////////////////////////////////////////////////////////////////// // Window has changed size, or has just been created. In either case, we need // to use the window dimensions to set the viewport and the projection matrix. void ChangeSize(int w, int h) { glViewport(0, 0, w, h); viewFrustum.SetPerspective(35.0f, float(w) / float(h), 1.0f, 500.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelViewMatrix.LoadIdentity(); }
void ChangeSize(int w, int h){ if(h == 0) { h = 1; } glViewport(0, 0, w, h); viewFrustum.SetPerspective(35.0f, float(w)/float(h), 1.0f, 1000.0f); projection.LoadMatrix(viewFrustum.GetProjectionMatrix()); geometryPipeline.SetMatrixStacks(modelView, projection); }
/////////////////////////////////////////////////////////////////////////////// // This is called at least once and before any rendering occurs. If the screen // is a resizeable window, then this will also get called whenever the window // is resized. void ChangeSize(int nWidth, int nHeight) { glViewport(0, 0, nWidth, nHeight); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelViewMatrix.LoadIdentity(); // update screen sizes screenWidth = nWidth; screenHeight = nHeight; glBindRenderbuffer(GL_RENDERBUFFER, depthBufferName); #ifndef ANGLE glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, screenWidth, screenHeight); #else glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, screenWidth, screenHeight); #endif glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[0]); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight); glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[1]); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight); glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[2]); glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight); }
/////////////////////////////////////////////////////////////////////////////// // This is called at least once and before any rendering occurs. If the screen // is a resizeable window, then this will also get called whenever the window // is resized. void ChangeSize(int nWidth, int nHeight) { glViewport(0, 0, nWidth, nHeight); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelViewMatrix.LoadIdentity(); // update screen sizes screenWidth = nWidth; screenHeight = nHeight; // reset screen aligned quad gltGenerateOrtho2DMat(screenWidth, screenHeight, orthoMatrix, screenQuad); free(pixelData); pixelDataSize = screenWidth*screenHeight*3*sizeof(unsigned int); pixelData = (void*)malloc(pixelDataSize); // Resize PBOs #ifndef OPENGL_ES glBindBuffer(GL_PIXEL_PACK_BUFFER, pixBuffObjs[0]); glBufferData(GL_PIXEL_PACK_BUFFER, pixelDataSize, pixelData, GL_DYNAMIC_COPY); glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); #endif gltCheckErrors(); }
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 changeSize(int w, int h) { if (h == 0) h = 1; glViewport(0, 0, w, h); frustum.SetPerspective(35, (float)w/h, 1, 100); projectionM.LoadMatrix(frustum.GetProjectionMatrix()); }
void ChangeSize(int nWidth, int nHeight) { glViewport(0, 0, nWidth, nHeight); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelViewMatrix.LoadIdentity(); }
void Reshape(int w,int h) { if(h == 0) h = 1; glViewport(0,0,w,h); viewFrustum.SetPerspective(35.0,(float) w /(float) h,1.0,2000.0); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); transformPipeLine.SetMatrixStacks(modelViewMatrix,projectionMatrix); }
void changeSize(int w, int h) { glViewport(0, 0, w, h); if(h <= 0) {h = 1;} viewFrustum.SetPerspective(35.0f, float(w)/float(h), 1.0f, 100.0f); projectionStack.LoadMatrix(viewFrustum.GetProjectionMatrix()); tPipeline.SetMatrixStacks(modelViewStack, projectionStack); }
void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glFrontFace(GL_CW); glUseProgram(shader); M3DVector3f at={0.0f, 0.0f, 0.0f}; M3DVector3f up={0.0f, 0.0f, 1.0f}; M3DVector3f eye; float angle = timer.GetElapsedSeconds()*3.14159f/8; eye[0]= 6.8f * cos(angle); eye[1]= 6.0f * sin(angle); eye[2]= 25.0f; LookAt(cameraFrame,eye,at,up); projection.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelView.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelView.LoadMatrix(mCamera); modelView.PushMatrix(); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); szachownica(); modelView.Translate(0.0f, 0.0f, 0.0f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujPiramidke(); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(5.0f, 0.0f, 0.0f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujPiramidke(); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(-5.0f, 0.0f, 0.0f); modelView.Scale(2.0f, 2.0f, 2.0f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujPiramidke(); modelView.PopMatrix(); modelView.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
void ResizeWindow(int nWidth, int nHeight) { glViewport(0, 0, nWidth, nHeight); // Create the projection matrix, and load it on the projection matrix stack viewFrustum.SetPerspective(FRUSTUM_FIELD_OF_VIEW, float(nWidth)/float(nHeight), FRUSTUM_NEAR_PLANE, FRUSTUM_FAR_PLANE); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); // Set the transformation pipeline to use the two matrix stacks transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); }
/////////////////////////////////////////////////// // Screen changes size or is initialized void ChangeSize(int nWidth, int nHeight) { glViewport(0, 0, nWidth, nHeight); // Create the projection matrix, and load it on the projection matrix stack viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); // Set the transformation pipeline to use the two matrix stacks transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); }
void Reshape(int width,int height) { glViewport(0,0,width,height); transformPipeline.SetMatrixStacks(modelViewMatrix,projectionMatrix); viewFrustum.SetPerspective(35.0f,float(width)/float(height),1.0f,100.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelViewMatrix.LoadIdentity(); screenHeight = height; screenWidth = width; }
void ChangeSize(int w, int h) { if (h <= 0) { h = 1; } glViewport(0, 0, w, h); viewFrustum.SetPerspective(80.0f, float(w) / float(h), 1.0f, 120.0f); projctionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); transformPipeLine.SetMatrixStacks(modelViewMatrix, projctionMatrix); }
/////////////////////////////////////////////////////////////////////////////// // 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 ChangeSize(int w, int h) { // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); viewFrustum.SetPerspective(35.0f, float(w)/float(h), 1.0f, 100.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); }
void ChangeSize(int w, int h) { // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); viewFrustum.SetOrthographic(-130.0f, 130.0f, -130.0f, 130.0f, -130.0f, 130.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); transformPipeline.SetMatrixStacks(modelViewMatix, projectionMatrix); }
void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(shader); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); CStopWatch timer; float angle = timer.GetElapsedSeconds()*3.14f; M3DVector3f mAt={0,0,0}; M3DVector3f mUp={0,0,1}; M3DVector3f mEye; mEye[0]=6.8f*cos(angle); mEye[1]=6.0f*sin(angle); mEye[2]=5.0f; LookAt(mFrame,mEye,mAt,mUp); mFrame.GetCameraMatrix(mCameraMatrix); matrixStack.LoadMatrix(mFrustrum.GetProjectionMatrix()); matrixStack.MultMatrix(mCameraMatrix); glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, matrixStack.GetMatrix()); drawGrid(); matrixStack.Translate(1.0f,7.0f,0.0f); matrixStack.Rotate(30.0f,0.0,0.0,1.0); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,matrixStack.GetMatrix()); drawPyramid(); matrixStack.PopMatrix(); matrixStack.Translate(-7.0f,0.0f,0.0f); matrixStack.Scale(2.0f, 2.0f, 2.0f); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,matrixStack.GetMatrix()); drawPyramid(); matrixStack.PopMatrix(); // Perform the buffer swap to display back buffer glutSwapBuffers(); glutPostRedisplay(); }
///////////////////////////////////////////////////////////////////// // Change viewing volume and viewport. Called when window is resized void ChangeSize(int w, int h) { GLfloat fAspect; // Prevent a divide by zero if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); fAspect = (GLfloat)w/(GLfloat)h; // Produce the perspective projection viewFrustum.SetPerspective(80.0f,fAspect,1.0,120.0); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); }
/////////////////////////////////////////////////////////////////////////////// // This is called at least once and before any rendering occurs. If the screen // is a resizeable window, then this will also get called whenever the window // is resized. void ChangeSize(int nWidth, int nHeight) { glViewport(0, 0, nWidth, nHeight); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f); projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelViewMatrix.LoadIdentity(); // update screen sizes screenWidth = nWidth; screenHeight = nHeight; glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, hdrTextures[0]); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 8, GL_RGB16F, screenWidth, screenHeight, GL_FALSE); GenerateOrtho2DMat(nWidth, nHeight); glUseProgram(0); }
void ChangeSize(int w, int h) { GLfloat nRange = 500.0f; windowWidth = w; windowHeight = h; // Verhindere eine Division durch Null if (h == 0) { h = 1; } // Setze den Viewport gemaess der Window-Groesse glViewport(0, 0, w, h); // Ruecksetzung des Projection matrix stack projectionMatrix.LoadIdentity(); if (bPerspectiveProj) { // Definiere das viewing volume (left, right, bottom, top, near, far) if (w <= h) { viewFrustum.SetPerspective(30.0f, h/w, 1, 3000); } else { viewFrustum.SetPerspective(30.0f, w / h, 1, 3000); } } else { // Definiere das viewing volume (left, right, bottom, top, near, far) if (w <= h) { viewFrustum.SetOrthographic(-nRange, nRange, -nRange*h / w, nRange*h / w, -nRange, nRange); } else { viewFrustum.SetOrthographic(-nRange*w / h, nRange*w / h, -nRange, nRange, -nRange, nRange); } } projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix()); // Ruecksetzung des Model view matrix stack modelViewMatrix.LoadIdentity(); TwWindowSize(w, h); }
void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUniform3fv(shaderMaterialAmbientLocation, 1, ambientColor); glUniform3fv(shaderMaterialDiffuseLocation, 1, diffuseColor); glUniform3fv(shaderMaterialSpecularLocation, 1, specularColor); glUniform1f(shaderMaterialSpecularExponentLocation, specularExponent); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); GLMatrixStack modelView; GLMatrixStack projection; GLGeometryTransform geometryPipeline; geometryPipeline.SetMatrixStacks(modelView,projection); projection.LoadMatrix(frustum.GetProjectionMatrix()); modelView.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelView.LoadMatrix(mCamera); modelView.PushMatrix(); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujSiatke(); modelView.PushMatrix(); modelView.Translate(0.0f,0.0f,-1.f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujTrojkat(); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(0.0f,4.0f,0.f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujTrojkat(); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(3.0f,-3.0f,0.f); modelView.Scale(2.0f,2.0f,2.f); modelView.Rotate(45,0,0,1); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); rysujTrojkat(); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(3.0f,3.0f,0.f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); drawTriangles(20, ico_vertices,ico_faces); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(0.0f,0.0f,7.f); modelView.Rotate(90+rotAngle,1,1,1); modelView.Scale(2.0f,2.5f,2.5f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); drawTriangles(20, ico_vertices,ico_faces); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(-4.0f,0.0f,4.f); modelView.Scale(2.0f,2.0f,2.0f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(MNMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glDrawElements(GL_TRIANGLES,3*n_faces,GL_UNSIGNED_INT,0); modelView.PopMatrix(); // Perform the buffer swap to display back buffer glutSwapBuffers(); rotAngle+=5.f; if(!stopRotate){ M3DVector3f at={0,0,0}; M3DVector3f up={0,0,1}; M3DVector3f eye; float angle = timer.GetElapsedSeconds()*3.14159f /3.f; eye[0]=16.f*cos(angle); eye[1]=40.0f*sin(angle); eye[2]=20.0f; LookAt(cameraFrame,eye,at,up); } glutPostRedisplay(); }
void RenderScene(void) { // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); //glFrontFace(GL_CW); glUseProgram(shader); float angle=timer.GetElapsedSeconds()*M_PI/5; M3DVector3f at={1,0,0}; M3DVector3f up={0,0,1}; M3DVector3f eye; eye[0]=6.0f*cos(angle); eye[1]=6.0f*sin(angle); eye[2]=kz; LookAt(cameraFrame,eye,at,up); geometryPipeline.SetMatrixStacks(modelView,projection); //swiatlo M3DVector3f ambientLight = {1.0f, 1.0f, 1.0f}; M3DVector3f position = {2.0f, 2.0f, 5.0f}; M3DVector3f color = {1.0f, 1.0f, 1.0f}; float l_angle = 90.0f; float attenuation0 = 0.5f; float attenuation1 = 0.02f; float attenuation2 = 0.05f; M3DVector3f ambientColor = {0.1f, 0.1, 0.1}; M3DVector3f diffuseColor = {0.184f, 0.598f, 0.75f}; M3DVector3f specularColor = {1.0f, 1.0f, 1.0f}; float specularExponent = 9; float ico_vertices[3 * 12] = { 0., 0., -0.9510565162951536, 0., 0., 0.9510565162951536, -0.85065080835204, 0., -0.42532540417601994, 0.85065080835204, 0., 0.42532540417601994, 0.6881909602355868, -0.5, -0.42532540417601994, 0.6881909602355868, 0.5, -0.42532540417601994, -0.6881909602355868, -0.5, 0.42532540417601994, -0.6881909602355868, 0.5, 0.42532540417601994, -0.2628655560595668, -0.8090169943749475, -0.42532540417601994, -0.2628655560595668, 0.8090169943749475, -0.42532540417601994, 0.2628655560595668, -0.8090169943749475, 0.42532540417601994, 0.2628655560595668, 0.8090169943749475, 0.42532540417601994}; int ico_faces[3*20] = { 1 , 11 , 7 , 1 , 7 , 6 , 1 , 6 , 10 , 1 , 10 , 3 , 1 , 3 , 11 , 4 , 8 , 0 , 5 , 4 , 0 , 9 , 5 , 0 , 2 , 9 , 0 , 8 , 2 , 0 , 11 , 9 , 7 , 7 , 2 , 6 , 6 , 8 , 10 , 10 , 4 , 3 , 3 , 5 , 11 , 4 , 10 , 8 , 5 , 3 , 4 , 9 , 11 , 5 , 2 , 7 , 9 , 8 , 6 , 2 }; projection.LoadMatrix(viewFrustum.GetProjectionMatrix()); cameraFrame.GetCameraMatrix(mCamera); modelView.LoadMatrix(mCamera); modelView.PushMatrix(); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, l_angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); glPolygonOffset(1.0f, 1.0f); drawGrid(); glEnable(GL_POLYGON_OFFSET_FILL); drawGrid(); glDisable(GL_POLYGON_OFFSET_FILL); modelView.Translate(-2.0f,-2.0f,2.0f); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, l_angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); drawTriangles(20, ico_vertices, ico_faces); modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(2.0,2.0,2.0); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, l_angle); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); drawSmoothTriangles(20, ico_vertices, ico_faces); modelView.PopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // 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) { load_vertices("geode_vertices.dat", vertices); load_faces("geode_faces.dat", faces); glGenBuffers(1, &vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[0], GL_STATIC_DRAW); glVertexAttribPointer(GLT_ATTRIBUTE_VERTEX, 4 ,GL_FLOAT,GL_FALSE, sizeof(float) * 7, (const GLvoid *)0); glVertexAttribPointer(GLT_ATTRIBUTE_NORMAL, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 7, (const GLvoid *)(4*sizeof(float)) ); glEnableVertexAttribArray(GLT_ATTRIBUTE_VERTEX); glEnableVertexAttribArray(GLT_ATTRIBUTE_NORMAL); //--- glGenBuffers(1, &faces_buffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, faces_buffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, faces.size() * sizeof(GLuint), &faces[0], GL_STATIC_DRAW); //--- // Clear the window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Obracanie widoku float angle =timer.GetElapsedSeconds()*PI/4; posVector[0] = -8.0f * cos(angle / 2.0f); posVector[1] = -8.0f * sin(angle / 2.0f); posVector[2] = 5.0f; swiatlo0.position[0] = 8.0f * cos(-angle); swiatlo0.position[1] = 15.0f * sin(-angle); swiatlo0.position[2] = 5.0f; LookAt(viewFrame, posVector, atVector, upVector); geometryPipeline.SetMatrixStacks(modelView,projection); projection.LoadMatrix(viewFrustum.GetProjectionMatrix()); modelView.PushMatrix(); M3DMatrix44f mCamera; viewFrame.GetCameraMatrix(mCamera); modelView.LoadMatrix(mCamera); modelView.PushMatrix(); //glUseProgram(shader); modelView.Translate(swiatlo0.position[0], swiatlo0.position[1], swiatlo0.position[2]); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); modelView.PopMatrix(); //mno¿enie macierzy //modelView.MultMatrix(mCamera); // modelView.PushMatrix(); //m3dMatrixMultiply44(mModelViewProjection, viewFrustum.GetProjectionMatrix(), mCamera); // wrzucanie do shadera glUniformMatrix3fv(NMatrixLocation, 1, GL_FALSE, geometryPipeline.GetNormalMatrix()); glUniformMatrix4fv(VMmatrixLocation, 1, GL_FALSE, mCamera); glUniform3fv(iambient_component_location, 1, iambient_component); glUniform3fv(swiatlo0_location, 1, swiatlo0.position); glUniform3fv(swiatlo0_idiffuse_location, 1, swiatlo0.idiffuse); glUniform3fv(swiatlo0_ispecular_location, 1, swiatlo0.ispecular); glUniform3fv(swiatlo0_attenuation_location, 1, swiatlo0.attenuation); glUniform1f(material0_ka_location, material0.ka); glUniform1f(material0_kd_location, material0.kd); glUniform1f(material0_ks_location, material0.ks); glUniform1f(material0_alpha_location, material0.alpha); //-- glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewMatrix()); //DrawPramid(0.5,0.0,1.0); drawTriangles(20,ico_vertices,ico_faces); // rysowanie siatki -------------------------------------------------------------------------- glEnable(GL_CULL_FACE); glPolygonOffset(1.0f, 1.0f); glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0, 1.0, 1.0); glEnable(GL_POLYGON_OFFSET_FILL); glBegin(GL_QUADS); glVertex3f(10, -10.0f, 0.0f); glVertex3f(-10, -10.0f, 0.0f); glVertex3f(-10, 10.0f, 0.0f); glVertex3f(10, 10.0f, 0.0f); glEnd(); glDisable(GL_POLYGON_OFFSET_FILL); glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0, 1.0, 1.0); for(int i=-10;i<=10;i++){ glBegin(GL_LINES); glVertex3f((float)i, -10.0f, 0.0f); glVertex3f((float)i, 10.0f, 0.0f); glEnd(); } for(int i=-10;i<=10;i++){ glBegin(GL_LINES); glVertex3f(-10.0f, (float)i, 0.0f); glVertex3f(10.0f, (float)i, 0.0f); glEnd(); } glDisable(GL_CULL_FACE); //sphereBatch.Draw(); glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewMatrix()); modelView.PopMatrix(); // rysowanie siatki - koniec ------------------------------------------------------------------- //matrixStack.Translate(10.0f,1.0f,0.0f); // macierz translacji i macierz rotacji //M3DMatrix44f mT,mR; // m3dTranslationMatrix44(mT,0.0f,3.0f,0.0f); //m3dRotationMatrix44(mR, angle, 0.0f, 0.0f, 1.0f); //mno¿enie macierzy translacji i macierzy rotacji //m3dMatrixMultiply44(mM,mT,mR); //mno¿enie macierzy przekszta³ceñ i macierzy projekcji modelwidok // m3dMatrixMultiply44(mModelViewProjection,mModelViewProjection, mM); //wysy³anie macierzy projekcji modelwidok do shadera //glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, mModelViewProjection); //TriangleFace(position,color,atVector); //DrawPramid(0.5,0.0,1.0); //drawTriangles(20, ico_vertices, ico_faces); //matrixStack.PopMatrix(); //matrixStack.Rotate(45.0,0,0,1); //matrixStack.Translate(0.0,0.0,1.0); //glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); //DrawPramid(0.5,0.0,1.0); glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewMatrix()); modelView.PopMatrix(); glUseProgram(Pshader);//wywo³anie shadera // Perform the buffer swap to display back buffer glutSwapBuffers(); glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // Render a frame. The owning framework is responsible for buffer swaps, // flushes, etc. void RenderScene(void) { // first render the scene in HDR to fbo glBindFramebuffer(GL_DRAW_FRAMEBUFFER, hdrFBO[0]); glDrawBuffers(1, &fboBuffs[0]); glClearColor(vSkyBlue[0], vSkyBlue[1], vSkyBlue[2], vSkyBlue[3]); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Draw to two textures, the first contains scene data // the second contains only the bright areas modelViewMatrix.PushMatrix(); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelViewMatrix.MultMatrix(mCamera); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble // Draw the floor SetupTexReplaceProg(vLightPos, vWhite); floorBatch.Draw(); // Draw the window modelViewMatrix.PushMatrix(); modelViewMatrix.Translate(0.0f, -0.4f, -4.0f); modelViewMatrix.Rotate(10.0, 0.0, 1.0, 0.0); glBindTexture(GL_TEXTURE_2D, windowTexture); // Window Tex // First draw the window contents from texture SetupTexReplaceProg(vLightPos, vWhiteX2); windowBatch.Draw(); // Now draw the border and the grid SetupFlatColorProg(vLightPos, vLtGrey); windowGridBatch.Draw(); windowBorderBatch.Draw(); modelViewMatrix.PopMatrix(); modelViewMatrix.PopMatrix(); projectionMatrix.PushMatrix(); projectionMatrix.LoadMatrix(orthoMatrix); modelViewMatrix.PushMatrix(); modelViewMatrix.LoadIdentity(); // Combine original scene with blurred bright textures // to create the bloom effect glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glDrawBuffers(1,windowBuff); glViewport(0, 0, screenWidth, screenHeight); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SetupHDRProg(); screenQuad.Draw(); modelViewMatrix.PopMatrix(); projectionMatrix.PopMatrix(); // Put the texture units back the way they were glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0); // Do the buffer Swap glutSwapBuffers(); // Do it again glutPostRedisplay(); }
void RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(shader); static CStopWatch Timer; float angle = Timer.GetElapsedSeconds() * 3/7; GLfloat position[] = { 1.0f, 1.0f, .5f }; GLfloat color[] = { 1.0f, 1.0f, 1.0f }; GLfloat angle2 = 90.0f; GLfloat attenuation0 = 0.1f; GLfloat attenuation1 = 0.1f; GLfloat attenuation2 = 0.1f; GLfloat ambientColor[] = { 0.1f, 0.5f, 0.1f }; GLfloat diffuseColor[] = { 1.0f, 1.0f, 0.0f }; GLfloat specularColor[] = { 0.0f, 0.0f, 1.0f }; GLfloat specularExponent = 100.0f; GLMatrixStack modelView; GLMatrixStack projection; M3DVector3f at={0,0,0}; M3DVector3f up={0,0,1}; M3DVector3f eye; eye[0] = 2 * cos(angle); eye[1] = 2 * sin(angle); eye[2] = 10; LookAt(cameraFrame,eye,at,up); GLGeometryTransform geometryPipeline; geometryPipeline.SetMatrixStacks(modelView,projection); projection.LoadMatrix(frustum.GetProjectionMatrix()); M3DMatrix44f mCamera; cameraFrame.GetCameraMatrix(mCamera); modelView.LoadMatrix(mCamera); modelView.PushMatrix(); for(int i=-10; i<=10; ++i) { glBegin(GL_LINES); glVertex3f(-10, i, 0); glVertex3f(10, i, 0); glEnd(); glBegin(GL_LINES); glVertex3f(i, -10, 0); glVertex3f(i, 10, 0); glEnd(); } modelView.PopMatrix(); modelView.PushMatrix(); modelView.Translate(0,0.0,0.0); glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix()); glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix()); glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix()); glUniform3fv(shaderPositionLocation, 1, position); glUniform3fv(shaderColorLocation, 1, color); glUniform1f(shaderAngleLocation, angle2); glUniform1f(shaderAttenuation0Location, attenuation0); glUniform1f(shaderAttenuation1Location, attenuation1); glUniform1f(shaderAttenuation2Location, attenuation2); glUniform3fv(shaderAmbientColorLocation, 1, ambientColor); glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor); glUniform3fv(shaderSpecularColorLocation, 1, specularColor); glUniform1f(shaderSpecularExponentLocation, specularExponent); GLuint vertex_buffer; glGenBuffers(1,&vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBufferData(GL_ARRAY_BUFFER,n_vertices*sizeof(float)*7,&vertices[0],GL_STATIC_DRAW); if(glGetError()!=GL_NO_ERROR) { fprintf(stderr,"error copying vertices\n"); } glVertexAttribPointer(GLT_ATTRIBUTE_VERTEX,4,GL_FLOAT,GL_FALSE,sizeof(float)*7,(const GLvoid *)0); glVertexAttribPointer(GLT_ATTRIBUTE_NORMAL,3,GL_FLOAT,GL_FALSE,sizeof(float)*7,(const GLvoid *)(4*sizeof(float)) ); glEnableVertexAttribArray(GLT_ATTRIBUTE_VERTEX); glEnableVertexAttribArray(GLT_ATTRIBUTE_NORMAL); GLuint faces_buffer; glGenBuffers(1,&faces_buffer); if(glGetError()!=GL_NO_ERROR) { fprintf(stderr,"faces_buffer invalid\n"); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,faces_buffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER,n_faces*sizeof(GLuint)*3,&faces[0],GL_STATIC_DRAW); if(glGetError()!=GL_NO_ERROR) { fprintf(stderr,"error copying faces\n"); } glDrawElements(GL_TRIANGLES,3*n_faces,GL_UNSIGNED_INT,0); modelView.PopMatrix(); // Perform the buffer swap to display back buffer glUseProgram(0); glutSwapBuffers(); glutPostRedisplay(); }