Directional light in OGL vs D3D

Started by
1 comment, last by stefu 22 years, 9 months ago
Finally I got my OpenGL lighting to work somehow in my GFX wrapper (supports OGL and D3D). This is fun: In OpenGL I must set light direction to point opposite direction than in D3D. Why? I can do it so but it bothers me if I don''t know why. In D3D I do all right, there''s no question about it I think the OpenGL lighting system is a bit of mystery. The light must be set every frame after view matrix is set by camera to make light fixed in scene.
Advertisement
The Z axis is pointing in the opposite direction in OpenGL than the D3D default. This could explain why you have set the light in the "opposite" direction.

The light position is transformed by the contents of the current top of the ModelView matrix stack when you specify the light position with a call to glLightfv(GL_LIGHT_POSITION,…). You may or may not have to set the light position each frame depending on what you want the light be fixed to.
The OpenGL FAQ has a good discussion about this
http://www.frii.com/~martz/oglfaq/lights.htm#ligh0050

As far as I know is OpenGL and D3D lights identical.
This is one I never understood. They say that OGL uses right-handed and D3D left-handed coord system. For OGL it is true, but I use right-handed coord system also in D3D. So Z -axis points towards me out of the monitor in both APIs. and X goes right and y up. In D3DX there are functions for bot LH and RH and I never had to change any vertex or normal data before so I don''t think that''s the problem.

If the Z was pointing opposite direction, I think it should be enought to change z-value of direction vector. (?) But I have to multiply (x,y,z) by -1.

This topic is closed to new replies.

Advertisement