protected void display() {
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClearDepth( 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
MatrixStack modelMatrix = new MatrixStack();
modelMatrix.setMatrix( viewPole.calcMatrix() );
Vec4 lightDirCameraSpace = Mat4.mul( modelMatrix.top(), lightDirection );
ProgramData whiteDiffuse = showAmbient ? whiteAmbDiffuseColor : whiteDiffuseColor;
ProgramData vertexDiffuse = showAmbient ? vertexAmbDiffuseColor : vertexDiffuseColor;
if ( showAmbient ) {
glUseProgram( whiteDiffuse.theProgram );
glUniform4f( whiteDiffuse.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
glUniform4f( whiteDiffuse.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
glUseProgram( vertexDiffuse.theProgram );
glUniform4f( vertexDiffuse.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
glUniform4f( vertexDiffuse.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
} else {
glUseProgram( whiteDiffuse.theProgram );
glUniform4f( whiteDiffuse.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f );
glUseProgram( vertexDiffuse.theProgram );
glUniform4f( vertexDiffuse.lightIntensityUnif, 1.0f, 1.0f, 1.0f, 1.0f );
}
glUseProgram( whiteDiffuse.theProgram );
glUniform3( whiteDiffuse.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
glUseProgram( vertexDiffuse.theProgram );
glUniform3( vertexDiffuse.dirToLightUnif, lightDirCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
glUseProgram( 0 );
{
modelMatrix.push();
// Render the ground plane.
{
modelMatrix.push();
glUseProgram( whiteDiffuse.theProgram );
glUniformMatrix4( whiteDiffuse.modelToCameraMatrixUnif, false,
modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
Mat3 normMatrix = new Mat3( modelMatrix.top() );
glUniformMatrix3( whiteDiffuse.normalModelToCameraMatrixUnif, false,
normMatrix.fillAndFlipBuffer( mat3Buffer ) );
planeMesh.render();
glUseProgram( 0 );
modelMatrix.pop();
}
// Render the Cylinder
{
modelMatrix.push();
modelMatrix.applyMatrix( objtPole.calcMatrix() );
if ( drawColoredCyl ) {
glUseProgram( vertexDiffuse.theProgram );
glUniformMatrix4( vertexDiffuse.modelToCameraMatrixUnif, false,
modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
Mat3 normMatrix = new Mat3( modelMatrix.top() );
glUniformMatrix3( vertexDiffuse.normalModelToCameraMatrixUnif, false,
normMatrix.fillAndFlipBuffer( mat3Buffer ) );
cylinderMesh.render( "lit-color" );
} else {
glUseProgram( whiteDiffuse.theProgram );
glUniformMatrix4( whiteDiffuse.modelToCameraMatrixUnif, false,
modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
Mat3 normMatrix = new Mat3( modelMatrix.top() );
glUniformMatrix3( whiteDiffuse.normalModelToCameraMatrixUnif, false,
normMatrix.fillAndFlipBuffer( mat3Buffer ) );
cylinderMesh.render( "lit" );
}
glUseProgram( 0 );
modelMatrix.pop();
}
modelMatrix.pop();
}
}