Hi,

I'm having problems getting OpenGL lighting to work.  Right now I'm
playing with a grid of random
polygons.  I've assigned a material that I think should give a light
brown color to everything.
But what I'm seeing is everything is either mostly black or mostly
white most of the time, and there's
a narrow view of angles where I can see shades of my desired color
(and I am getting some correct-looking
shading, so it looks like the normals are at least partly right).  If
I had to guess, I'd say that I'm seeing only
a specular component, and no diffuse or ambient - even though I am
setting material only for diffuse and
ambient, and leaving specular at the default.

Here's some relevant bits:

                        global_ambient = FloatBuffer.allocate(4);
                        global_ambient.put(0.5f);
                        global_ambient.put(0.5f);
                        global_ambient.put(0.5f);
                        global_ambient.put(1.0f);

                        position = FloatBuffer.allocate(4);
                        position.put(10f);
                        position.put(10f);
                        position.put(10f);
                        position.put(1f);

                        gl.glEnable(GL10.GL_LIGHTING);
                        gl.glEnable(GL10.GL_LIGHT0);
                        gl.glLightfv(GL10.GL_LIGHT0, 
GL10.GL_AMBIENT_AND_DIFFUSE,
global_ambient);
                        gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, 
position);
                [ ... ]
                float[] mycolor = { 0.8f, 0.7f, 0.6f, 1.0f };
                gl.glMaterialfv(GL10.GL_FRONT, GL10.GL_AMBIENT_AND_DIFFUSE, 
mycolor,
0);
                gl.glVertexPointer(3, GL10.GL_FIXED, 0, mVertexBuffer);
                gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
                gl.glNormalPointer(GL10.GL_FIXED, 0, mNormalBuffer);
                gl.glDrawElements(GL10.GL_TRIANGLES, 6*(GRID-1)*(GRID-1),
GL10.GL_UNSIGNED_SHORT, mIndexBuffer);

Any ideas on what might be wrong?  Is there any sample code that
covers this territory?

Incidentally, I couldn't get the FloatBuffer version of glMaterialfv
to work, my code kept crashing.

       tom

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to