/////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Everything is white GLfloat vWhite [] = { 1.0f, 1.0f, 1.0f, 1.0f }; #ifndef OPENGL_ES shaderManager.UseStockShader(GLT_SHADER_FLAT, viewFrustum.GetProjectionMatrix(), vWhite); // Draw small stars glPointSize(1.0f); #else glUseProgram(pointSizeShader); GLint iTransform, iColor, iPointSize; iTransform = glGetUniformLocation(pointSizeShader, "mvpMatrix"); glUniformMatrix4fv(iTransform, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); iColor = glGetUniformLocation(pointSizeShader, "vColor"); glUniform4fv(iColor, 1, vWhite); iPointSize = glGetUniformLocation(pointSizeShader, "fPointSize"); glUniform1f(iPointSize, 1.0f); #endif smallStarBatch.Draw(); // Draw medium sized stars #ifdef OPENGL_ES iPointSize = glGetUniformLocation(pointSizeShader, "fPointSize"); glUniform1f(iPointSize, 4.0f); #else glPointSize(4.0f); #endif mediumStarBatch.Draw(); // Draw largest stars #ifdef OPENGL_ES iPointSize = glGetUniformLocation(pointSizeShader, "fPointSize"); glUniform1f(iPointSize, 8.0f); #else glPointSize(8.0f); #endif largeStarBatch.Draw(); // Draw the "moon" moonBatch.Draw(); // Draw distant horizon glLineWidth(3.5); mountainRangeBatch.Draw(); moonBatch.Draw(); // Swap buffers glutSwapBuffers(); }
/////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { static CStopWatch timer; // Clear the window glClear(GL_COLOR_BUFFER_BIT); // Everything is white GLfloat vWhite [] = { 1.0f, 1.0f, 1.0f, 1.0f }; glBindTexture(GL_TEXTURE_2D, starTexture); glUseProgram(starFieldShader); glUniformMatrix4fv(locMVP, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); glUniform1i(locStarTexture, 0); // Draw small stars glPointSize(4.0f); smallStarBatch.Draw(); // Draw medium sized stars glPointSize(8.0f); mediumStarBatch.Draw(); // Draw largest stars glPointSize(12.0f); largeStarBatch.Draw(); // Draw distant horizon shaderManager.UseStockShader(GLT_SHADER_FLAT, viewFrustum.GetProjectionMatrix(), vWhite); glLineWidth(3.5); mountainRangeBatch.Draw(); // Draw the "moon" glBindTexture(GL_TEXTURE_2D_ARRAY, moonTexture); glUseProgram(moonShader); glUniformMatrix4fv(locMoonMVP, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); glUniform1i(locMoonTexture, 0); // fTime goes from 0.0 to 28.0 and recycles float fTime = timer.GetElapsedSeconds(); fTime = fmod(fTime, 28.0f); glUniform1f(locTimeStamp, fTime); moonBatch.Draw(); // Swap buffers glutSwapBuffers(); glutPostRedisplay(); }
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); }
// Called to draw scene void RenderScene(void) { static CStopWatch timer; // Clear the window and the depth buffer glClear(GL_COLOR_BUFFER_BIT); // Turn on additive blending glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); // Let the vertex program determine the point size glEnable(GL_PROGRAM_POINT_SIZE); // Bind to our shader, set uniforms glUseProgram(starFieldShader); glUniformMatrix4fv(locMVP, 1, GL_FALSE, viewFrustum.GetProjectionMatrix()); glUniform1i(locTexture, 0); // fTime goes from 0.0 to 999.0 and recycles float fTime = timer.GetElapsedSeconds() * 10.0f; fTime = fmod(fTime, 999.0f); glUniform1f(locTimeStamp, fTime); // Draw the stars starsBatch.Draw(); glutSwapBuffers(); glutPostRedisplay(); }
/////////////////////////////////////////////////////////////////////////////// // 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 GetViewProjectionMatrix(float *viewProjectionMatrix) { M3DMatrix44f viewMatrix; cameraFrame.GetCameraMatrix(viewMatrix); m3dMatrixMultiply44(viewProjectionMatrix, viewFrustum.GetProjectionMatrix(), viewMatrix); }
/////////////////////////////////////////////////////////////////////////////// // 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 RenderScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glEnable( GL_DEPTH_TEST ) ; glUseProgram(shader); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); float angle = timer.GetElapsedSeconds(); M3DVector3f eye = {cos(angle)*4.0f,sin(angle)*4.0,sin(angle)*4.0f}; M3DVector3f at = {0,0,0}; M3DVector3f up = {0.0f,0.0f,1.0f}; GLFrame cameraFrame; LookAt(cameraFrame, eye, at, up); cameraFrame.GetCameraMatrix(cameraMatrix); m3dMatrixMultiply44(matrix, viewFrustum.GetProjectionMatrix(), cameraMatrix); M3DMatrix44f tMatrix; m3dTranslationMatrix44(tMatrix, 0, 0, 0); m3dMatrixMultiply44(matrix, tMatrix, matrix); if((sin(angle) < 0 && sin(angle-0.003) > 0) || (sin(angle) > 0 && sin(angle-0.003) < 0)) { debugMatrix44(matrix); } glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,matrix); // drawGrid(0.1); drawPyramid(); glutSwapBuffers(); glutPostRedisplay(); }
/////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Everything is white GLfloat vWhite [] = { 1.0f, 1.0f, 1.0f, 1.0f }; shaderManager.UseStockShader(GLT_SHADER_FLAT, viewFrustum.GetProjectionMatrix(), vWhite); // Draw small stars glPointSize(1.0f); smallStarBatch.Draw(); // Draw medium sized stars glPointSize(4.0f); mediumStarBatch.Draw(); // Draw largest stars glPointSize(8.0f); largeStarBatch.Draw(); // Draw the "moon" moonBatch.Draw(); // Draw distant horizon glLineWidth(3.5); mountainRangeBatch.Draw(); moonBatch.Draw(); // Swap buffers glutSwapBuffers(); }
/////////////////////////////////////////////////////////////////////////////// // 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); }
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); }
/////////////////////////////////////////////////// // 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 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); }
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); }
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 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) { // Prevent a divide by zero if ( h == 0 ) { h = 1; } // Set viewport to window dimensions glViewport(0, 0, w, h); GLfloat fAspect = (GLfloat)w/(GLfloat)h; // Produce the perspective projection viewFrustum.setPerspective(80.0f, fAspect, 1.0f, 120.0f); projectionMatrix.setMatrix(viewFrustum.GetProjectionMatrix()); transformPipeline.setMatrixStacks(modelViewMatrix, 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(); }
/////////////////////////////////////////////////////////////////////////////// // 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 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 renderScene(void) { float angle = timer.GetElapsedSeconds() * 3.14f; location[0] = 6.0f * cos(angle); location[1] = 6.0f * sin(angle); location[2] = 5.0f; lookAt(cameraFrame, location, target, upDir); cameraFrame.GetCameraMatrix(cameraMatrix); m3dMatrixMultiply44(MVPMatrix, viewFrustum.GetProjectionMatrix(), cameraMatrix); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glUseProgram(shader); glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, MVPMatrix); glBegin(GL_QUADS); glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0f, 0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f); glEnd(); glBegin(GL_TRIANGLES); glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0f, 1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f); glVertex3f(1.0f, 1.0f, 0.0f); glVertex3f(0.0f, 0.0f, 2.0f); //-- glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0f, 1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glVertex3f(0.0f, 0.0f, 2.0f); //-- glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 0.0f, 1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glVertex3f(0.0f, 0.0f, 2.0f); glVertex3f(-1.0f, 1.0f, 0.0f); //-- glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 0.0f, 0.0f, 1.0f); glVertex3f(1.0f, -1.0f, 0.0f); glVertex3f(0.0f, 0.0f, 2.0f); glVertex3f(-1.0f, -1.0f, 0.0f); glEnd(); glutSwapBuffers(); glutPostRedisplay(); }
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); }
/** * 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); transformPipeline.setMatrixStacks(modelViewMatrix, projectionMatrix); viewFrustum.setPerspective(35.0f, float(w) / float(h), 1.0f, 100.0f); projectionMatrix.setMatrix(viewFrustum.GetProjectionMatrix()); modelViewMatrix.identity(); GenerateOrtho2DMat(w, h); screenWidth = w; screenHeight = h; // resize texture glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, depthTextureName); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 8, GL_DEPTH_COMPONENT24, w, h, GL_FALSE); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msTexture[0]); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 8, GL_RGBA8, w, h, GL_FALSE); }