Hi,
I’ll start in little specs. I have a concept of a mesh which consists of triangles. The mesh knows how to calculate the normals and I am assured that the normals are correct.
Actually, there only difference between the two spheres on the image is GL_FLAT vs. GL_SMOOTH and I would argue that even on the left GL_FLAT image the shading is wrong.
gl.glMaterialfv(GL.GL_BACK, GL.GL_AMBIENT_AND_DIFFUSE, myAmbientColorBack.getComponents(null) );
gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, myAmbientColorFront.getComponents(null) );
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, ZERO );
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, Color.WHITE.getComponents(null) );
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
for (int t = 0; t < myMesh.pGetNumberOfElements(); t++) {
Element elem = myMesh.pGetElement(t);
gl.glBegin(GL.GL_TRIANGLES);
for (int v = 0; v < elem.pGetNumberOfNodes(); v++) {
VDouble x = myMesh.pGetX(elem.pGetNode(v));
VDouble n = normals[elem.pGetNode(v)];
gl.glVertex3d(x.pGet(0), x.pGet(1), x.pGet(2));
gl.glNormal3d(n.pGet(0), n.pGet(1), n.pGet(2));
}
gl.glEnd();
}
}
Then elsewhere in my init() I have:
GL gl = inDrawable.getGL();
gl.glClearColor(1f, 1f, 1f, 1f);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
gl.glEnable(GL.GL_POLYGON_OFFSET_LINE);
// Lights
gl.glEnable(GL.GL_LIGHTING);
gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, new float[] { .6f, .6f, .6f, 1f });
myLight0 = new GLUtils.Light(myCanvas3D, // Self-explanatory, really
GL.GL_LIGHT0,
0f, 0f, 3f,
Color.GRAY,
Color.BLACK);
// Uncomment for FLAT.
// gl.glShadeModel(GL.GL_FLAT);
Thanks for taking a look at this.
Dola