Hi. I am trying to implement the Earth model.
I have already rendered the Earth model with texture.
now, I want to put lighting effect on the Earth but It never works.
Could anybody comment on my source code??
below is source code and screen shot for the result
public void display(GLAutoDrawable drawable) {
//***************TEXTURE MAPPING***************//
// Enables this texture's target in the current GL context's state.
gl.glBegin(GL2.GL_TRIANGLES);
for (Triangle t: theEarth.triangles) {
gl.glNormal3d(t.a, t.b, t.c); //surface normal of the triangle
Vertex p0, p1, p2;
p0 = theEarth.vertices[t.v0];
p1 = theEarth.vertices[t.v1];
p2 = theEarth.vertices[t.v2];
gl.glTexCoord2d(p0.u, p0.v);
gl.glVertex3d(p0.x, p0.y, p0.z);
gl.glTexCoord2d(p1.u, p1.v);
gl.glVertex3d(p1.x, p1.y, p1.z);
gl.glTexCoord2d(p2.u, p2.v);
gl.glVertex3d(p2.x, p2.y, p2.z);
}
gl.glEnd(); // of the tessellated sphere
//***************TEXTURE MAPPING***************//
//***************LIGHTING***************// <------- this part is not working :(
// light to light up the scene. Ambient's value in RGBA
float[] lightAmbientValue = {0.1f, 0.1f, 0.1f, 1.0f};
// Diffuse light comes from a particular location. Diffuse's value in RGBA
float[] lightDiffuseValue = {1.0f, 1.0f, 1.0f, 1.0f};
// Diffuse light location xyz (in front of the screen).
float lightDiffusePosition[] = {0.0f, 2.0f, 2.0f, 1.0f};
gl.glLightfv(GL2.GL_LIGHT0, GL_AMBIENT, lightAmbientValue, 0);
gl.glLightfv(GL2.GL_LIGHT0, GL_DIFFUSE, lightDiffuseValue, 0);
gl.glLightfv(GL2.GL_LIGHT0, GL_POSITION, lightDiffusePosition, 0);
gl.glEnable(GL2.GL_LIGHT0);
//***************LIGHTING***************//
//***************CAMERA MOVEMENT***************//
gl.glLoadIdentity(); // reset the model-view matrix
glu.gluLookAt(posX, posY, posZ, posX, 0, 0, 0, 1, 0);
//***************CAMERA MOVEMENT***************//
}
Thanks for reading my message :)