OpenGL ES ... glEnable(GL_LIGHTING) causes crash?

Apprentice
Posts: 8
Joined: 2008.09
Post: #1
So I am trying to add lighting to an opengl es iphone app and I have run into a bit of a snag. If I mak a glEnable(GL_LIGHTING) call the program will crash whenever I make a glDrawElements() call. If I comment out the glEnable(GL_LIGHTING) call then the program runs fine (obviously without lighting though). Here is my entire setup.

glMatrixMode(GL_PROJECTION);
glEnable(GL_DEPTH_TEST);
size = zNear * tanf(DEGREES_TO_RADIANS(fieldOfView) / 2.0);
CGRect rect = view.bounds;
glFrustumf(-size, size, -size / (rect.size.width / rect.size.height), size /
(rect.size.width / rect.size.height), zNear, zFar);
glViewport(0, 0, rect.size.width, rect.size.height);
glMatrixMode(GL_MODELVIEW);

glEnable(GL_LIGHTING); //***********//

glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

What am I doing that openGL ES is objecting to? THNX
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #2
That code's all mixed up and not enough to go off of. We'll probably need more than that to help you out. Wink
Quote this message in a reply
Member
Posts: 87
Joined: 2006.08
Post: #3
I would make sure your normal array is correct. DrawElements will crash if it reads an invalid address while iterating across your array.

As a first order test, call glDisableClientState(GL_NORMAL_ARRAY) before the call to DrawElements.
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #4
Heck, it seems like any mis-set client state will do that (colors, verts, etc.). I was going to suggest the same, but... I don't trust my mind reading skills! LOL
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2008.09
Post: #5
Frogblast Wrote:I would make sure your normal array is correct. DrawElements will crash if it reads an invalid address while iterating across your array.

As a first order test, call glDisableClientState(GL_NORMAL_ARRAY) before the call to DrawElements.

Yah. That solved the crashing problem. I am drawing a normal icosahedron so I was just using the vertex array as the normal array. This is the relevant code

glVertexPointer(3, GL_FLOAT, 0, sphere->icosVertices);
glTexCoordPointer(2, GL_FLOAT, 0, sphere->icosTextureVertices);
glNormalPointer(3 , GL_FLOAT , sphere->icosVertices);

for(int i = 0; i < sphere->numFaces ; i ++)
{ glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, &sphere->icosFaces[i*3]);
}
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2008.09
Post: #6
Not sure why it would like the vertex array for the vertices but dislike it for the normals?
Quote this message in a reply
Apprentice
Posts: 8
Joined: 2008.09
Post: #7
Awe crap. That call should be
glNormalPointer( GL_FLOAT ,0, sphere->icosVertices);
Sry. It's been 3 years or so since I've done any coding. Works now.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  my app crash, please help ! imaumac 4 2,518 Dec 19, 2008 06:16 AM
Last Post: imaumac