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

	M3DVector3f at={0,0,0};
	M3DVector3f up={0,0,1};
	M3DVector3f eye;
	float angle = timer.GetElapsedSeconds()*M_PI/3;

	eye[0]=6.8f*cos(angle);
	eye[1]=6.0f*sin(angle);
	eye[2]=5.0f; 
	LookAt(cameraFrame,eye,at,up);

	geometryPipeline.SetMatrixStacks(modelView,projection);

	projection.LoadMatrix(viewFrustum.GetProjectionMatrix());
	modelView.PushMatrix();

	cameraFrame.GetCameraMatrix(mCamera);
	modelView.LoadMatrix(mCamera);
	modelView.PushMatrix();

	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());

		drawLines();

		drawPyramid();
		
	modelView.PopMatrix();
	modelView.PushMatrix();
	modelView.Translate(1.0f,6.0f,2.0f);
	modelView.Rotate(180.0f,0.0f,0.0f,1.0f);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());

		drawPyramid();

	modelView.PopMatrix();
	modelView.PushMatrix();
	modelView.Translate(6.0f,-4.0f,1.0f);
	modelView.Rotate(60.0f,1.0f,1.0f,1.5f);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    
		drawPyramid();

	modelView.PopMatrix();
	modelView.PushMatrix();
	modelView.Translate(-2.0f,0.0f,1.0f);
	modelView.Rotate(80.0f,1.0f,0.0f,1.0f);
	modelView.Scale(0.8f,0.4f,1.0f);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    
		drawPyramid();

	modelView.PopMatrix();
	modelView.PopMatrix();

    // Perform the buffer swap to display back buffer
    glutSwapBuffers();
	glutPostRedisplay();
}
Exemple #2
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();
	}
// 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();
    }
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();
	}
Exemple #5
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();
}
// main rendering loop
void RenderScene(void){
    static CStopWatch rotTimer;
    float yRot = rotTimer.GetElapsedSeconds() * 60.0f;
    GLfloat vBarColor[] = {1.0f, 0.0f, 0.0f, 1.0f};

    currentFrame = getLatestBufferIndex();

    if(mapper.getSimpleArg('c')){
        vBarColor[0] = .7;
        vBarColor[1] = .2 + sharedBuffer[currentFrame].averageAmp * 60;
        vBarColor[2] = 1.0;

        b = sharedBuffer[currentFrame].averageAmp;
        g = 0;
        r = 0;
        glClearColor(r, g, b, 1.0f);
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    modelViewMatrix.PushMatrix();

    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.PushMatrix(mCamera);
    if(mapper.getCompoundArg('r') == "auto"){
        cameraFrame.RotateWorld(.01, 0.0, 0.0, 1.0);
        cameraFrame.MoveForward(-.1 * sin(yRot * .05));
    }

    // set up light source
    M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f };
    M3DVector4f vLightEyePos;
    m3dTransformVector4(vLightEyePos, vLightPos, mCamera);

    for(int m = 0; m < NUM_MACROS; m++){
        if(mapper.getSimpleArg('m')){
            modelViewMatrix.PushMatrix();
            macros[m].refFrame.RotateLocalY(.01 * macros[m].multiplier);
            macros[m].refFrame.RotateLocalX(.5 * sharedBuffer[currentFrame].averageAmp);
            modelViewMatrix.MultMatrix(macros[m].refFrame);
        }
        for(int i = 0; i < PACKET_SIZE; i++){
            modelViewMatrix.PushMatrix();
            GLfloat y = 5 * fabs(sharedBuffer[currentFrame].frames[i][0]);
            modelViewMatrix.MultMatrix(bars[i]);
            modelViewMatrix.Scale(barWidth, y, sharedBuffer[currentFrame].averageAmp * 4);
            if(mapper.getSimpleArg('t')){
                modelViewMatrix.Translate(0.0, sharedBuffer[currentFrame].averageAmp, 0.0);
            }
            shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF,
                    transformPipeline.GetModelViewMatrix(),
                    transformPipeline.GetProjectionMatrix(),
                    vLightEyePos, vBarColor);
            cubeBatch.Draw();
            modelViewMatrix.PopMatrix();
        }
        if(mapper.getSimpleArg('m')){
            modelViewMatrix.PopMatrix();
        }
    }

    // draw prisms for amplitudes
    modelViewMatrix.PopMatrix();

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

    glutSwapBuffers();
    glutPostRedisplay();

    if(currentFrame != -1){
        sharedBuffer[currentFrame].free = true;
    }
}
Exemple #7
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();
}
Exemple #8
0
void RenderScene(void) {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glFrontFace(GL_CW);
    glUseProgram(shader);
    M3DVector3f at={1.5f, 0.0f, 0.0f};
    M3DVector3f up={-1.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]= 30.0f;
    LookAt(cameraFrame,eye,at,up);

    M3DVector3f ambientLight = {1.0f, 1.0f, 1.0f};
    M3DVector3f position = {10.0f, 10.0f, 5.0f};
    M3DVector3f color = {1.0f, 1.0f, 1.0f};
    float l_angle = 90.0f;
    float attenuation0 = 0.01f;
    float attenuation1 = 0.01f;
    float attenuation2 = 0.01f;
    M3DVector3f ambientColor = {0.0f, 1.0, 0.0};
    M3DVector3f diffuseColor = {0.0f, 1.0f, 1.0f};
    M3DVector3f specularColor = {1.0f, 1.0f, 1.0f};
    float specularExponent = 8;

    projection.LoadMatrix(viewFrustum.GetProjectionMatrix());
    modelView.PushMatrix();
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelView.LoadMatrix(mCamera);
    modelView.PushMatrix();

glUniform3fv(shaderPositionLocation, 1, position);
glUniform3fv(shaderColorLocation, 1, color);
glUniform1f(shaderAngleLocation, angle);
glUniform1f(shaderAttenuation0Location, attenuation0);
glUniform1f(shaderAttenuation1Location, attenuation1);
glUniform1f(shaderAttenuation2Location, attenuation2);

    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);

    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);

    glPolygonOffset(1.0f, 1.0f);
	grid();
    glEnable(GL_POLYGON_OFFSET_FILL);
	grid();
    glDisable(GL_POLYGON_OFFSET_FILL);
   

	modelView.PopMatrix();
    modelView.PushMatrix();
    modelView.Translate(-7.75f, -7.75f, 0.0f);
	modelView.Scale(0.25f, 0.25f, 0.25f);
    glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
	glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
	
	piramida();

	modelView.PopMatrix();
    modelView.PushMatrix();
    modelView.Translate(-6.0f, -6.0f, 0.0f);
	modelView.Scale(0.5f, 0.5f, 0.5f);
	modelView.Rotate(angle*512, 0.0f, 0.0f, 2.0f);
    glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
	
	glDrawElements(GL_TRIANGLES,3*n_faces,GL_UNSIGNED_INT,0);

	modelView.PopMatrix();
    modelView.PushMatrix();
    modelView.Translate(-4.0f, -4.0f, 0.0f);
	modelView.Scale(0.75f, 0.75f, 0.75f);
	modelView.Rotate(angle*512, 0.0f, 2.0f, 0.0f);
	glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
    
	piramida();

	modelView.PopMatrix();`
    modelView.PushMatrix();
    modelView.Translate(2.0f, 2.0f, 0.0f);
    modelView.Scale(1.5f, 1.5f, 1.5f);
	modelView.Rotate(angle*512, 2.0f, 2.0f, 0.0f);
	glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
    
	piramida();

	modelView.PopMatrix();
    modelView.PushMatrix();
	modelView.Translate(-1.5f, -1.5f, 0.0f);
	modelView.Rotate(angle*512, 2.0f, 0.0f, 0.0f);
	glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);

	DrawTriangles(20, vertices_tab, faces_tab);
	
	modelView.PopMatrix();
	modelView.PushMatrix();
    modelView.Translate(6.5f, 6.5f, 0.0f);
    modelView.Scale(2.5f, 2.5f, 2.5f);
	modelView.Rotate(angle*512, 2.0f, 2.0f, 2.0f);
	glUniform3fv(shaderPositionLocation, 1, position);
    glUniform3fv(shaderColorLocation, 1, color);
    glUniform1f(shaderAngleLocation, l_angle);
    glUniform1f(shaderAttenuation0Location, attenuation0);
    glUniform1f(shaderAttenuation1Location, attenuation1);
    glUniform1f(shaderAttenuation2Location, attenuation2);
    glUniformMatrix4fv(MVMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(normalMatrixLocation,1,GL_FALSE,geometryPipeline.GetNormalMatrix());
    glUniform3fv(ambientLightLocation, 1, ambientLight);
    glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
    glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
    glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
    glUniform1f(shaderSpecularExponentLocation, specularExponent);
	
	DrawSmoothTriangles(20, vertices_tab, faces_tab);

	modelView.PopMatrix();
    modelView.PopMatrix();
    glutSwapBuffers();
    glutPostRedisplay();
}
Exemple #9
0
void RenderScene(void) {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	glUseProgram(shader);
	GLMatrixStack modelView;
	GLMatrixStack projection;
	GLGeometryTransform geometryPipeline;
	geometryPipeline.SetMatrixStacks(modelView,projection);
	M3DVector3f at={0,0,0};
	M3DVector3f up={0,0,1};
	M3DVector3f eye;
	float angle=timer.GetElapsedSeconds()*3.14f;
	eye[0]=40*cos(angle);
	eye[1]=40*sin(angle);
	eye[2]=30.0f; 
	LookAt(frame,eye,at,up);
	projection.LoadMatrix(frustum.GetProjectionMatrix());
	modelView.PushMatrix();
	M3DMatrix44f mCamera;
	frame.GetCameraMatrix(mCamera);
	modelView.LoadMatrix(mCamera);
	modelView.PushMatrix();

	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	glBegin(GL_LINES);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 0.5f, 0.5f, 0.5f);
		for (int i=-10; i<=10; i++)
		{
			glVertex3f(i,-10.0f,0);
			glVertex3f(i,10.0f,0);
			glVertex3f(-10.0f,i,0);
			glVertex3f(10.0f,i,0);
		}
	glEnd();
	modelView.Translate(10.0f,1.0f,0.0f);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	glBegin(GL_QUADS);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 0.5f, 0.5f, 0.5f);
		glVertex3f(-1.0f,-1.0f,0.0f);
		glVertex3f(-1.0f,1.0f,0.0f);
		glVertex3f(1.0f,1.0f,0.0f);
		glVertex3f(1.0f,-1.0f,0.0f);
	glEnd();
    glBegin(GL_TRIANGLES);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0f, 1.0f, 0.0f);
		glVertex3f(-1.0f, 1.0f, 0.0f);
 		glVertex3f(0.0f, 0.0f, 2.0f);
 		glVertex3f(1.0f, 1.0f, 0.0f);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 0.0f, 0.0f, 0.8f);
		glVertex3f(-1.0f, -1.0f, 0.0f);
 		glVertex3f(0.0f, 0.0f, 2.0f);
 		glVertex3f(-1.0f, 1.0f, 0.0f);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 0.0f, 1.0f, 0.0f);
		glVertex3f(1.0f, -1.0f, 0.0f);
 		glVertex3f(0.0f, 0.0f, 2.0f);
 		glVertex3f(-1.0f, -1.0f, 0.0f);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0f, 0.0f, 0.0f);
		glVertex3f(1.0f, 1.0f, 0.0f);
 		glVertex3f(0.0f, 0.0f, 2.0f);
 		glVertex3f(1.0f, -1.0f, 0.0f);
    glEnd();
	modelView.PopMatrix();
	modelView.Rotate(45.0,0,0,1);
	modelView.Translate(0.0,0.0,1.0);
	glUniformMatrix4fv(MVPMatrixLocation,1,GL_FALSE,geometryPipeline.GetModelViewProjectionMatrix());
	glBegin(GL_QUADS);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 0.5f, 0.5f, 0.5f);
		glVertex3f(-1.0f,-1.0f,0.0f);
		glVertex3f(-1.0f,1.0f,0.0f);
		glVertex3f(1.0f,1.0f,0.0f);
		glVertex3f(1.0f,-1.0f,0.0f);
	glEnd();
    glBegin(GL_TRIANGLES);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0f, 1.0f, 0.0f);
		glVertex3f(-1.0f, 1.0f, 0.0f);
 		glVertex3f(0.0f, 0.0f, 2.0f);
 		glVertex3f(1.0f, 1.0f, 0.0f);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 0.0f, 0.0f, 0.8f);
		glVertex3f(-1.0f, -1.0f, 0.0f);
 		glVertex3f(0.0f, 0.0f, 2.0f);
 		glVertex3f(-1.0f, 1.0f, 0.0f);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 0.0f, 1.0f, 0.0f);
		glVertex3f(1.0f, -1.0f, 0.0f);
 		glVertex3f(0.0f, 0.0f, 2.0f);
 		glVertex3f(-1.0f, -1.0f, 0.0f);
	    glVertexAttrib3f(GLT_ATTRIBUTE_COLOR, 1.0f, 0.0f, 0.0f);
		glVertex3f(1.0f, 1.0f, 0.0f);
 		glVertex3f(0.0f, 0.0f, 2.0f);
 		glVertex3f(1.0f, -1.0f, 0.0f);
    glEnd();

	modelView.PopMatrix();
	modelView.PopMatrix();
    glutSwapBuffers();
	glutPostRedisplay();
}
Exemple #10
0
void RenderScene(void) {
  


    // 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();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glUseProgram(shader);
   modelView.PushMatrix();
  modelView.Translate(swiatlo0.position[0], swiatlo0.position[1], swiatlo0.position[2]);
   modelView.Scale(0.25f, 0.25f, 0.25f);
   glUniformMatrix4fv(MVPMatrixLocationshader, 1, GL_FALSE, geometryPipeline.GetModelViewProjectionMatrix());
modelView.PopMatrix();
    glUseProgram(Pshader);//wywo³anie shadera

    //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(0);
    // Perform the buffer swap to display back buffer
    glutSwapBuffers();
    glutPostRedisplay();
}
Exemple #11
0
///////////////////////////////////////////////////////////////////////////////
// Render a frame. The owning framework is responsible for buffer swaps,
// flushes, etc.
void RenderScene(void)
{
    static CStopWatch animationTimer;
    float yRot = animationTimer.GetElapsedSeconds() * 60.0f;
    
    M3DVector3f vCameraPos;
    M3DVector3f vCameraForward;
    M3DVector3f vMirrorPos;
    M3DVector3f vMirrorForward;
    cameraFrame.GetOrigin(vCameraPos);
    cameraFrame.GetForwardVector(vCameraForward);
    
    // Set position of mirror frame (camera)
    vMirrorPos[0] = 0.0;
    vMirrorPos[1] = 0.1f;
    vMirrorPos[2] = -6.0f; // view pos is actually behind mirror
    mirrorFrame.SetOrigin(vMirrorPos);
    
    // Calculate direction of mirror frame (camera)
    // Because the position of the mirror is known relative to the origin
    // find the direction vector by adding the mirror offset to the vector
    // of the viewer-origin
    vMirrorForward[0] = vCameraPos[0];
    vMirrorForward[1] = vCameraPos[1];
    vMirrorForward[2] = (vCameraPos[2] + 5);
    m3dNormalizeVector3(vMirrorForward);
    mirrorFrame.SetForwardVector(vMirrorForward);
    
    // first render from the mirrors perspective
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName);
    glDrawBuffers(1, fboBuffs);
    glViewport(0, 0, mirrorTexWidth, mirrorTexHeight);
    
    // Draw scene from the perspective of the mirror camera
    modelViewMatrix.PushMatrix();
    M3DMatrix44f mMirrorView;
    mirrorFrame.GetCameraMatrix(mMirrorView);
    modelViewMatrix.MultMatrix(mMirrorView);
    
    // Flip the mirror camera horizontally for the reflection
    modelViewMatrix.Scale(-1.0f, 1.0f, 1.0f);
    
    glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0);
    floorBatch.Draw();
    DrawWorld(yRot);
    
    // Now draw a cylinder representing the viewer
    M3DVector4f vLightTransformed;
    modelViewMatrix.GetMatrix(mMirrorView);
    m3dTransformVector4(vLightTransformed, vLightPos, mMirrorView);
    modelViewMatrix.Translate(vCameraPos[0],vCameraPos[1]-0.8f,vCameraPos[2]-1.0f);
    modelViewMatrix.Rotate(-90.0f, 1.0f, 0.0f, 0.0f);
    
    shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF,
                                 modelViewMatrix.GetMatrix(),
                                 transformPipeline.GetProjectionMatrix(),
                                 vLightTransformed, vBlue, 0);
    cylinderBatch.Draw();
    modelViewMatrix.PopMatrix();
    
    // Reset FBO. Draw world again from the real cameras perspective
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
    glDrawBuffers(1, windowBuff);
    glViewport(0, 0, screenWidth, screenHeight);
    modelViewMatrix.PushMatrix();
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.MultMatrix(mCamera);
    
    glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0);
    
    floorBatch.Draw();
    DrawWorld(yRot);
    
    // Now draw the mirror surfaces
    modelViewMatrix.PushMatrix();
    modelViewMatrix.Translate(0.0f, -0.4f, -5.0f);
    if(vCameraPos[2] > -5.0)
    {
        glBindTexture(GL_TEXTURE_2D, mirrorTexture); // Reflection
        shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0);
    }
    else
    {
        // If the camera is behind the mirror, just draw black
        shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBlack);
    }
    mirrorBatch.Draw();
    shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vGrey);
    mirrorBorderBatch.Draw();
    modelViewMatrix.PopMatrix();
    modelViewMatrix.PopMatrix();
    
    // Do the buffer Swap
    glutSwapBuffers();
    
    // Do it again
    glutPostRedisplay();
}
Exemple #12
0
void renderScene()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    modelViewM.PushMatrix();

    M3DMatrix44f cameraM;
    cameraFrame.GetCameraMatrix(cameraM);
    modelViewM.MultMatrix(cameraM);

    M3DVector4f lightPos = {0.0f, 10.0f, 5.0f, 1.0f};
    M3DVector4f lightEyePos;
    m3dTransformVector4(lightEyePos, lightPos, cameraM);
    GLfloat whiteLight[] = {1.0f, 1.0f, 1.0f, 1.0f};

    modelViewM.PushMatrix();

    modelViewM.Translate(0, 0, -3);

    M3DMatrix44f objectM;
    objectFrame.GetMatrix(objectM);
    modelViewM.MultMatrix(objectM);

    glBindTexture(GL_TEXTURE_2D, textureID[0]);
#if 0
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, 
                                 pipelineTransform.GetModelViewMatrix(),
                                 pipelineTransform.GetProjectionMatrix(), 
                                 lightEyePos, whiteLight, 0);
#else
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, 
                                 pipelineTransform.GetModelViewProjectionMatrix(),
                                 0);
#endif
    cuboidBatch.Draw();

    modelViewM.PopMatrix();

    static CStopWatch timer;
    float angle = timer.GetElapsedSeconds() * 120;
    modelViewM.Translate(0.5f, 0.6f, -5);
    modelViewM.Rotate(angle, 1, 1, 1);
    modelViewM.Scale(0.5/cuboidLength, 0.3/cuboidHeigth, 0.4/cuboidWidth);
    glBindTexture(GL_TEXTURE_2D, textureID[1]);
#if 0
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, 
                                 pipelineTransform.GetModelViewMatrix(),
                                 pipelineTransform.GetProjectionMatrix(), 
                                 lightEyePos, whiteLight, 0);
#else
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, 
                                 pipelineTransform.GetModelViewProjectionMatrix(),
                                 0);
#endif

    cuboidBatch.Draw();

    modelViewM.PopMatrix();

    glutSwapBuffers();
    glutPostRedisplay();
}
/**
 * Called to draw scene
 */
void RenderScene(void)
{
	static GLfloat vFloorColor[] = { 1.0f, 1.0f, 1.0f, 0.75f };
	static CStopWatch rotTimer;
	float yRot = rotTimer.delta() * 60.0f;

	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	modelViewMatrix.push();

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

	// draw the world upside down
	modelViewMatrix.push();
	modelViewMatrix.scaleTo(1.0f, -1.0f, 1.0f); // flips the Y axis
	modelViewMatrix.moveTo(0.0f, 0.8f, 0.0f); // scootch the world down a bit...

	glFrontFace(GL_CW);
	DrawSongAndDance(yRot);
	glFrontFace(GL_CCW); // restore it

	modelViewMatrix.pop();

	// draw the solid ground
	glEnable(GL_BLEND);
	glBindTexture(GL_TEXTURE_2D, uiTextures[0]);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	shaderManager.useStockShader(GLT_SHADER_TEXTURE_MODULATE, 
		transformPipeline.GetMVPMatrix(), 
		vFloorColor, 
		0);
	floorBatch.draw();
	glDisable(GL_BLEND);

	DrawSongAndDance(yRot);

	modelViewMatrix.pop();

	// 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 dephth testing off
	glEnable(GL_BLEND);
	glDisable(GL_DEPTH_TEST);

	glUseProgram(rectReplaceShader);
	glUniform1i(locRectTexture, 0);
	glUniformMatrix4fv(locRectMVP, 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);

	// Perform the buffer swap to display back buffer
	glutSwapBuffers();
	glutPostRedisplay();
}
// called to draw dancing objects
static void DrawSongAndDance(GLfloat yRot)
{
	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
	M3DMatrix44f mCamera;
	modelViewMatrix.GetMatrix(mCamera);
	M3DVector4f vLightTransformed;
	m3dTransformVector4(vLightTransformed, vLightPos, mCamera);

	// draw the light source
	modelViewMatrix.push();
	modelViewMatrix.moveTo(vLightPos);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(),
								vWhite);
	sphereBatch.draw();

	modelViewMatrix.pop();

	glBindTexture(GL_TEXTURE_2D, uiTextures[2]);
	for (int i = 0; i < NUM_SPHERES; ++i) {
		modelViewMatrix.push();

		modelViewMatrix.MultMatrix(spheres[i]);
		shaderManager.useStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF,
									modelViewMatrix.GetMatrix(),
									transformPipeline.GetProjectionMatrix(),
									vLightTransformed,
									vWhite,
									0);
		sphereBatch.draw();

		modelViewMatrix.pop();
	}

	// song and dance
	modelViewMatrix.moveTo(0.0f, 0.2f, -2.5f);
	modelViewMatrix.push();	// save the translated origin
	modelViewMatrix.rotateTo(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.pop();	// erased the rotate

	modelViewMatrix.rotateTo(yRot * -2.0f, 0.0f, 1.0f, 0.0f);
	modelViewMatrix.moveTo(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();
}
Exemple #15
0
///////////////////////////////////////////////////////////////////////////////
// OpenGL related startup code is safe to put here. Load textures, etc.
void SetupRC(void)
{
	GLfloat texCoordOffsets[4][5*5*2];
	GLfloat exposureLUT[20]   = { 11.0, 6.0, 3.2, 2.8, 2.2, 1.90, 1.80, 1.80, 1.70, 1.70,  1.60, 1.60, 1.50, 1.50, 1.40, 1.40, 1.30, 1.20, 1.10, 1.00 };
	
	// Make sure OpenGL entry points are set
	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		/* Problem: glewInit failed, something is seriously wrong. */
		fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
	}

	// Will not use depth buffer
	glDisable(GL_DEPTH_TEST);
	curHDRTex = 0;
	
	// Init codel-view and leave it 
	modelViewMatrix.LoadIdentity();

	// Black
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	// Setup LUT texture for use with the adaptive exposure filter
	glGenTextures(1, lutTxtures);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_1D, lutTxtures[1]);
	glTexImage1D(GL_TEXTURE_1D, 0, GL_R16F, 20,  0, GL_RED, GL_FLOAT, exposureLUT);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

	// Setup HDR texture(s)
	glActiveTexture(GL_TEXTURE0);
	glGenTextures(1, hdrTextures);
	glBindTexture(GL_TEXTURE_2D, hdrTextures[curHDRTex]);

	// Load HDR image from EXR file
    LoadOpenEXRImage("Tree.exr", hdrTextures[curHDRTex], hdrTexturesWidth[curHDRTex], hdrTexturesHeight[curHDRTex]);

	// Create ortho matrix and screen-sized quad matching images aspect ratio
    GenerateOrtho2DMat(screenWidth, screenHeight, hdrTexturesWidth[curHDRTex], hdrTexturesHeight[curHDRTex]);
	//GenerateFBOOrtho2DMat(hdrTexturesWidth[curHDRTex], hdrTexturesHeight[curHDRTex]);
    gltGenerateOrtho2DMat(hdrTexturesWidth[curHDRTex], hdrTexturesHeight[curHDRTex], fboOrthoMatrix, fboQuad);

	// Setup tex coords to be used for fetching HDR kernel data
	for (int k = 0; k < 4; k++)
	{
		float xInc = 1.0f / (GLfloat)(hdrTexturesWidth[curHDRTex] >> k);
		float yInc = 1.0f / (GLfloat)(hdrTexturesHeight[curHDRTex] >> k);

		for (int i = 0; i < 5; i++)
		{
			for (int j = 0; j < 5; j++)
			{
				texCoordOffsets[k][(((i*5)+j)*2)+0] = (-1.0f * xInc) + ((GLfloat)i * xInc);
				texCoordOffsets[k][(((i*5)+j)*2)+1] = (-1.0f * yInc) + ((GLfloat)j * yInc);
			}
		}
	}

	// Load shaders 
    mapTexProg =  gltLoadShaderPairWithAttributes("hdr.vs", "hdr_simple.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_TEXTURE0, "vTexCoord0");
	glBindFragDataLocation(mapTexProg, 0, "oColor");
	glLinkProgram(mapTexProg);

	varExposureProg =  gltLoadShaderPairWithAttributes("hdr.vs", "hdr_exposure_image.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_TEXTURE0, "vTexCoord0");
	glBindFragDataLocation(varExposureProg, 0, "oColor");
	glLinkProgram(varExposureProg);
	glUseProgram(varExposureProg);
	glUniform1i(glGetUniformLocation(varExposureProg, "textureUnit0"), 0);

	adaptiveProg =  gltLoadShaderPairWithAttributes("hdr.vs", "hdr_adaptive.fs", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_TEXTURE0, "vTexCoord0");
	glBindFragDataLocation(adaptiveProg, 0, "oColor");
	glLinkProgram(adaptiveProg);
	glUseProgram(adaptiveProg);
	glUniform1i(glGetUniformLocation(adaptiveProg, "textureUnit0"), 0);
	glUniform1i(glGetUniformLocation(adaptiveProg, "textureUnit1"), 1);
	glUniform2fv(glGetUniformLocation(adaptiveProg, "tc_offset"), 25, texCoordOffsets[0]);

	glUseProgram(0);

	// Create and bind an FBO
	glGenFramebuffers(1,&fboName);
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName);

	// Create the FBO texture
	glGenTextures(1, fboTextures);
	glBindTexture(GL_TEXTURE_2D, fboTextures[0]);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, hdrTexturesWidth[curHDRTex], hdrTexturesHeight[curHDRTex], 0, GL_RGBA, GL_FLOAT, NULL);
	glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fboTextures[0], 0);
    
	// Make sure all went well
	gltCheckErrors();
	
	glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);

	// Set first running mode
	curProg = adaptiveProg;
}
Exemple #16
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();
}
// called when screen size changes
void ChangeSize(int nWidth, int nHeight){
    glViewport(0, 0, nWidth, nHeight);
    viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f);
    projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
    transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
}
Exemple #18
0
///////////////////////////////////////////////////////////////////////////////
// Render a frame. The owning framework is responsible for buffer swaps,
// flushes, etc.
void RenderScene(void)
{
    // Bind the FBO with multisample buffers
    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, msFBO);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// User selected order independant transparency
    if (mode == USER_OIT)
    {
        // Use OIT, setup sample masks
        glSampleMaski(0, 0x01);
        glEnable(GL_SAMPLE_MASK);

		// Prevent depth test from culling covered surfaces
        glDepthFunc(GL_ALWAYS);
    }
    
    modelViewMatrix.PushMatrix();	
      M3DMatrix44f mCamera;
      cameraFrame.GetCameraMatrix(mCamera);
      modelViewMatrix.MultMatrix(mCamera);

      modelViewMatrix.PushMatrix();	
        modelViewMatrix.Translate(0.0f, -0.4f, -4.0f);
        modelViewMatrix.Rotate(worldAngle, 0.0, 1.0, 0.0);

		// Draw the background and disk to the first sample
        modelViewMatrix.PushMatrix();
          modelViewMatrix.Translate(0.0f, 3.0f, 0.0f);
          modelViewMatrix.Rotate(90.0, 1.0, 0.0, 0.0);
          modelViewMatrix.Rotate(90.0, 0.0, 0.0, 1.0);
          glBindTexture(GL_TEXTURE_2D, textures[1]); 
          shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE, transformPipeline.GetModelViewProjectionMatrix(), 0);
          bckgrndCylBatch.Draw();
        modelViewMatrix.PopMatrix();
        
        modelViewMatrix.Translate(0.0f, -0.3f, 0.0f);
        modelViewMatrix.PushMatrix();
            modelViewMatrix.Rotate(90.0, 1.0, 0.0, 0.0);
            shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vGrey);
            diskBatch.Draw();
        modelViewMatrix.PopMatrix();
		modelViewMatrix.Translate(0.0f, 0.1f, 0.0f);

		// User selected blending
        if (mode == USER_BLEND)
        {
            // Setup blend state
			glDisable(GL_DEPTH_TEST);
            glEnable(GL_BLEND);
            switch (blendMode)
            {
            case 1:
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                break;
            case 2:
                glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA);
                break;
            case 3:
                glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
                break;
            case 4:
                glBlendFunc(GL_SRC_ALPHA, GL_ONE);
                break;
            case 5:
                glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR);
                break;
            case 6:
                glBlendFuncSeparate(GL_SRC_ALPHA, GL_DST_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                break;
            case 7:
                glBlendFuncSeparate(GL_SRC_COLOR, GL_DST_COLOR, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                break;
            default:
                glDisable(GL_BLEND);
            }
        }
   
		// Now draw the glass pieces
        DrawWorld();
    
      modelViewMatrix.PopMatrix();
    modelViewMatrix.PopMatrix();
    
    // Clean up all state 
    glDepthFunc(GL_LEQUAL);
    glDisable(GL_BLEND);
    glDisable(GL_SAMPLE_MASK);
    glSampleMaski(0, 0xffffffff);

    // Resolve multisample buffer
    projectionMatrix.PushMatrix();
      projectionMatrix.LoadMatrix(orthoMatrix);
      modelViewMatrix.PushMatrix();
        modelViewMatrix.LoadIdentity();
		// Setup and Clear the default framebuffer
        glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
        glViewport(0, 0, screenWidth, screenHeight);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        
        if (mode == USER_OIT)
            SetupOITResolveProg();
        else if (mode == USER_BLEND)
            SetupResolveProg();

		// Draw a full-size quad to resolve the multisample surfaces
        screenQuad.Draw();
      modelViewMatrix.PopMatrix();
    projectionMatrix.PopMatrix();
    
	// Reset texture state
    glEnable(GL_DEPTH_TEST);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
    glActiveTexture(GL_TEXTURE1);
    glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
               
    // Do the buffer Swap
    glutSwapBuffers();
        
    // Do it again
    glutPostRedisplay();
}
Exemple #19
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();
}
Exemple #20
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);
   //--
   glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix());
   glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix());
   draw_grid();
   draw_floor();
   //--
   for(int i = -20; i < 20; i += 5) {
      for(int j = -20; j < 20; j += 5) {
         mv_stack.PushMatrix();
         mv_stack.Translate((float)i, (float)j, 0.0f);
         glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix());
         glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix());
         draw_pyramid();
         mv_stack.PopMatrix();
      }
   }
   //--
   mv_stack.PushMatrix();
   mv_stack.Translate(0.0f, 0.0f, 4.0f);
   glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix());
   glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix());
   draw_icosahedron(20, vertices_icosahedron, faces_icosahedron);
   mv_stack.PopMatrix();
   //--
   mv_stack.PushMatrix();
   mv_stack.Translate(-5.0f, 0.0f, 4.0f);
   glUniformMatrix4fv(mvp_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewProjectionMatrix());
   glUniformMatrix4fv(mv_matrix_location, 1, GL_FALSE, geometry_pipeline.GetModelViewMatrix());
   draw_icosahedron_smooth(20, vertices_icosahedron, faces_icosahedron);
   mv_stack.PopMatrix();
   //--
   glUseProgram(0);
   glutSwapBuffers();
   glutPostRedisplay();
}
// 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();

	// 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(rectReplaceShader);
	glUniform1i(locRectTexture, 0);
	glUniformMatrix4fv(locRectMVP, 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();
    }
Exemple #22
0
///////////////////////////////////////////////////////////////////////////////
// Render a frame. The owning framework is responsible for buffer swaps,
// flushes, etc.
void RenderScene(void)
{
	static CStopWatch animationTimer;
	static float totalTime = 6; // To go back and forth
	static float halfTotalTime = totalTime/2;
	float seconds = animationTimer.GetElapsedSeconds() * speedFactor;
	float xPos = 0;

	// Calculate the next postion of the moving object
	// First perform a mod-like operation on the time as a float
	while(seconds > totalTime)
		seconds -= totalTime;

	// Move object position, if it's gone half way across
	// start bringing it back
	if(seconds < halfTotalTime)
		xPos = seconds -halfTotalTime*0.5f;
	else
		xPos = totalTime - seconds -halfTotalTime*0.5f;

	// First draw world to screen
	modelViewMatrix.PushMatrix();	
		M3DMatrix44f mCamera;
		cameraFrame.GetCameraMatrix(mCamera);
		modelViewMatrix.MultMatrix(mCamera);

		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vWhite, 0);

		floorBatch.Draw();
		DrawWorld(0.0f, xPos);
	modelViewMatrix.PopMatrix();
	
	if(bUsePBOPath)
	{
		// First bind the PBO as the pack buffer, then read the pixels directly to the PBO
		glBindBuffer(GL_PIXEL_PACK_BUFFER, pixBuffObjs[0]);
		glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, NULL);
		glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

		// Next bind the PBO as the unpack buffer, then push the pixels straight into the texture
		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pixBuffObjs[0]);
        
        // Setup texture unit for new blur, this gets imcremented every frame 
		glActiveTexture(GL_TEXTURE0+GetBlurTarget0() ); 
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
	}
	else
	{
		// Grab the screen pixels and copy into local memory
		glReadPixels(0, 0, screenWidth, screenHeight, GL_RGB, GL_UNSIGNED_BYTE, pixelData);
		
		// Push pixels from client memory into texture
        // Setup texture unit for new blur, this gets imcremented every frame
		glActiveTexture(GL_TEXTURE0+GetBlurTarget0() );
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, screenWidth, screenHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, pixelData);
	}

	// Draw full screen quad with blur shader and all blur textures
	projectionMatrix.PushMatrix(); 
		projectionMatrix.LoadIdentity();
		projectionMatrix.LoadMatrix(orthoMatrix);
		modelViewMatrix.PushMatrix();	
			modelViewMatrix.LoadIdentity();
			glDisable(GL_DEPTH_TEST); 
			SetupBlurProg();
			screenQuad.Draw();
			glEnable(GL_DEPTH_TEST); 
		modelViewMatrix.PopMatrix(); 
	projectionMatrix.PopMatrix();

	// Move to the next blur texture for the next frame
	AdvanceBlurTaget();
    
    // Do the buffer Swap
    glutSwapBuffers();
        
    // Do it again
    glutPostRedisplay();

    UpdateFrameCount();
}
Exemple #23
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();
}
Exemple #24
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();
}
Exemple #25
0
///////////////////////////////////////////////////////////////////////////////
// Render the block
void RenderBlock(void)
	{
	GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f};
	GLfloat vWhite[] = { 1.0f, 1.0f, 1.0f, 1.0f };

	switch(nStep)
		{
		// Wire frame
		case 0:
			glEnable(GL_BLEND);
			glEnable(GL_LINE_SMOOTH);
			shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vRed);
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
			glDisable(GL_CULL_FACE);

			// Draw the cube
			cubeBatch.Draw();

			break;

		// Wire frame, but not the back side... we also want the block to be in the stencil buffer
		case 1:
			shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vRed);

			// Draw solid block in stencil buffer
			// Back face culling prevents the back sides from showing through
			// The stencil pattern is used to mask when we draw the floor under it
			// to keep it from showing through.
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
			glEnable(GL_STENCIL_TEST);
			glStencilFunc(GL_NEVER, 0, 0);
			glStencilOp(GL_INCR, GL_INCR, GL_INCR);
			cubeBatch.Draw();
			glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
			glDisable(GL_STENCIL_TEST);

			glEnable(GL_BLEND);
			glEnable(GL_LINE_SMOOTH);
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

			// Draw the front side cube
			cubeBatch.Draw();
			break;

		// Solid
		case 2:
			shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vRed);
			
			// Draw the cube
			cubeBatch.Draw();
			break;

		// Lit
		case 3:
			shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(),
				projectionMatrix.GetMatrix(), vLightPos, vRed);

			// Draw the cube
			cubeBatch.Draw();
			break;

		// Textured & Lit
		case 4:
		case 5:
		default:
			glBindTexture(GL_TEXTURE_2D, textures[2]);
			shaderManager.UseStockShader(GLT_SHADER_TEXTURE_POINT_LIGHT_DIFF, modelViewMatrix.GetMatrix(),
				projectionMatrix.GetMatrix(), vLightPos, vWhite, 0);

			glBindTexture(GL_TEXTURE_2D, textures[1]);
			topBlock.Draw();
			glBindTexture(GL_TEXTURE_2D, textures[2]);
			frontBlock.Draw();
			glBindTexture(GL_TEXTURE_2D, textures[3]);
			leftBlock.Draw();

			break;
		}
	
	// Put everything back
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_CULL_FACE);
	glDisable(GL_BLEND);
	glDisable(GL_LINE_SMOOTH);
	glDisable(GL_STENCIL_TEST);
	}
///////////////////////////////////////////////////////////////////////////////
// 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();
}
Exemple #27
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();
}
///////////////////////////////////////////////////////////////////////////////
// Render a frame. The owning framework is responsible for buffer swaps,
// flushes, etc.
void RenderScene(void)
{
	static CStopWatch animationTimer;
	float yRot = animationTimer.GetElapsedSeconds() * 60.0f;
//	MoveCamera();

	modelViewMatrix.PushMatrix();	
		M3DMatrix44f mCamera;
		cameraFrame.GetCameraMatrix(mCamera);
		modelViewMatrix.MultMatrix(mCamera);
		
		GLfloat vFloorColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };

		if(bUseFBO)
		{
			glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboName);
#ifndef OPENGL_ES
			glDrawBuffers(3, fboBuffs);
#endif
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

			// Need light position relative to the Camera
			M3DVector4f vLightTransformed;
			m3dTransformVector4(vLightTransformed, vLightPos, mCamera);
			UseProcessProgram(vLightTransformed, vFloorColor, 0);
		}
		else
		{
			glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
#ifndef OPENGL_ES
			glDrawBuffers(1, windowBuff);
#endif
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vFloorColor, 0);
		}

        glBindTexture(GL_TEXTURE_2D, textures[0]); // Marble
		floorBatch.Draw();
		DrawWorld(yRot);

	modelViewMatrix.PopMatrix();

	if(bUseFBO)
	{
		// Direct drawing to the window
		glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
#ifndef OPENGL_ES
		glDrawBuffers(1, windowBuff);
#endif
		glViewport(0, 0, screenWidth, screenHeight);

#ifndef OPENGL_ES
		// Source buffer reads from the framebuffer object
		glBindFramebuffer(GL_READ_FRAMEBUFFER, fboName);

		// Copy greyscale output to the left half of the screen
		glReadBuffer(GL_COLOR_ATTACHMENT1);
		glBlitFramebuffer(0, 0, screenWidth/2, screenHeight,
						  0, 0, screenWidth/2, screenHeight,
						  GL_COLOR_BUFFER_BIT, GL_NEAREST );
	
		// Copy the luminance adjusted color to the right half of the screen
		glReadBuffer(GL_COLOR_ATTACHMENT2);	
		glBlitFramebuffer(screenWidth/2, 0, screenWidth, screenHeight,
						  screenWidth/2, 0, screenWidth, screenHeight,
						  GL_COLOR_BUFFER_BIT, GL_NEAREST );

		// Scale the unaltered image to the upper right of the screen
		glReadBuffer(GL_COLOR_ATTACHMENT0);
		glBlitFramebuffer(0, 0, screenWidth, screenHeight,
						  (int)(screenWidth *(0.8)), (int)(screenHeight*(0.8)), 
						  screenWidth, screenHeight,
						  GL_COLOR_BUFFER_BIT, GL_LINEAR );

		glBindTexture(GL_TEXTURE_2D, 0);
#endif
	} 

    // Do the buffer Swap
    glutSwapBuffers();
        
    // Do it again
    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 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();
}