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() );
final Vec4 worldLightPos = calcLightPosition();
final Vec4 lightPosCameraSpace = Mat4.mul( modelMatrix.top(), worldLightPos );
ProgramData whiteProg = programs[lightModel.ordinal()].whiteProg;
ProgramData colorProg = programs[lightModel.ordinal()].colorProg;
glUseProgram( whiteProg.theProgram );
glUniform4f( whiteProg.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
glUniform4f( whiteProg.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
glUniform3( whiteProg.cameraSpaceLightPosUnif, lightPosCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
float lightAttenuation = 1.2f;
glUniform1f( whiteProg.lightAttenuationUnif, lightAttenuation );
glUniform1f( whiteProg.shininessFactorUnif, matParams.getSpecularValue() );
glUniform4( whiteProg.baseDiffuseColorUnif,
drawDark ? darkColor.fillAndFlipBuffer( vec4Buffer ) : lightColor.fillAndFlipBuffer( vec4Buffer ) );
glUseProgram( colorProg.theProgram );
glUniform4f( colorProg.lightIntensityUnif, 0.8f, 0.8f, 0.8f, 1.0f );
glUniform4f( colorProg.ambientIntensityUnif, 0.2f, 0.2f, 0.2f, 1.0f );
glUniform3( colorProg.cameraSpaceLightPosUnif, lightPosCameraSpace.fillAndFlipBuffer( vec4Buffer ) );
glUniform1f( colorProg.lightAttenuationUnif, lightAttenuation );
glUniform1f( colorProg.shininessFactorUnif, matParams.getSpecularValue() );
glUseProgram( 0 );
{
modelMatrix.push();
// Render the ground plane.
{
modelMatrix.push();
Mat3 normMatrix = new Mat3( modelMatrix.top() );
normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );
glUseProgram( whiteProg.theProgram );
glUniformMatrix4( whiteProg.modelToCameraMatrixUnif, false,
modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
glUniformMatrix3( whiteProg.normalModelToCameraMatrixUnif, false,
normMatrix.fillAndFlipBuffer( mat3Buffer ) );
planeMesh.render();
glUseProgram( 0 );
modelMatrix.pop();
}
// Render the Cylinder
{
modelMatrix.push();
modelMatrix.applyMatrix( objtPole.calcMatrix() );
if ( scaleCyl ) {
modelMatrix.scale( 1.0f, 1.0f, 0.2f );
}
Mat3 normMatrix = new Mat3( modelMatrix.top() );
normMatrix = Glm.transpose( Glm.inverse( normMatrix ) );
ProgramData prog = drawColoredCyl ? colorProg : whiteProg;
glUseProgram( prog.theProgram );
glUniformMatrix4( prog.modelToCameraMatrixUnif, false,
modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
glUniformMatrix3( prog.normalModelToCameraMatrixUnif, false,
normMatrix.fillAndFlipBuffer( mat3Buffer ) );
if ( drawColoredCyl ) {
cylinderMesh.render( "lit-color" );
} else {
cylinderMesh.render( "lit" );
}
glUseProgram( 0 );
modelMatrix.pop();
}
// Render the light
if ( drawLightSource ) {
modelMatrix.push();
modelMatrix.translate( worldLightPos.x, worldLightPos.y, worldLightPos.z );
modelMatrix.scale( 0.1f, 0.1f, 0.1f );
glUseProgram( unlit.theProgram );
glUniformMatrix4( unlit.modelToCameraMatrixUnif, false,
modelMatrix.top().fillAndFlipBuffer( mat4Buffer ) );
glUniform4f( unlit.objectColorUnif, 0.8078f, 0.8706f, 0.9922f, 1.0f );
cubeMesh.render( "flat" );
modelMatrix.pop();
}
modelMatrix.pop();
}
}