I am having show light on my models, when light is enabled either the texture is not lighted or if not texture, the mesh is black. I do have normals set, as I set cull face to back and they render correctly. As you can see I’ve tried very little lighting thing I’ve seen so far. Also the normals have been computed via Blender 3D.
gl.glShadeModel(GL.GL_SMOOTH);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, position, 0); // 3, 3, 0
gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, diffuse, 0); // 1, 1, 1, 1
gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, ambient, 0); // 0, 0, 0, 1
gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, specular, 0); // 1, 1, 1, 1
gl.glLightf(GL.GL_LIGHT0, GL.GL_LINEAR_ATTENUATION, 0.25f);
gl.glEnable(GL.GL_LIGHTING);
gl.glEnable(GL.GL_LIGHT0);
gl.glDepthFunc(GL.GL_LESS);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glColorMaterial(GL.GL_BACK, GL.GL_DIFFUSE);
gl.glEnable(GL.GL_COLOR_MATERIAL);
// RENDER MESH
gl.glEnable(GL.GL_CULL_FACE);
gl.glCullFace(GL.GL_BACK);
gl.glMaterialfv(GL.GL_BACK, GL.GL_EMISSION, ambient, 0); // 0,0,0,1
gl.glMaterialfv(GL.GL_BACK, GL.GL_DIFFUSE, diffuse, 0); // 1,1,1,1
gl.glMaterialfv(GL.GL_BACK, GL.GL_SPECULAR, specular, 0); // 1,1,1,1
gl.glMaterialf(GL.GL_BACK, GL.GL_SHININESS, shininess); // 25
gl.glCallList(1);
gl.glDisable(GL.GL_CULL_FACE);
gl.glDisable(GL.GL_COLOR_MATERIAL);
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glDisable(GL.GL_LIGHTING);
As for my mesh code:
public void init(GL gl) {
this.setDisplayId((short) gl.glGenLists(1));
gl.glNewList(this.getDisplayId(), GL.GL_COMPILE);
gl.glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
gl.glBegin(GL.GL_TRIANGLES);
for (int i = 0; i < faces.length; i++) {
float[] v1 = vertices[faces[i][0]];
float[] v2 = vertices[faces[i][1]];
float[] v3 = vertices[faces[i][2]];
/*
* Face Point 1
*/
if(uv != null) {
float[] n = uv[faces[i][0]];
gl.glTexCoord2f(n[0], n[1]);
}
if(normals != null) {
float[] n = normals[faces[i][0]];
gl.glNormal3f(n[0], n[1], n[2]);
}
gl.glVertex3f(v1[0], v1[1], v1[2]);
/*
* Face Point 2
*/
if(uv != null) {
float[] n = uv[faces[i][1]];
gl.glTexCoord2f(n[0], n[1]);
}
if(normals != null) {
float[] n = normals[faces[i][1]];
gl.glNormal3f(n[0], n[1], n[2]);
}
gl.glVertex3f(v2[0], v2[1], v2[2]);
/*
* Face Point 3
*/
if(uv != null) {
float[] n = uv[faces[i][2]];
gl.glTexCoord2f(n[0], n[1]);
}
if(normals != null) {
float[] n = normals[faces[i][2]];
gl.glNormal3f(n[0], n[1], n[2]);
}
gl.glVertex3f(v3[0], v3[1], v3[2]);
}
gl.glEnd();
gl.glEndList();
}