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 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(); }