Esempio n. 1
0
void RenderScene()
{
	static GLfloat vSunColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
	static GLfloat vEarthColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };
	static GLfloat vMoonColor[] = { 1.0f, 1.0f, 0.0f, 1.0f };
	static GLfloat vFloorColor[] = { 0.0f, 1.0f, 0.0f, 1.0f};

	static CStopWatch rotTimer;
	float yRot = rotTimer.GetElapsedSeconds() * 60.0f;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	modelViewMatrix.PushMatrix();	

	M3DMatrix44f mCamera;
	cameraFrame.GetCameraMatrix(mCamera);
	modelViewMatrix.PushMatrix(mCamera);

	M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f };
	M3DVector4f vLightEyePos;
	m3dTransformVector4(vLightEyePos, vLightPos, mCamera);

	shaderManager.UseStockShader(GLT_SHADER_FLAT,
		transformPipeline.GetModelViewProjectionMatrix(),
		vFloorColor);	
	floorBatch.Draw();    

	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

	modelViewMatrix.Translate(0.0f, 0.0f, -3.5f);

	modelViewMatrix.PushMatrix();

	modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);
	shaderManager.UseStockShader(GLT_SHADER_FLAT, 
		transformPipeline.GetModelViewProjectionMatrix(), vSunColor);
	sunSphereBatch.Draw();
	modelViewMatrix.PopMatrix(); 

	modelViewMatrix.Rotate(yRot * -2.0f, 0.0f, 1.0f, 0.0f);
	modelViewMatrix.Translate(0.8f, 0.0f, 0.0f);
	shaderManager.UseStockShader(GLT_SHADER_FLAT, 
		transformPipeline.GetModelViewProjectionMatrix(), vEarthColor);
	earthSphereBatch.Draw();

	modelViewMatrix.Rotate(yRot * -4.0f, 0.0f, 1.0f, 0.0f);
	modelViewMatrix.Translate(0.4f, 0.0f, 0.0f);
	shaderManager.UseStockShader(GLT_SHADER_FLAT, 
		transformPipeline.GetModelViewProjectionMatrix(), vMoonColor);
	moonSphereBatch.Draw();

	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();    
	modelViewMatrix.PopMatrix();   


	glutSwapBuffers();

	glutPostRedisplay();
}
void DrawScene()
{
	modelViewMatrix.PushMatrix();	
		M3DMatrix44f mCamera;
		cameraFrame.GetCameraMatrix(mCamera);

		// Transform the light position into eye coordinates
		M3DVector4f vLightPos = { LIGHT_POSITION[0], LIGHT_POSITION[1], LIGHT_POSITION[2], LIGHT_POSITION[3] };
		M3DVector4f vLightEyePos;
		m3dTransformVector4(vLightEyePos, vLightPos, mCamera);

    /* ------------ */
    /* FERRIS WHEEL */

    modelViewMatrix.PushMatrix();
        /* Position the ferris wheel appropriately. */
      modelViewMatrix.Translate(FERRIS_WHEEL_POSITION[0], FERRIS_WHEEL_POSITION[1], FERRIS_WHEEL_POSITION[2]);

      /* Apply the Translation to this entire block of objects */
      modelViewMatrix.PushMatrix();
        //theWheel.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos, capTexture, wheelTexture, wallTexture, carTexture, currentTextureIndex);
      modelViewMatrix.PopMatrix();

    modelViewMatrix.PopMatrix();

    /* -------------- */
    /* ROLLER COASTER */

    modelViewMatrix.PushMatrix();
      modelViewMatrix.Translate(0.0, 0.0, -10.0);
      //track.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
    modelViewMatrix.PopMatrix();

    /* -------- */
    /* CAROUSEL */  

    modelViewMatrix.PushMatrix();
      //modelViewMatrix.Translate(3.0f, 0.0f, -3.0f);
      modelViewMatrix.Translate(0.0f, 0.0f, -3.0f);
      //carousel.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
      modelViewMatrix.Translate(0.0f, 0.0f, -2.0f);
      //unicorn.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
      //ostrich.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
      turtle.Draw(modelViewMatrix, shaderManager, transformPipeline, vLightEyePos);
    modelViewMatrix.PopMatrix();

	modelViewMatrix.PopMatrix();
}
Esempio n. 3
0
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();
}
Esempio n. 4
0
void RenderScene(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


	modelViewMatrix.PushMatrix();
	{

		modelViewMatrix.Translate(0.0f, 0.0f, viewZ);

		shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeLine.GetModelViewProjectionMatrix(), 0);

		glBindTexture(GL_TEXTURE_2D, uiTextures[TEXTURE_FLOOR]);
		floorBatch.Draw();

		glBindTexture(GL_TEXTURE_2D, uiTextures[TEXTURE_CEILING]);
		ceilingBatch.Draw();

		glBindTexture(GL_TEXTURE_2D, uiTextures[TEXTURE_BRICK]);
		leftWallBatch.Draw();
		rightWallBatch.Draw();
	}

	modelViewMatrix.PopMatrix();

	glutSwapBuffers();
}
Esempio n. 5
0
///////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
    {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT);

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(0.0f, 0.0f, viewZ);
        
        shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0);

        glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_FLOOR]);
        floorBatch.Draw();
        
        glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_CEILING]);
        ceilingBatch.Draw();
        
        glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_BRICK]);
        leftWallBatch.Draw();
        rightWallBatch.Draw();
        
    modelViewMatrix.PopMatrix();

    // Buffer swap
    glutSwapBuffers();
    }
Esempio n. 6
0
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();
}
Esempio n. 7
0
///////////////////////////////////////////////////////////////////////////////
// Draw the scene
//
void DrawWorld(GLfloat yRot)
{
    M3DMatrix44f mCamera;
    modelViewMatrix.GetMatrix(mCamera);
    
    // Need light position relative to the Camera
    M3DVector4f vLightTransformed;
    m3dTransformVector4(vLightTransformed, vLightPos, mCamera);
    
    // Draw the light source as a small white unshaded sphere
    modelViewMatrix.PushMatrix();
    modelViewMatrix.Translatev(vLightPos);
    shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vWhite);
    sphereBatch.Draw();
    modelViewMatrix.PopMatrix();
    
    // Draw stuff relative to the camera
    modelViewMatrix.PushMatrix();
    modelViewMatrix.Translate(0.0f, 0.2f, -2.5f);
    modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);
    
    shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF,
                                 modelViewMatrix.GetMatrix(),
                                 transformPipeline.GetProjectionMatrix(),
                                 vLightTransformed, vGreen, 0);
    torusBatch.Draw();
    modelViewMatrix.PopMatrix();
}
Esempio n. 8
0
void RenderDwudziestoscian(float xPos, float yPos, float zPos, float scale) {
	matrixStack.PushMatrix();

	matrixStack.Translate(xPos, yPos, zPos);
	matrixStack.Scale(scale, scale, scale);

	M3DMatrix44f MVMatrix;
	m3dCopyMatrix44(MVMatrix, matrixStack.GetMatrix());
	
	glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,MVMatrix);

	M3DMatrix44f normalMatrix;
	m3dInvertMatrix44(normalMatrix,MVMatrix);

	float tmp;
	// transponse
	for(int n = 0; n < 3; n++) {
		for(int m = n + 1; m <= 3; m++) {
			tmp = normalMatrix[4*n + m];
			normalMatrix[4*n + m] = normalMatrix[4*m + n];
			normalMatrix[4*m + n] = tmp;
		}
	}

	glUniformMatrix3fv(NormalMatrixLocation,1,GL_FALSE,normalMatrix);

	glDrawElements(GL_TRIANGLES,3*n_faces,GL_UNSIGNED_INT,0);

	matrixStack.PopMatrix();
}
Esempio n. 9
0
void DrawBaeumchen() {

	// Boden
	modelViewMatrix.PushMatrix();
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, -25, 0);
	modelViewMatrix.Scale(20, -0.01, 20);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	modelViewMatrix.PopMatrix();
	DrawCube();

	// Baumstamm
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, 0.0, 0);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.3, 0.5, 0.3);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	modelViewMatrix.PopMatrix();
	DrawCylinder();

	//unterster Kegel
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, 25.0, 0);
	modelViewMatrix.Scale(1.5, 1.5, 1.5);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCone();

	// mittlerer Kegel
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, 40.0, 0);
	modelViewMatrix.Scale(0.75, 0.75, 0.75);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCone();	
	
	// Spitze
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0, 50.0, 0);
	modelViewMatrix.Scale(0.75, 0.75, 0.75);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCone();

	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
}
Esempio n. 10
0
void DrawMaennchen(float angle) {

	//float overallScaleFactor = 0.2 * cos(GL_PI / 200 * angle) + 1;
	float jumpFactor = abs(cos(GL_PI/10 * angle));

	/**
	* Rumpf zeichnen
	**/
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Rotate(angle, 0, -1, 0);
	// generelle Verschiebung aus dem Mittelpunkt heraus
	modelViewMatrix.Translate(200.0f, 0.0f, 0.0f);
	// Verschiebung fuer Huepfbahn
	modelViewMatrix.Translate(0.0f, 30 * jumpFactor, 0);
	//modelViewMatrix.Scale(overallScaleFactor, overallScaleFactor, overallScaleFactor);

	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.9, 1.0, 0.7);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// Hals
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, 55.0f, 0.0f);
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Scale(0.25, 0.15, 0.25);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawCylinder();
	modelViewMatrix.PopMatrix();

	// Kopf
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translate(0.0f, 40.0f, 0.0f);
	modelViewMatrix.Scale(0.72, 0.72, 0.72);
	shaderManager.UseStockShader(GLT_SHADER_FLAT_ATTRIBUTES, transformPipeline.GetModelViewProjectionMatrix());
	DrawSphere();
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();
	
	// Giedmaßen zeichnen - abhaengig vom Rumpf!
	DrawLimbs(angle);

	modelViewMatrix.PopMatrix();
}
///////////////////////////////////////////////////////////////////////////////
// Draw the scene 
// 
void DrawWorld(GLfloat yRot)
{
	M3DMatrix44f mCamera;
	modelViewMatrix.GetMatrix(mCamera);
	
	// Need light position relative to the Camera
	M3DVector4f vLightTransformed;
	m3dTransformVector4(vLightTransformed, vLightPos, mCamera);

	// Draw the light source as a small white unshaded sphere
	modelViewMatrix.PushMatrix();
		modelViewMatrix.Translatev(vLightPos);

		if(bUseFBO)
			UseProcessProgram(vLightPos, vWhite, -1);
		else
			shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vWhite);

		sphereBatch.Draw();
	modelViewMatrix.PopMatrix();

	// Draw stuff relative to the camera
	modelViewMatrix.PushMatrix();
		modelViewMatrix.Translate(0.0f, 0.2f, -2.5f);

		modelViewMatrix.PushMatrix();
			modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);
            modelViewMatrix.Translate(0.0, (GLfloat)-0.60, 0.0);
            modelViewMatrix.Scale((GLfloat)0.02, (GLfloat)0.006, (GLfloat)0.02);
            
            glBindTexture(GL_TEXTURE_2D, ninjaTex[0]);

			if(bUseFBO)
			{
				UseProcessProgram(vLightTransformed, vWhite, 0);
			}
			else
			{
                shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0);
			}
            ninja.Render(0,0);
        modelViewMatrix.PopMatrix();

	modelViewMatrix.PopMatrix();
}
Esempio n. 12
0
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();
}
Esempio n. 13
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();
}
Esempio n. 14
0
// Called to draw scene
void RenderScene(void)
{
    static CStopWatch	rotTimer;
    float yRot = rotTimer.GetElapsedSeconds() * 60.0f;
    
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    modelViewMatrix.PushMatrix();
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.MultMatrix(mCamera);
    
    // Draw the world upside down
    modelViewMatrix.PushMatrix();
    modelViewMatrix.Scale(1.0f, -1.0f, 1.0f); // Flips the Y Axis
    modelViewMatrix.Translate(0.0f, 0.8f, 0.0f); // Scootch the world down a bit...
    glFrontFace(GL_CW);
    DrawSongAndDance(yRot);
    glFrontFace(GL_CCW);
    modelViewMatrix.PopMatrix();
    
    // Draw the solid ground
    glEnable(GL_BLEND);
    glBindTexture(GL_TEXTURE_2D, uiTextures[0]);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    static GLfloat vFloorColor[] = { 1.0f, 1.0f, 1.0f, 0.75f};
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE,
                                 transformPipeline.GetModelViewProjectionMatrix(),
                                 vFloorColor,
                                 0);
    
    floorBatch.Draw();
    glDisable(GL_BLEND);
    
    
    DrawSongAndDance(yRot);
    
    modelViewMatrix.PopMatrix();
    
    
    // Do the buffer Swap
    glutSwapBuffers();
    
    // Do it again
    glutPostRedisplay();
}
Esempio n. 15
0
void drawTorus(GLfloat yRot)
{
    M3DMatrix44f mCamera;
    M3DVector4f vLightTransform;
    modelViewMatrix.GetMatrix(mCamera);
    m3dTransformVector4(vLightTransform,vLightPosition,mCamera);

    modelViewMatrix.PushMatrix();
    modelViewMatrix.Translate(0.0,0.5,-1.0);
    modelViewMatrix.Rotate(yRot,0.0,1.0,0.0);
    shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF,
                                 modelViewMatrix.GetMatrix(),
                                 transformPipeline.GetProjectionMatrix(),
                                 vLightTransform,vGreen,0);
    torusBatch.Draw();
    modelViewMatrix.PopMatrix();
}
Esempio n. 16
0
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
	{
	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	modelViewMatrix.PushMatrix();
		M3DMatrix44f mCamera;
		cameraFrame.GetCameraMatrix(mCamera);
		modelViewMatrix.MultMatrix(mCamera);

		// Reflection step... draw cube upside down, the floor
		// blended on top of it
		if(nStep == 5) {
			glDisable(GL_CULL_FACE);
			modelViewMatrix.PushMatrix();
			modelViewMatrix.Scale(1.0f, -1.0f, 1.0f);
			modelViewMatrix.Translate(0.0f, 2.0f, 0.0f);
			modelViewMatrix.Rotate(35.0f, 0.0f, 1.0f, 0.0f);
			RenderBlock();
			modelViewMatrix.PopMatrix();
			glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			RenderFloor();
			glDisable(GL_BLEND);			
			}


		modelViewMatrix.PushMatrix();

			// Draw normally
			modelViewMatrix.Rotate(35.0f, 0.0f, 1.0f, 0.0f);
			RenderBlock();
		modelViewMatrix.PopMatrix();
		
		
	// If not the reflection pass, draw floor last
	if(nStep != 5)
		RenderFloor();

		
	modelViewMatrix.PopMatrix();


	// Flush drawing commands
	glutSwapBuffers();
	}
Esempio n. 17
0
void Display()
{
	// Clear the color and depth buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Save the current modelview matrix (the identity matrix)
	modelViewMatrix.PushMatrix();	
		M3DMatrix44f mCamera;
		cameraFrame.GetCameraMatrix(mCamera);
		modelViewMatrix.MultMatrix(mCamera);

		if (reflecting)
		{
			// Draw the "reflection" of the scene upside down
			modelViewMatrix.PushMatrix();

				// Flip the y-axis last.
				modelViewMatrix.Scale(1.0f, -1.0f, 1.0f);

				// The scene is essentially in a pit, bo elevate it an equal distance from the
				// x-z plane to ensure that its reflection will appear to be below the ground.
				modelViewMatrix.Translate(0.0f, -2.0f * FLOOR_HEIGHT, 0.0f);

				// Reverse the orientation of all polygonsm in the scene so the orientation of
				// their reflections will produce the same lighting as the above-ground scene.
				glFrontFace(GL_CW);
				DrawScene();
				glFrontFace(GL_CCW);

			modelViewMatrix.PopMatrix();
		}

  DrawGround();
  DrawScene();

	modelViewMatrix.PopMatrix();

	// Do the buffer Swap
	glutSwapBuffers();

	// Tell GLUT to do it again
	glutPostRedisplay();
}
Esempio n. 18
0
///////////////////////////////////////////////////////////////////////////////
// Draw the scene 
// 
void DrawWorld()
{
    modelViewMatrix.Translate(0.0f, 0.8f, 0.0f);
    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(-0.3f, 0.f, 0.0f);
        modelViewMatrix.Scale(0.40, 0.8, 0.40);
        modelViewMatrix.Rotate(50.0, 0.0, 10.0, 0.0);
        glSampleMaski(0, 0x02);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtYellow);
        glass1Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(0.4f, 0.0f, 0.0f);
        modelViewMatrix.Scale(0.5, 0.8, 1.0);
        modelViewMatrix.Rotate(-20.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x04);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtGreen);
        glass2Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(1.0f, 0.0f, -0.6f);
        modelViewMatrix.Scale(0.3, 0.9, 1.0);
        modelViewMatrix.Rotate(-40.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x08);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtMagenta);
        glass3Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(-0.8f, 0.0f, -0.60f);
        modelViewMatrix.Scale(0.6, 0.9, 0.40);
        modelViewMatrix.Rotate(60.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x10);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtBlue);
        glass4Batch.Draw();
    modelViewMatrix.PopMatrix();

    modelViewMatrix.PushMatrix();
        modelViewMatrix.Translate(0.1f, 0.0f, 0.50f);
        modelViewMatrix.Scale(0.4, 0.9, 0.4);
        modelViewMatrix.Rotate(205.0, 0.0, 1.0, 0.0);
        glSampleMaski(0, 0x20);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vLtPink);
        glass4Batch.Draw();
    modelViewMatrix.PopMatrix();
}
Esempio n. 19
0
// Called to draw scene
void RenderScene(void)
	{
    // Color values
    static GLfloat vFloorColor[] = { 0.0f, 1.0f, 0.0f, 1.0f};
    static GLfloat vTorusColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };

    // Time Based animation
	static CStopWatch	rotTimer;
	float yRot = rotTimer.GetElapsedSeconds() * 60.0f;
	
	// Clear the color and depth buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
    
    // Save the current modelview matrix (the identity matrix)
	modelViewMatrix.PushMatrix();	
		
	// Draw the ground
	shaderManager.UseStockShader(GLT_SHADER_FLAT,
								 transformPipeline.GetModelViewProjectionMatrix(),
								 vFloorColor);	
	floorBatch.Draw();

    // Draw the spinning Torus
    modelViewMatrix.Translate(0.0f, 0.0f, -2.5f);
    modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);
    shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(),
                                vTorusColor);
    torusBatch.Draw();

	// Restore the previous modleview matrix (the idenity matrix)
	modelViewMatrix.PopMatrix();
        
    // Do the buffer Swap
    glutSwapBuffers();
        
    // Tell GLUT to do it again
    glutPostRedisplay();
    }
Esempio n. 20
0
// Called to draw scene
void RenderScene(void)
{
    static CStopWatch rotTimer;

    // Clear the window and the depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    modelViewMatrix.PushMatrix(viewFrame);
    modelViewMatrix.Translate(0.0f, 0.0f, 800.0f);
    modelViewMatrix.Rotate(-12.0, 1.0f, 0.0f, 0.0f);
    modelViewMatrix.Rotate(rotTimer.GetElapsedSeconds() * 15.0f, 0.0f, 1.0f, 0.0f);

    glUseProgram(grassShader);
    glUniformMatrix4fv(locMVP, 1, GL_FALSE, transformPipeline.GetModelViewProjectionMatrix());

    glBindVertexArray(vao);

    glDrawArraysInstancedARB(GL_TRIANGLE_STRIP, 0, 6, 1024 * 1024);

    modelViewMatrix.PopMatrix();

    glutSwapBuffers();
    glutPostRedisplay();
}
Esempio n. 21
0
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();
}
Esempio n. 22
0
void DrawSongAndDance(GLfloat yRot)		// Called to draw dancing objects
{
	static GLfloat vWhite[] = { 1.0f, 1.0f, 1.0f, 1.0f };
	static GLfloat vLightPos[] = { 0.0f, 3.0f, 0.0f, 1.0f };

	// Get the light position in eye space
	M3DVector4f	vLightTransformed;
	M3DMatrix44f mCamera;
	modelViewMatrix.GetMatrix(mCamera);
	m3dTransformVector4(vLightTransformed, vLightPos, mCamera);

	// Draw the light source
	modelViewMatrix.PushMatrix();
	modelViewMatrix.Translatev(vLightPos);
	shaderManager.UseStockShader(GLT_SHADER_FLAT,
		transformPipeLine.GetModelViewProjectionMatrix(),
		vWhite);
	sphereBatch.Draw();
	modelViewMatrix.PopMatrix();

	glBindTexture(GL_TEXTURE_2D, uiTextures[2]);
	for (int i = 0; i < NUM_SPHERES; i++) {
		modelViewMatrix.PushMatrix();
		modelViewMatrix.MultMatrix(spheres[i]);
		shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
			modelViewMatrix.GetMatrix(),
			transformPipeLine.GetProjectionMatrix(),
			vLightTransformed,
			vWhite,
			0);
		sphereBatch.Draw();
		modelViewMatrix.PopMatrix();
	}

	// Song and dance
	modelViewMatrix.Translate(0.0f, 0.2f, -2.5f);
	modelViewMatrix.PushMatrix();	// Saves the translated origin
	modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);

	// Draw stuff relative to the camera
	glBindTexture(GL_TEXTURE_2D, uiTextures[1]);
	shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
		modelViewMatrix.GetMatrix(),
		transformPipeLine.GetProjectionMatrix(),
		vLightTransformed,
		vWhite,
		0);
	torusBatch.Draw();
	modelViewMatrix.PopMatrix(); // Erased the rotate

	modelViewMatrix.Rotate(yRot * -2.0f, 0.0f, 1.0f, 0.0f);
	modelViewMatrix.Translate(0.8f, 0.0f, 0.0f);

	glBindTexture(GL_TEXTURE_2D, uiTextures[2]);
	shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
		modelViewMatrix.GetMatrix(),
		transformPipeLine.GetProjectionMatrix(),
		vLightTransformed,
		vWhite,
		0);
	sphereBatch.Draw();
}
Esempio n. 23
0
void RenderScene(void)
{
	static CStopWatch	rotTimer;
	float yRot = rotTimer.GetElapsedSeconds() * 60.0f;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	modelViewMatrix.PushMatrix();

	M3DMatrix44f mCamera;
	cameraFrame.GetCameraMatrix(mCamera);
	modelViewMatrix.MultMatrix(mCamera);

	modelViewMatrix.PushMatrix();
	{
		//反向
		modelViewMatrix.Scale(1.0f, -1.0f, 1.0f);
		//因为是反向,所以正数是向下
		modelViewMatrix.Translate(0.0f, 0.8f, 0.0f); // Scootch the world down a bit...
		
		//三维中其中一维反向之后,缠绕方向也会呈相反,所以重新定义缠绕正方向为顺时针方向;
		glFrontFace(GL_CW);
		DrawSongAndDance(yRot);
		glFrontFace(GL_CCW);
	}
	modelViewMatrix.PopMatrix();

	// Draw the solid ground
	glEnable(GL_BLEND);
	glBindTexture(GL_TEXTURE_2D, uiTextures[0]);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	static GLfloat vFloorColor[] = { 1.0f, 1.0f, 1.0f, 0.75f };
	shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE,
		transformPipeLine.GetModelViewProjectionMatrix(),
		vFloorColor,
		0);

	floorBatch.Draw();
	glDisable(GL_BLEND);


	DrawSongAndDance(yRot);

	modelViewMatrix.PopMatrix();
	

	// Render the overlay

	// Creating this matrix really doesn't need to be done every frame. I'll leave it here
	// so all the pertenant code is together
	M3DMatrix44f mScreenSpace;
	m3dMakeOrthographicMatrix(mScreenSpace, 0.0f, 800.0f, 0.0f, 600.0f, -1.0f, 1.0f);

	// Turn blending on, and depth testing off
	glEnable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);

	glUseProgram(sphereWolrdShader);
	glUniform1i(locTexture, 0);
	glUniformMatrix4fv(locMVP, 1, GL_FALSE, mScreenSpace);
	glBindTexture(GL_TEXTURE_RECTANGLE, uiTextures[3]);
	logoBatch.Draw();

	// Restore no blending and depth test
	glDisable(GL_BLEND);
	glEnable(GL_DEPTH_TEST);

	// Do the buffer Swap
	glutSwapBuffers();

	// Do it again
	glutPostRedisplay();

}
Esempio n. 24
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();
	
}
Esempio n. 25
0
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();
}
Esempio n. 26
0
void RenderScene(void) 
{
    // clear the window with current clearing lightColor
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glUseProgram(shader);
	
	// use camera transform
	M3DMatrix44f cameraMatrix;
	cameraFrame.GetCameraMatrix(cameraMatrix);	
	modelViewMatrix.PushMatrix(cameraMatrix);	

	
	modelViewMatrix.PushMatrix();
		modelViewMatrix.Translate(0.0f, 0.0f, -10.0f);
		materialDiffuseColor[0] = materialDiffuseColor[1] = materialDiffuseColor[2] = 0.9f;
		PassGouraudDataToShader();	
		glutSolidCube(20);
	modelViewMatrix.PopMatrix();

	modelViewMatrix.PushMatrix();
		modelViewMatrix.Translate(0, 2, 0);
		modelViewMatrix.Rotate(timer.GetElapsedSeconds()*5, 0.0f, 0.0f, 1.0f);
		materialDiffuseColor[0] = 0.0f;
		materialDiffuseColor[1] = 0.0f;
		materialDiffuseColor[2] = 0.9f;
		PassGouraudDataToShader();	
		RenderTwentatenta();
	modelViewMatrix.PopMatrix();

	modelViewMatrix.PushMatrix();
		modelViewMatrix.Translate(0, -2, 0);
		modelViewMatrix.Rotate(timer.GetElapsedSeconds()*10, 0.0f, 0.0f, 1.0f);
		materialDiffuseColor[0] = 0.0f;
		materialDiffuseColor[1] = 0.9f;
		materialDiffuseColor[2] = 0.0f;
		PassGouraudDataToShader();	
		RenderSmoothTwentatenta();
	modelViewMatrix.PopMatrix();


	modelViewMatrix.PushMatrix();
		//modelViewMatrix.Translate(0, 0, 0);
		modelViewMatrix.Rotate(timer.GetElapsedSeconds()*10, 0.0f, 0.0f, 1.0f);
		materialDiffuseColor[0] = 0.9f;
		materialDiffuseColor[1] = 0.0f;
		materialDiffuseColor[2] = 0.0f;
		PassGouraudDataToShader();	
		glutSolidSphere(1, 20, 20);

	modelViewMatrix.PopMatrix();

	
	modelViewMatrix.PushMatrix();
		modelViewMatrix.Translate(5.0f, 0.0f, 3.0f);		
		materialDiffuseColor[0] = materialDiffuseColor[1] = materialDiffuseColor[2] = 10.0f;
		PassGouraudDataToShader();	
		glutSolidCube(0.1);
	modelViewMatrix.PopMatrix();

	// bring camera matrix back to top of the stack
	modelViewMatrix.PopMatrix();
	


    // perform the buffer swap to display back buffer
    glutSwapBuffers();
	glutPostRedisplay();
}
Esempio n. 27
0
/**
 * @brief Called to draw scene
 */
void RenderScene()
{
	// Color values
	static GLfloat vSunColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
	static GLfloat vEarthColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };
	static GLfloat vMoonColor[] = { 1.0f, 1.0f, 0.0f, 1.0f };
	static GLfloat vFloorColor[] = { 0.0f, 0.64f, 0.0f, 1.0f};

	// Time Based animation
	static CStopWatch rotTimer;
	float yRot = rotTimer.GetElapsedSeconds() * 60.0f;

	// Clear the color and depth buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Save the current modelview matrix (the identity matrix)
	modelViewMatrix.PushMatrix();	

	M3DMatrix44f mCamera;
	cameraFrame.GetCameraMatrix(mCamera);
	modelViewMatrix.PushMatrix(mCamera);

	// Transform the light position into eye coordinates
	M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f };
	M3DVector4f vLightEyePos;
	m3dTransformVector4(vLightEyePos, vLightPos, mCamera);

	// Draw the floor
	shaderManager.UseStockShader(GLT_SHADER_FLAT,
		transformPipeline.GetModelViewProjectionMatrix(),
		vFloorColor);	
	floorBatch.Draw();    

	// Draw the spinning Sun
	modelViewMatrix.Translate(0.0f, 0.0f, -3.5f);

	// Save the Translation
	modelViewMatrix.PushMatrix();

	// Apply a rotation and draw the Sun
	modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);
	shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, 
		transformPipeline.GetModelViewMatrix(), 
		transformPipeline.GetProjectionMatrix(), vLightEyePos, vSunColor);
	sunSphereBatch.Draw();
	modelViewMatrix.PopMatrix(); // "Erase" the Rotation from before

	// Apply another rotation, followed by a translation, then draw the Earth
	modelViewMatrix.Rotate(yRot * -2.0f, 0.0f, 1.0f, 0.0f);
	modelViewMatrix.Translate(0.8f, 0.0f, 0.0f);
	shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, 
		transformPipeline.GetModelViewMatrix(), 
		transformPipeline.GetProjectionMatrix(), vLightEyePos, vEarthColor);
	earthSphereBatch.Draw();

	// Apply another rotation, followed by a translation, then draw the Moon
	modelViewMatrix.Rotate(yRot * -4.0f, 0.0f, 1.0f, 0.0f);
	modelViewMatrix.Translate(0.4f, 0.0f, 0.0f);
	shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, 
		transformPipeline.GetModelViewMatrix(), 
		transformPipeline.GetProjectionMatrix(), vLightEyePos, vMoonColor);
	moonSphereBatch.Draw();

	// Restore the previous modleview matrix (the identity matrix)
	modelViewMatrix.PopMatrix();
	modelViewMatrix.PopMatrix();    
	modelViewMatrix.PopMatrix();   

	// Do the buffer Swap
	glutSwapBuffers();

	// Tell GLUT to do it again
	glutPostRedisplay();
}
// Called to draw scene
void RenderScene(void)
	{
    // Color values
    static GLfloat vFloorColor[] = { 0.0f, 1.0f, 0.0f, 1.0f};
    static GLfloat vTorusColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
    static GLfloat vSphereColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };

    // Time Based animation
	static CStopWatch	rotTimer;
	float yRot = rotTimer.GetElapsedSeconds() * 60.0f;
	
	// Clear the color and depth buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
    
    // Save the current modelview matrix (the identity matrix)
	modelViewMatrix.PushMatrix();	
    
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.PushMatrix(mCamera);
		
	// Draw the ground
	shaderManager.UseStockShader(GLT_SHADER_FLAT,
								 transformPipeline.GetModelViewProjectionMatrix(),
								 vFloorColor);	
	floorBatch.Draw();    
    
    for(int i = 0; i < NUM_SPHERES; i++) {
        modelViewMatrix.PushMatrix();
        modelViewMatrix.MultMatrix(spheres[i]);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(),
                                vSphereColor);
        sphereBatch.Draw();
        modelViewMatrix.PopMatrix();
        }

    // Draw the spinning Torus
    modelViewMatrix.Translate(0.0f, 0.0f, -2.5f);
    
    // Save the Translation
    modelViewMatrix.PushMatrix();
    
        // Apply a rotation and draw the torus
        modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(),
                                vTorusColor);
        torusBatch.Draw();
    modelViewMatrix.PopMatrix(); // "Erase" the Rotation from before

    // Apply another rotation, followed by a translation, then draw the sphere
    modelViewMatrix.Rotate(yRot * -2.0f, 0.0f, 1.0f, 0.0f);
    modelViewMatrix.Translate(0.8f, 0.0f, 0.0f);
    shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(),
                                     vSphereColor);
    sphereBatch.Draw();

	// Restore the previous modleview matrix (the identity matrix)
	modelViewMatrix.PopMatrix();
    modelViewMatrix.PopMatrix();    
    // Do the buffer Swap
    glutSwapBuffers();
        
    // Tell GLUT to do it again
    glutPostRedisplay();
    }
Esempio n. 29
0
///////////////////////////////////////////////////////////////////////////////
// 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();
}
Esempio n. 30
0
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();
}