This may be more like a general OpenGL question, but I'm really struggling with this one...
I am trying to get per-pixel dynamic lights working in my JOGL app (an extremely young game engine), using multiple passes to draw each light and blend them together. From what I know, the basic idea is to render ambient light in an initial pass, and then add the diffuse lighting components in the next passes, one for each light.
It also seems like a good idea to write the z-buffer in only the first pass, to save time in the later ones. However, this doesn't seem to be working in my code.
I initialize OpenGL like this:
And my rendering code looks like this:
With this code, I get strange artifacts that I thought at first were due to z-fighting, because if I set glDepthMask(true) for the diffuse passes, the artifacts disappear. But polygons aren't appearing over others, sections of my rendered model are just disappearing. Right now I'm testing with only one light.
Each pass is working fine on its own, I've tried commenting out one or the other and looking at the results.
Is there anything wrong with my code? I don't think the problem in is the shaders, but I can post their code too if it would be helpful. I can also try to upload some screenshots of the artifacts.
Windows Vista Business 64-bit
nVidida GeForce 8800 GTS 640MB with 175.19 drivers
JDK/JRE 1.6.0 update 4