Jump to content
  • Advertisement
Sign in to follow this  
karx11erx

OpenGL Need help with light calculation - I'm too stupid :(

This topic is 4376 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

I am trying to emulate OpenGL hardware vertex lighting in C. This is my code:
//lightColor holds the RGB light color
lightColor = <RGB light color>;
//lightPos holds the light pos in eye space (translated & rotated)
lightPos = <xyz light position>;
//vertNorm holds the vertex normal in eye space (rotated)
vertNorm = <xyz vertex normal>;
NdotL = Dot (vertNorm, Normalize (lightPos));
if (NdotL < 0.0)
	NdotL = 0.0;
// matAmbient, matDiffuse are ambient and diffuse material colors
vertColor = lightColor * (matDiffuse * NdotL + matAmbient);



Depending on where the viewer faces, there is no light, or the light at wrong positions. Looks like I am just too dang stupid to figure the bloody 3D math needed for this. Oh yeah, the application does its own translation and rotation, the OpenGL matrices are all set to identity. Where did I go wrong please? How does the correct code have to look like?

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!