void setup_rc() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); shader_light = gltLoadShaderPairWithAttributes("gouraud_shading.vp", "gouraud_shading.fp", 3, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color", GLT_ATTRIBUTE_NORMAL, "vertex_normal"); shader_color = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color"); mvp_matrix_location_shader_color = glGetUniformLocation(shader_color, "mvp_matrix"); mvp_matrix_location = glGetUniformLocation(shader_light, "mvp_matrix"); mv_matrix_location = glGetUniformLocation(shader_light, "mv_matrix"); v_matrix_location = glGetUniformLocation(shader_light, "v_matrix"); normal_matrix_location = glGetUniformLocation(shader_light, "normal_matrix"); intensity_ambient_component_location = glGetUniformLocation(shader_light, "intensity_ambient_component"); light_0_position_location = glGetUniformLocation(shader_light, "light_0.position"); light_0_intensity_diffuse_location = glGetUniformLocation(shader_light, "light_0.intensity_diffuse"); light_0_intensity_specular_location = glGetUniformLocation(shader_light, "light_0.intensity_specular"); light_0_attenuation_location = glGetUniformLocation(shader_light, "light_0.attenuation"); material_0_ka_location = glGetUniformLocation(shader_light, "material_0.ka"); material_0_kd_location = glGetUniformLocation(shader_light, "material_0.kd"); material_0_ks_location = glGetUniformLocation(shader_light, "material_0.ks"); material_0_alpha_location = glGetUniformLocation(shader_light, "material_0.alpha"); light_0.set_position(0.0f, 0.0f, 0.0f); light_0.set_intensity_diffuse(1.0f, 1.0f, 1.0f); light_0.set_intensity_specular(1.0f, 1.0f, 1.0f); light_0.set_attenuation(0.0f, 0.1f, 0.0f); material_0.set_parameters(1.0f, 1.0f, 1.0f, 200.0f); geometry_pipeline.SetMatrixStacks(mv_stack, p_stack); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glFrontFace(GL_CCW); }
/////////////////////////////////////////////////////////////////////////////// // 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); }
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 SetupRC() { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_DEPTH_TEST); shader = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal"); fprintf(stdout, "GLT_ATTRIBUTE_VERTEX : %d\nGLT_ATTRIBUTE_COLOR : %d \n", GLT_ATTRIBUTE_VERTEX, GLT_ATTRIBUTE_COLOR); shaderColorLocation = glGetUniformLocation(shader, "light1.color"); shaderAngleLocation = glGetUniformLocation(shader, "light1.angle"); shaderAttenuation0Location = glGetUniformLocation(shader, "light1.attenuation0"); shaderAttenuation1Location = glGetUniformLocation(shader, "light1.attenuation1"); shaderAttenuation2Location = glGetUniformLocation(shader, "light1.attenuation2"); MVMatrixLocation = glGetUniformLocation(shader,"MVMatrix"); MVPMatrixLocation = glGetUniformLocation(shader,"MVPMatrix"); normalMatrixLocation = glGetUniformLocation(shader,"normalMatrix"); ambientLightLocation = glGetUniformLocation(shader,"ambientLight"); shaderPositionLocation = glGetUniformLocation(shader, "light1.position"); shaderAmbientColorLocation = glGetUniformLocation(shader, "material.ambientColor"); shaderDiffuseColorLocation = glGetUniformLocation(shader, "material.diffuseColor"); shaderSpecularColorLocation = glGetUniformLocation(shader, "material.specularColor"); shaderSpecularExponentLocation = glGetUniformLocation(shader, "material.specularExponent"); if(MVMatrixLocation==-1){ fprintf(stderr,"uniform MVMatrix could not be found\n"); } geometryPipeline.SetMatrixStacks(modelView, projection); M3DVector3f eye = {1.0f, 1.0f, 1.0f}; M3DVector3f at = {5.0f, 5.0f, 5.0f}; M3DVector3f up = {1.0f, 1.0f, 1.0f}; LookAt(cameraFrame, eye, at, up); }
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; // 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(); }
/////////////////////////////////////////////////////////////////////////////// // 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 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 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; }
/////////////////////////////////////////////////////////////////////////////// // 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); modelViewMatrix.LoadIdentity(); // update screen sizes screenWidth = nWidth; screenHeight = nHeight; GenerateOrtho2DMat(nWidth, nHeight, hdrTexturesWidth[curHDRTex], hdrTexturesHeight[curHDRTex]); }
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 SetupRC() { glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glEnable(GL_DEPTH_TEST); shader = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_COLOR, "vColor"); fprintf(stdout, "GLT_ATTRIBUTE_VERTEX : %d\nGLT_ATTRIBUTE_COLOR : %d \n", GLT_ATTRIBUTE_VERTEX, GLT_ATTRIBUTE_COLOR); MVMatrixLocation=glGetUniformLocation(shader,"MVMatrix"); if(MVMatrixLocation==-1){ fprintf(stderr,"uniform MVMatrix could not be found\n"); } geometryPipeline.SetMatrixStacks(modelView, projection); M3DVector3f eye = {1.0f, 1.0f, 10.0f}; M3DVector3f at = {0.0f, 0.0f, 0.0f}; M3DVector3f up = {0.0f, 0.0f, 0.5f}; LookAt(cameraFrame, eye, at, up); }
///////////////////////////////////////////////////////////////////// // 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); }
// Initialisierung des Rendering Kontextes void SetupRC() { // Schwarzer Hintergrund glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // In Uhrzeigerrichtung zeigende Polygone sind die Vorderseiten. // Dies ist umgekehrt als bei der Default-Einstellung weil wir Triangle_Fans benützen glFrontFace(GL_CW); //initialisiert die standard shader shaderManager.InitializeStockShaders(); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); //erzeuge die geometrie CreateCone(0, 0, 0); CreateCube(0, 0, 0); CreateCylinder(0, 0, 0); CreateSphere(0, 0, 0); InitGUI(); }
/////////////////////////////////////////////////////////////////////////////// // 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 setup_rc() { 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); //--- glClearColor(0.0f, 0.0f, 0.0f, 1.0f); shader_light = gltLoadShaderPairWithAttributes("gouraud_shading.vp", "gouraud_shading.fp", 3, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color", GLT_ATTRIBUTE_NORMAL, "vertex_normal"); shader_color = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color"); mvp_matrix_location_shader_color = glGetUniformLocation(shader_color, "mvp_matrix"); mvp_matrix_location = glGetUniformLocation(shader_light, "mvp_matrix"); mv_matrix_location = glGetUniformLocation(shader_light, "mv_matrix"); v_matrix_location = glGetUniformLocation(shader_light, "v_matrix"); normal_matrix_location = glGetUniformLocation(shader_light, "normal_matrix"); intensity_ambient_component_location = glGetUniformLocation(shader_light, "intensity_ambient_component"); light_0_position_location = glGetUniformLocation(shader_light, "light_0.position"); light_0_intensity_diffuse_location = glGetUniformLocation(shader_light, "light_0.intensity_diffuse"); light_0_intensity_specular_location = glGetUniformLocation(shader_light, "light_0.intensity_specular"); light_0_attenuation_location = glGetUniformLocation(shader_light, "light_0.attenuation"); material_0_ka_location = glGetUniformLocation(shader_light, "material_0.ka"); material_0_kd_location = glGetUniformLocation(shader_light, "material_0.kd"); material_0_ks_location = glGetUniformLocation(shader_light, "material_0.ks"); material_0_alpha_location = glGetUniformLocation(shader_light, "material_0.alpha"); light_0.set_position(0.0f, 0.0f, 0.0f); light_0.set_intensity_diffuse(1.0f, 1.0f, 1.0f); light_0.set_intensity_specular(1.0f, 1.0f, 1.0f); light_0.set_attenuation(0.0f, 0.1f, 0.0f); material_0.set_parameters(1.0f, 1.0f, 1.0f, 200.0f); geometry_pipeline.SetMatrixStacks(mv_stack, p_stack); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glFrontFace(GL_CCW); }
void setupRC() { glClearColor(0.5f, 0.5f, 0.5f, 1.0f); glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); shaderManager.InitializeStockShaders(); pipelineTransform.SetMatrixStacks(modelViewM, projectionM); generateCuboidBatch(cuboidBatch, cuboidLength, cuboidWidth, cuboidHeigth); glGenTextures(2, textureID); glBindTexture(GL_TEXTURE_2D, textureID[0]); LoadTGATexture("stone.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D, textureID[1]); LoadTGATexture("black_white.tga", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_REPEAT); if(gltIsExtSupported("GL_EXT_texture_filter_anisotropic")) { isAnisotropySupported = true; glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &largest); printf("anisotropy is supported, largest %f\n", largest); } }
/////////////////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { // Black background glClearColor(0.7f, 0.7f, 0.7f, 1.0f ); shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); cameraFrame.MoveForward(-15.0f); ////////////////////////////////////////////////////////////////////// // Some points, more or less in the shape of Florida GLfloat vCoast[24][3] = {{2.80, 1.20, 0.0 }, {2.0, 1.20, 0.0 }, {2.0, 1.08, 0.0 }, {2.0, 1.08, 0.0 }, {0.0, 0.80, 0.0 }, {-.32, 0.40, 0.0 }, {-.48, 0.2, 0.0 }, {-.40, 0.0, 0.0 }, {-.60, -.40, 0.0 }, {-.80, -.80, 0.0 }, {-.80, -1.4, 0.0 }, {-.40, -1.60, 0.0 }, {0.0, -1.20, 0.0 }, { .2, -.80, 0.0 }, {.48, -.40, 0.0 }, {.52, -.20, 0.0 }, {.48, .20, 0.0 }, {.80, .40, 0.0 }, {1.20, .80, 0.0 }, {1.60, .60, 0.0 }, {2.0, .60, 0.0 }, {2.2, .80, 0.0 }, {2.40, 1.0, 0.0 }, {2.80, 1.0, 0.0 }}; // Load point batch pointBatch.Begin(GL_POINTS, 24); pointBatch.CopyVertexData3f(vCoast); pointBatch.End(); // Load as a bunch of line segments lineBatch.Begin(GL_LINES, 24); lineBatch.CopyVertexData3f(vCoast); lineBatch.End(); // Load as a single line segment lineStripBatch.Begin(GL_LINE_STRIP, 24); lineStripBatch.CopyVertexData3f(vCoast); lineStripBatch.End(); // Single line, connect first and last points lineLoopBatch.Begin(GL_LINE_LOOP, 24); lineLoopBatch.CopyVertexData3f(vCoast); lineLoopBatch.End(); // For Triangles, we'll make a Pyramid GLfloat vPyramid[12][3] = { -2.0f, 0.0f, -2.0f, 2.0f, 0.0f, -2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f, -2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f, 2.0f, -2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f, -2.0f, 0.0f, 2.0f, -2.0f, 0.0f, -2.0f, 0.0f, 4.0f, 0.0f}; triangleBatch.Begin(GL_TRIANGLES, 12); triangleBatch.CopyVertexData3f(vPyramid); triangleBatch.End(); // For a Triangle fan, just a 6 sided hex. Raise the center up a bit GLfloat vPoints[100][3]; // Scratch array, more than we need int nVerts = 0; GLfloat r = 3.0f; vPoints[nVerts][0] = 0.0f; vPoints[nVerts][1] = 0.0f; vPoints[nVerts][2] = 0.0f; for(GLfloat angle = 0; angle < M3D_2PI; angle += M3D_2PI / 6.0f) { nVerts++; vPoints[nVerts][0] = float(cos(angle)) * r; vPoints[nVerts][1] = float(sin(angle)) * r; vPoints[nVerts][2] = -0.5f; } // Close the fan nVerts++; vPoints[nVerts][0] = r; vPoints[nVerts][1] = 0; vPoints[nVerts][2] = 0.0f; // Load it up triangleFanBatch.Begin(GL_TRIANGLE_FAN, 8); triangleFanBatch.CopyVertexData3f(vPoints); triangleFanBatch.End(); // For triangle strips, a little ring or cylinder segment int iCounter = 0; GLfloat radius = 3.0f; for(GLfloat angle = 0.0f; angle <= (2.0f*M3D_PI); angle += 0.3f) { GLfloat x = radius * sin(angle); GLfloat y = radius * cos(angle); // Specify the point and move the Z value up a little vPoints[iCounter][0] = x; vPoints[iCounter][1] = y; vPoints[iCounter][2] = -0.5; iCounter++; vPoints[iCounter][0] = x; vPoints[iCounter][1] = y; vPoints[iCounter][2] = 0.5; iCounter++; } // Close up the loop vPoints[iCounter][0] = vPoints[0][0]; vPoints[iCounter][1] = vPoints[0][1]; vPoints[iCounter][2] = -0.5; iCounter++; vPoints[iCounter][0] = vPoints[1][0]; vPoints[iCounter][1] = vPoints[1][1]; vPoints[iCounter][2] = 0.5; iCounter++; // Load the triangle strip triangleStripBatch.Begin(GL_TRIANGLE_STRIP, iCounter); triangleStripBatch.CopyVertexData3f(vPoints); triangleStripBatch.End(); }
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(); }
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 SetupRC() { glClearColor(0.7f, 0.7f, 0.7f, 1.0f ); shaderManager.InitializeStockShaders(); glEnable(GL_DEPTH_TEST); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); cameraFrame.MoveForward(-15.0f); // 一组图元顶点——长得像佛罗里达州 GLfloat vCoast[24][3] = { {2.80, 1.20, 0.0 }, {2.0, 1.20, 0.0 }, {2.0, 1.08, 0.0 }, {2.0, 1.08, 0.0 }, {0.0, 0.80, 0.0 }, {-.32, 0.40, 0.0 }, {-.48, 0.2, 0.0 }, {-.40, 0.0, 0.0 }, {-.60, -.40, 0.0 }, {-.80, -.80, 0.0 }, {-.80, -1.4, 0.0 }, {-.40, -1.60, 0.0 }, {0.0, -1.20, 0.0 }, { .2, -.80, 0.0 }, {.48, -.40, 0.0 }, {.52, -.20, 0.0 }, {.48, .20, 0.0 }, {.80, .40, 0.0 }, {1.20, .80, 0.0 }, {1.60, .60, 0.0 }, {2.0, .60, 0.0 }, {2.2, .80, 0.0 }, {2.40, 1.0, 0.0 }, {2.80, 1.0, 0.0 } }; // 点批次 pointBatch.Begin(GL_POINTS, 24); pointBatch.CopyVertexData3f(vCoast); pointBatch.End(); // 线段批次 lineBatch.Begin(GL_LINES, 24); lineBatch.CopyVertexData3f(vCoast); lineBatch.End(); // 线批次 lineStripBatch.Begin(GL_LINE_STRIP, 24); lineStripBatch.CopyVertexData3f(vCoast); lineStripBatch.End(); // 循环线批次 lineLoopBatch.Begin(GL_LINE_LOOP, 24); lineLoopBatch.CopyVertexData3f(vCoast); lineLoopBatch.End(); GLfloat vPyramid[12][3] = { -2.0f, 0.0f, -2.0f, 2.0f, 0.0f, -2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f, -2.0f, 2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f, 2.0f, 0.0f, 2.0f, -2.0f, 0.0f, 2.0f, 0.0f, 4.0f, 0.0f, -2.0f, 0.0f, 2.0f, -2.0f, 0.0f, -2.0f, 0.0f, 4.0f, 0.0f }; triangleBatch.Begin(GL_TRIANGLES, 12); triangleBatch.CopyVertexData3f(vPyramid); triangleBatch.End(); GLfloat vPoints[100][3]; int nVerts = 0; GLfloat r = 3.0f; vPoints[nVerts][0] = 0.0f; vPoints[nVerts][1] = 0.0f; vPoints[nVerts][2] = 0.0f; for(GLfloat angle = 0; angle < M3D_2PI; angle += M3D_2PI / 6.0f) { nVerts++; vPoints[nVerts][0] = float(cos(angle)) * r; vPoints[nVerts][1] = float(sin(angle)) * r; vPoints[nVerts][2] = -0.5f; } nVerts++; vPoints[nVerts][0] = r; vPoints[nVerts][1] = 0; vPoints[nVerts][2] = 0.0f; triangleFanBatch.Begin(GL_TRIANGLE_FAN, 8); triangleFanBatch.CopyVertexData3f(vPoints); triangleFanBatch.End(); int iCounter = 0; GLfloat radius = 3.0f; for(GLfloat angle = 0.0f; angle <= (2.0f * M3D_PI); angle += 0.3f) { GLfloat x = radius * sin(angle); GLfloat y = radius * cos(angle); vPoints[iCounter][0] = x; vPoints[iCounter][1] = y; vPoints[iCounter][2] = -0.5; iCounter++; vPoints[iCounter][0] = x; vPoints[iCounter][1] = y; vPoints[iCounter][2] = 0.5; iCounter++; } vPoints[iCounter][0] = vPoints[0][0]; vPoints[iCounter][1] = vPoints[0][1]; vPoints[iCounter][2] = -0.5; iCounter++; vPoints[iCounter][0] = vPoints[1][0]; vPoints[iCounter][1] = vPoints[1][1]; vPoints[iCounter][2] = 0.5; iCounter++; triangleStripBatch.Begin(GL_TRIANGLE_STRIP, iCounter); triangleStripBatch.CopyVertexData3f(vPoints); triangleStripBatch.End(); }
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(); }
/////////////////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { GLbyte *pBytes; GLint nWidth, nHeight, nComponents; GLenum format; shaderManager.InitializeStockShaders(); // Black background glClearColor(0.0f, 0.0f, 0.0f, 1.0f ); glEnable(GL_DEPTH_TEST); glLineWidth(2.5f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix); cameraFrame.MoveForward(-15.0f); cameraFrame.MoveUp(6.0f); cameraFrame.RotateLocalX(float(m3dDegToRad(20.0f))); MakeCube(cubeBatch); MakeFloor(floorBatch); // Make top topBlock.Begin(GL_TRIANGLE_FAN, 4, 1); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 0.0f, 0.0f); topBlock.Vertex3f(-1.0f, 1.0f, 1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 1.0f, 0.0f); topBlock.Vertex3f(1.0f, 1.0f, 1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 1.0f, 1.0f); topBlock.Vertex3f(1.0f, 1.0f, -1.0f); topBlock.Normal3f(0.0f, 1.0f, 0.0f); topBlock.MultiTexCoord2f(0, 0.0f, 1.0f); topBlock.Vertex3f(-1.0f, 1.0f, -1.0f); topBlock.End(); // Make Front frontBlock.Begin(GL_TRIANGLE_FAN, 4, 1); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 0.0f, 0.0f); frontBlock.Vertex3f(-1.0f, -1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 1.0f, 0.0f); frontBlock.Vertex3f(1.0f, -1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 1.0f, 1.0f); frontBlock.Vertex3f(1.0f, 1.0f, 1.0f); frontBlock.Normal3f(0.0f, 0.0f, 1.0f); frontBlock.MultiTexCoord2f(0, 0.0f, 1.0f); frontBlock.Vertex3f(-1.0f, 1.0f, 1.0f); frontBlock.End(); // Make left leftBlock.Begin(GL_TRIANGLE_FAN, 4, 1); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 0.0f, 0.0f); leftBlock.Vertex3f(-1.0f, -1.0f, -1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 1.0f, 0.0f); leftBlock.Vertex3f(-1.0f, -1.0f, 1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 1.0f, 1.0f); leftBlock.Vertex3f(-1.0f, 1.0f, 1.0f); leftBlock.Normal3f(-1.0f, 0.0f, 0.0f); leftBlock.MultiTexCoord2f(0, 0.0f, 1.0f); leftBlock.Vertex3f(-1.0f, 1.0f, -1.0f); leftBlock.End(); // Create shadow projection matrix GLfloat floorPlane[] = { 0.0f, 1.0f, 0.0f, 1.0f}; m3dMakePlanarShadowMatrix(shadowMatrix, floorPlane, vLightPos); // Load up four textures glGenTextures(4, textures); // Wood floor pBytes = gltReadTGABits("floor.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // One of the block faces pBytes = gltReadTGABits("Block4.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // Another block face pBytes = gltReadTGABits("block5.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); // Yet another block face pBytes = gltReadTGABits("block6.tga", &nWidth, &nHeight, &nComponents, &format); glBindTexture(GL_TEXTURE_2D, textures[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0, format, GL_UNSIGNED_BYTE, pBytes); free(pBytes); }
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(); }