OpenGL: Lighting Crash

Hi guys,

Tempted to post this over on the GL forums but I thought it'd be worth a crack over here.

Have any of you GL programmers had a problem with GL_LIGHT0? I get a runtime crash when I enable it.

1
2
3
4
5
6
7
8
  // Set up perspective projection
  glMatrixMode( GL_PROJECTION );
  glLoadIdentity();
  gluPerspective( 30.f, 1.6f, 0.1f, 50.f );

  // Lighting
  glEnable( GL_LIGHTING );
  glEnable( GL_LIGHT0 );  // Causing crash... 


Granted, I'm just setting up the lighting and I haven't given the models normal data yet. That said, I'd expect the models to be fine with that; they'd just be black.

I've also enabled the GL_NORMAL_ARRAY client state. Haven't initialised the normal pointer yet, though. Again, I'd expect this to be fine and I'd have unlit models. Could be the cause of the problem, I guess.

One other thing. If I omit that line (the GL_LIGHT0 one, that is), my models are black, as I'd expect. And I can enable any of the other seven lights just fine.
Last edited on
closed account (zb0S216C)
Someone already asked this question on SO: http://stackoverflow.com/a/13910634

Wazzak
Haven't initialised the normal pointer yet, though. Again, I'd expect this to be fine and I'd have unlit models. Could be the cause of the problem, I guess.

Yeah, that's probably the problem. You should send valid normals and see if that corrects the problem.

EDIT: It's very likely the problem (see link above)

One other thing. If I omit that line (the GL_LIGHT0 one, that is), my models are black, as I'd expect. And I can enable any of the other seven lights just fine.

GL_LIGHT0 is unique in that its diffuse component has a default white color. The other lights default to black. That could explain the different behaviour you have with the other lights.
Last edited on
Thanks guys.

I'll check this out tomorrow and mark as solved if it's sorted.
Just wanted to let you know that you were right guys. :-)

Only other issue was getting the vectors the wrong way around when calculating the cross products for my normals. All good now, though. :-)

http://s4.postimage.org/kykjrtqyl/basic_shaded_terrain.png

Note: Final terrain won't actually look like that - it's just a randomised height at the moment as I haven't implemented the correct algorithm yet. The idea was to build the renderer from the ground up first.

Cheers.
Last edited on
Topic archived. No new replies allowed.