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();
}
Example #2
0
void SetupOITResolveProg()
{
	glUseProgram(oitResolve);

	// Set projection matrix
	glUniformMatrix4fv(glGetUniformLocation(oitResolve, "pMatrix"),
		1, GL_FALSE, transformPipeline.GetProjectionMatrix());

	// Set MVP matrix
	glUniformMatrix4fv(glGetUniformLocation(oitResolve, "mvMatrix"),
		1, GL_FALSE, transformPipeline.GetModelViewMatrix());

	// Now setup the right textures
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, msTexture[0]);
	glUniform1i(glGetUniformLocation(oitResolve, "origImage"), 0);

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, depthTextureName);
	glUniform1i(glGetUniformLocation(oitResolve, "origDepth"), 1);

	glUniform1f(glGetUniformLocation(oitResolve, "sampleCount"), 8);

	glActiveTexture(GL_TEXTURE0);
	gltCheckErrors(oitResolve);
}
Example #3
0
// Called to draw scene
static 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.Rotate(40.0f, 0.0f, 1.0f, 0.0f);
    modelViewMatrix.Rotate(20.0f, 1.0f, 0.0f, 0.0f);

    float f = (float)rotTimer.GetElapsedSeconds();
    GLfloat vViewpoint[] = { sinf(f * 3.1f) * 30.0f, cosf(f * 2.4f) * 30.0f, sinf(f * 1.7f) * 30.0f };

    glUseProgram(cullingShader);
    glUniformMatrix4fv(locMVP, 1, GL_FALSE, transformPipeline.GetModelViewProjectionMatrix());
    glUniformMatrix4fv(locMV, 1, GL_FALSE, transformPipeline.GetModelViewMatrix());
    glUniformMatrix3fv(locNM, 1, GL_FALSE, transformPipeline.GetNormalMatrix());
    glUniform3fv(locViewpoint, 1, vViewpoint);

    torusBatch.Draw();

    modelViewMatrix.PopMatrix();

    glutSwapBuffers();
    glutPostRedisplay();
}
void MyShaderManager::useDiffVert(M3DVector4f vDiffuseColor, M3DVector3f vLightEyePos, GLGeometryTransform tPipeline)
{
	glUseProgram(diffVert);
	glUniform4fv(vDiffColor, 1, vDiffuseColor);
	glUniform3fv(vDiffLight, 1, vLightEyePos);
	glUniformMatrix4fv(vDiffMVP, 1, GL_FALSE, tPipeline.GetModelViewProjectionMatrix());
	glUniformMatrix4fv(vDiffMV, 1, GL_FALSE, tPipeline.GetModelViewMatrix());
	glUniformMatrix3fv(vDiffNM, 1, GL_FALSE, tPipeline.GetNormalMatrix());
}
void MyShaderManager::useADSFrag(M3DVector4f vDiffuseColor, M3DVector4f vAmbientColor, M3DVector4f vSpecularColor, M3DVector4f vLightEyePos, GLGeometryTransform tPipeline)
{
	glUseProgram(ADSFrag);
	glUniform4fv(fADSambColor, 1, vAmbientColor);
	glUniform4fv(fADSspecColor, 1, vSpecularColor);
	glUniform4fv(fADSdiffColor, 1, vDiffuseColor);
	glUniformMatrix4fv(fADSMVP, 1, GL_FALSE, tPipeline.GetModelViewProjectionMatrix());
	glUniformMatrix4fv(fADSMV, 1, GL_FALSE, tPipeline.GetModelViewMatrix());
	glUniformMatrix3fv(fADSNM, 1, GL_FALSE, tPipeline.GetNormalMatrix());
}
///////////////////////////////////////////////////////////////////////////////
// Render the floor
void RenderFloor(void)
{
    GLfloat vBrown [] = { 0.55f, 0.292f, 0.09f, 1.0f};
    GLfloat vFloor[] = { 1.0f, 1.0f, 1.0f, 0.6f };

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

        // Wire frame, but not the back side.. and only where stencil == 0
        case 1:
            glEnable(GL_BLEND);
            glEnable(GL_LINE_SMOOTH);

            glEnable(GL_STENCIL_TEST);
            glStencilFunc(GL_EQUAL, 0, 0xff);

            shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBrown);
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
            break;

        // Solid
        case 2:
        case 3:	
            shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vBrown);
            break;

        // Textured
        case 4:
        case 5:
        default:
            glBindTexture(GL_TEXTURE_2D, textures[0]);
            shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE, transformPipeline.GetModelViewProjectionMatrix(), vFloor, 0);
            break;
        }
    
    // Draw the floor
    floorBatch.Draw();

    // 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);
}
Example #7
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();
}
Example #8
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();
}
Example #9
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();
}
Example #10
0
///////////////////////////////////////////////////////////////////////////////
// Draw the scene 
// 
void DrawWorld()
{
	modelViewMatrix.moveTo(0.0f, 0.8f, 0.0f);
	modelViewMatrix.push();
	modelViewMatrix.moveTo(-0.3f, 0.f, 0.0f);
	modelViewMatrix.scaleTo(0.40, 0.8, 0.40);
	modelViewMatrix.rotateTo(50.0, 0.0, 10.0, 0.0);
	glSampleMaski(0, 0x02);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtYellow);
	glass1Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(0.4f, 0.0f, 0.0f);
	modelViewMatrix.scaleTo(0.5, 0.8, 1.0);
	modelViewMatrix.rotateTo(-20.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x04);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtGreen);
	glass2Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(1.0f, 0.0f, -0.6f);
	modelViewMatrix.scaleTo(0.3, 0.9, 1.0);
	modelViewMatrix.rotateTo(-40.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x08);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtMagenta);
	glass3Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(-0.8f, 0.0f, -0.60f);
	modelViewMatrix.scaleTo(0.6, 0.9, 0.40);
	modelViewMatrix.rotateTo(60.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x10);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtBlue);
	glass4Batch.draw();
	modelViewMatrix.pop();

	modelViewMatrix.push();
	modelViewMatrix.moveTo(0.1f, 0.0f, 0.50f);
	modelViewMatrix.scaleTo(0.4, 0.9, 0.4);
	modelViewMatrix.rotateTo(205.0, 0.0, 1.0, 0.0);
	glSampleMaski(0, 0x20);
	shaderManager.useStockShader(GLT_SHADER_FLAT, transformPipeline.GetMVPMatrix(), vLtPink);
	glass4Batch.draw();
	modelViewMatrix.pop();
}
Example #11
0
void SetupRC() {
    glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    glEnable(GL_DEPTH_TEST);
    shader = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vVertex", GLT_ATTRIBUTE_NORMAL, "vNormal");
    fprintf(stdout, "GLT_ATTRIBUTE_VERTEX : %d\nGLT_ATTRIBUTE_COLOR : %d \n", GLT_ATTRIBUTE_VERTEX, GLT_ATTRIBUTE_COLOR);

shaderColorLocation = glGetUniformLocation(shader, "light1.color");
shaderAngleLocation = glGetUniformLocation(shader, "light1.angle");
shaderAttenuation0Location = glGetUniformLocation(shader, "light1.attenuation0");
shaderAttenuation1Location = glGetUniformLocation(shader, "light1.attenuation1");
shaderAttenuation2Location = glGetUniformLocation(shader, "light1.attenuation2");

    MVMatrixLocation = glGetUniformLocation(shader,"MVMatrix");
    MVPMatrixLocation = glGetUniformLocation(shader,"MVPMatrix");
    normalMatrixLocation = glGetUniformLocation(shader,"normalMatrix");
    ambientLightLocation = glGetUniformLocation(shader,"ambientLight");
    shaderPositionLocation = glGetUniformLocation(shader, "light1.position");

shaderAmbientColorLocation = glGetUniformLocation(shader, "material.ambientColor");
    shaderDiffuseColorLocation = glGetUniformLocation(shader, "material.diffuseColor");
    shaderSpecularColorLocation = glGetUniformLocation(shader, "material.specularColor");
    shaderSpecularExponentLocation = glGetUniformLocation(shader, "material.specularExponent");
if(MVMatrixLocation==-1){
        fprintf(stderr,"uniform MVMatrix could not be found\n");
    }
    
geometryPipeline.SetMatrixStacks(modelView, projection);
    M3DVector3f eye = {1.0f, 1.0f, 1.0f};
    M3DVector3f at = {5.0f, 5.0f, 5.0f};
    M3DVector3f up = {1.0f, 1.0f, 1.0f};
    LookAt(cameraFrame, eye, at, up);
}
Example #12
0
// Called to draw scene
void RenderScene(void)
	{
	// Clear the window and the depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Turn culling on if flag is set
	if(iCull)
		glEnable(GL_CULL_FACE);
	else
		glDisable(GL_CULL_FACE);

	// Enable depth testing if flag is set
	if(iDepth)
		glEnable(GL_DEPTH_TEST);
	else
		glDisable(GL_DEPTH_TEST);

		
    modelViewMatix.PushMatrix(viewFrame);
            
    GLfloat vRed[] = { 1.0f, 0.0f, 0.0f, 1.0f };
    //shaderManager.UseStockShader(GLT_SHADER_FLAT, transformPipeline.GetModelViewProjectionMatrix(), vRed);
    shaderManager.UseStockShader(GLT_SHADER_DEFAULT_LIGHT, transformPipeline.GetModelViewMatrix(), transformPipeline.GetProjectionMatrix(), vRed);
    

    torusBatch.Draw();

    modelViewMatix.PopMatrix();


    glutSwapBuffers();
	}
Example #13
0
void setup_rc() {
   glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
   shader_light = gltLoadShaderPairWithAttributes("gouraud_shading.vp", "gouraud_shading.fp", 3, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color", GLT_ATTRIBUTE_NORMAL, "vertex_normal");
   shader_color = gltLoadShaderPairWithAttributes("pass_thru_shader.vp", "pass_thru_shader.fp", 2, GLT_ATTRIBUTE_VERTEX, "vertex_position", GLT_ATTRIBUTE_COLOR, "vertex_color");
   mvp_matrix_location_shader_color = glGetUniformLocation(shader_color, "mvp_matrix");
   mvp_matrix_location = glGetUniformLocation(shader_light, "mvp_matrix");
   mv_matrix_location = glGetUniformLocation(shader_light, "mv_matrix");
   v_matrix_location = glGetUniformLocation(shader_light, "v_matrix");
   normal_matrix_location = glGetUniformLocation(shader_light, "normal_matrix");
   intensity_ambient_component_location = glGetUniformLocation(shader_light, "intensity_ambient_component");
   light_0_position_location = glGetUniformLocation(shader_light, "light_0.position");
   light_0_intensity_diffuse_location = glGetUniformLocation(shader_light, "light_0.intensity_diffuse");
   light_0_intensity_specular_location = glGetUniformLocation(shader_light, "light_0.intensity_specular");
   light_0_attenuation_location = glGetUniformLocation(shader_light, "light_0.attenuation");
   material_0_ka_location = glGetUniformLocation(shader_light, "material_0.ka");
   material_0_kd_location = glGetUniformLocation(shader_light, "material_0.kd");
   material_0_ks_location = glGetUniformLocation(shader_light, "material_0.ks");
   material_0_alpha_location = glGetUniformLocation(shader_light, "material_0.alpha");
   light_0.set_position(0.0f, 0.0f, 0.0f);
   light_0.set_intensity_diffuse(1.0f, 1.0f, 1.0f);
   light_0.set_intensity_specular(1.0f, 1.0f, 1.0f);
   light_0.set_attenuation(0.0f, 0.1f, 0.0f);
   material_0.set_parameters(1.0f, 1.0f, 1.0f, 200.0f);
   geometry_pipeline.SetMatrixStacks(mv_stack, p_stack);
   glEnable(GL_CULL_FACE);
   glEnable(GL_DEPTH_TEST);
   glFrontFace(GL_CCW);
}
Example #14
0
///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
	{
	glViewport(0, 0, w, h);
	viewFrustum.SetPerspective(35.0f, float(w) / float(h), 1.0f, 500.0f);
	projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
    transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
	}
///////////////////////////////////////////////////////
// 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();
    }
Example #16
0
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			break;
		case 2:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
			break;
		case 3:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR);
			break;
		case 4:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
			break;
		case 5:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
			break;
		case 6:
			{
				GLfloat fLargest = 0;
				glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);	// 获取各向异性支持的数量
				glTexParameteri(GL_TEXTURE_2D, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, fLargest);
			}
			break;
		case 7:
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1);
		}
	}

	// Trigger redraw
	glutPostRedisplay();
}
Example #17
0
  void ChangeSize(int w, int h){
    if(h == 0)  { h = 1; }
    glViewport(0, 0, w, h);      
    viewFrustum.SetPerspective(35.0f, float(w)/float(h), 1.0f, 1000.0f);
    projection.LoadMatrix(viewFrustum.GetProjectionMatrix());
	geometryPipeline.SetMatrixStacks(modelView, projection);
   }
///////////////////////////////////////////////////////////////////////////////
// This is called at least once and before any rendering occurs. If the screen
// is a resizeable window, then this will also get called whenever the window
// is resized.
void ChangeSize(int nWidth, int nHeight)
{
	glViewport(0, 0, nWidth, nHeight);
	transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
 	viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f);
	projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
	modelViewMatrix.LoadIdentity();

	// update screen sizes
	screenWidth = nWidth;
	screenHeight = nHeight;

	// reset screen aligned quad
	gltGenerateOrtho2DMat(screenWidth, screenHeight, orthoMatrix, screenQuad);

	free(pixelData);
	pixelDataSize = screenWidth*screenHeight*3*sizeof(unsigned int);
	pixelData = (void*)malloc(pixelDataSize);

	//  Resize PBOs
#ifndef OPENGL_ES
	glBindBuffer(GL_PIXEL_PACK_BUFFER, pixBuffObjs[0]);
	glBufferData(GL_PIXEL_PACK_BUFFER, pixelDataSize, pixelData, GL_DYNAMIC_COPY);
	glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
#endif

	gltCheckErrors();
}
///////////////////////////////////////////////////////////////////////////////
// This is called at least once and before any rendering occurs. If the screen
// is a resizeable window, then this will also get called whenever the window
// is resized.
void ChangeSize(int nWidth, int nHeight)
{
	glViewport(0, 0, nWidth, nHeight);
	transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
 
	viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f);
	projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
	modelViewMatrix.LoadIdentity();

	// update screen sizes
	screenWidth = nWidth;
	screenHeight = nHeight;

	glBindRenderbuffer(GL_RENDERBUFFER, depthBufferName);
#ifndef ANGLE
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32, screenWidth, screenHeight);
#else
	glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, screenWidth, screenHeight);
#endif
	glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[0]);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight);
	glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[1]);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight);
	glBindRenderbuffer(GL_RENDERBUFFER, renderBufferNames[2]);
	glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, screenWidth, screenHeight);
}
Example #20
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();
}
Example #21
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();
}
Example #22
0
void loadUniform(M3DVector3f ambientLight, M3DVector3f color, M3DVector3f position, M3DVector3f ambientColor, M3DVector3f diffuseColor,	float lightAngle, float attenuation0, float attenuation1, float attenuation2,	M3DVector3f specularColor, float specularExponent)
{
	glUniformMatrix4fv(MVMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewMatrix());
	glUniformMatrix4fv(MVPMatrixLocation, 1, GL_FALSE, geometryPipeline.GetModelViewProjectionMatrix());
	glUniformMatrix3fv(normalMatrixLocation, 1, GL_FALSE, geometryPipeline.GetNormalMatrix());
	glUniform3fv(ambientLightLocation, 1, ambientLight);
	glUniform3fv(shaderPositionLocation, 1, position);
	glUniform3fv(shaderColorLocation, 1, color);
	glUniform1f(shaderAngleLocation, lightAngle);
	glUniform1f(shaderAttenuation0Location, attenuation0);
	glUniform1f(shaderAttenuation1Location, attenuation1);
	glUniform1f(shaderAttenuation2Location, attenuation2);
	glUniform3fv(shaderAmbientColorLocation, 1, ambientColor);
	glUniform3fv(shaderDiffuseColorLocation, 1, diffuseColor);
	glUniform3fv(shaderSpecularColorLocation, 1, specularColor);
	glUniform1f(shaderSpecularExponentLocation, specularExponent);
}
Example #23
0
void SetupStraightTexProg()
{
	// Set the cur prog for tex replace
	glUseProgram(mapTexProg);

	// Set MVP matrix
	glUniformMatrix4fv(glGetUniformLocation(mapTexProg, "mvpMatrix"), 1, GL_FALSE, transformPipeline.GetModelViewProjectionMatrix());
}
///////////////////////////////////////////////////////////////////////////////
// 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();
}
Example #25
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();
}
Example #26
0
void ChangeSize(int nWidth, int nHeight)
    {
	glViewport(0, 0, nWidth, nHeight);
	transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
	
	viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f);
	projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
	modelViewMatrix.LoadIdentity();
	}
Example #27
0
void Reshape(int w,int h)
{
	if(h == 0) h = 1;
	glViewport(0,0,w,h);

	viewFrustum.SetPerspective(35.0,(float) w /(float) h,1.0,2000.0);
	projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
	transformPipeLine.SetMatrixStacks(modelViewMatrix,projectionMatrix);
}
Example #28
0
void changeSize(int w, int h)
{
	glViewport(0, 0, w, h);

	if(h <= 0) {h = 1;}

	viewFrustum.SetPerspective(35.0f, float(w)/float(h), 1.0f, 100.0f);
	projectionStack.LoadMatrix(viewFrustum.GetProjectionMatrix());
	tPipeline.SetMatrixStacks(modelViewStack, projectionStack);
}
Example #29
0
void drawSun()
{
    //draw the sphere batch as a sun
    modelViewMatrix.PushMatrix();
    modelViewMatrix.Translatev(vLightPosition);
    shaderManager.UseStockShader(GLT_SHADER_FLAT,
                                 transformPipeline.GetModelViewProjectionMatrix(),vWhite);
    sphereBatch.Draw();
    modelViewMatrix.PopMatrix();
}
Example #30
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();
}