Advertisement Jump to content


This topic is now archived and is closed to further replies.


Directional light in OGL vs D3D

This topic is 6395 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post

Link to post
Share on other sites
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

As far as I know is OpenGL and D3D lights identical.

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!