tags:

views:

384

answers:

1

I am learning OpenGL and just started getting into lighting. I enable lighting and light 0, set its ambient/diffuse/specular to default values in my init method, and then each frame I do something like this:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// do my 3rd-person camera transforms and rotations
glLightfv(GL_LIGHT0, GL_POSITION, {0.1f, 0.0f, 0.0f});

(note if it's slightly wrong, I'm writing my app in Java using JOGL so I trimmed the gl. and GL. from each line for better readability for all you C++ folks :) )

I then proceed to draw my triangles and such, and at the end I do a glFlush().

The odd problem is that when I run my application, the light flickers. I have no other calls to glLightfv in my whole program (other than, as mentioned above, the calls in my init method, which I have debugged to make sure it does only run once). It flickers very fast and the screen shows tearing. I also do not glDisable(GL_LIGHTING) at any point in my scene drawing; not that I think that should cause the lit objects to flicker.

I have also, for debugging purposes, commented out chunks of my drawing code, and nothing seems to be breaking the lighting - and of course, I wrote all that and tested it before lighting the scene anyway, so I see no reason it should be wrong.

Basically I know this isn't much to go by, but has anyone else had this problem before? Is there some simple solution I just can't find? Please request any additional information that could help you help me. And in the end if I simply can't get an answer, I'll probably have to break down and write a test case where I can just post the entire rendering code here and demonstrate the problem.

Here is a really bad animated gif I tried to make... But it kinda shows what I'm talking about, as far as the light being sporadic. The lit frames are what it's supposed to look like. Also it's not so much flickering when I slow it down to 5fps, more just kinda randomly on or off. I don't get it...

Thanks!!

+4  A: 

Aha! I found the answer already... I only specified 3 floats for the position, when it wants 4 as documented here. So the fourth number, which must have some affect on the light's brightness, was being read from some other random area in memory, and of course odd things happened.

Sorry to waste your time!

Ricket