Esempio n. 1
0
void RenderSmoothTwentatenta()
{
	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 };

	  drawSmoothTriangles(20, ico_vertices, ico_faces);
}
Esempio n. 2
0
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();
	
}