I am trying to add a light source to one of my application - but the result it quite strange. I tried to cut down the problem without any luck. Maybe anyone of this forum could help.
For better understanding I created a small 3d application (used nehe lesson for that) in order to focus the problem. The project consists of two simple classes with one triangle (not rotating) and one quad which rotates.
I placed a light into the scene. First all looks ok:
- Both front faces of triangle and quad are lighted
- The rotating quad gets darker which also seems to be ok
- When the background of the quad gets into the scene the light does not seem to work anymore since it remains dark grey ?
Here are the relevant code bits:
Using java Syntax Highlighting
- ...
- public void onDrawFrame(GL10 gl) {
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
- gl.glMatrixMode(GL10.GL_MODELVIEW);
- gl.glLoadIdentity();
- // Testing LIGHT
- //
- gl.glEnable(GL10.GL_LIGHTING);
- gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, matAmbient, 0);
- gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, matDiffuse, 0);
- gl.glEnable(GL10.GL_LIGHT0);
- gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, lightAmbient, 0);
- gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, lightDiffuse, 0);
- gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, lightPos, 0);
- // draw triangle
- gl.glTranslatef(-1.5f, 0, -6);
- gl.glRotatef(triangleRot, 0, 1, 0);
- gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
- gl.glVertexPointer(3, GL10.GL_FLOAT, 0, triangleVertexBfr);
- gl.glColorPointer(4, GL10.GL_FLOAT, 0, triangleColorBfr);
- gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 3);
- gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
- // draw quad
- gl.glLoadIdentity();
- gl.glTranslatef(1.5f, 0, -6);
- gl.glRotatef(quadRot, 1, 0, 0);
- gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
- gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glVertexPointer(3, GL10.GL_FLOAT, 0, quadVertexBfr);
- gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
- gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
- // update rotations
- //triangleRot += 0.8f;
- quadRot -= 0.5f;
- }
- ...
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
Any ideas ?
// Edit: I attached the exported Eclipse project if anyone want to test it out.



