Jump to content
  • Advertisement
Sign in to follow this  
STORM76

OpenGL Render a cone with correct normals for lighting

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

Hi there, I want to render a cone primitive with correct normals set for OpenGL lighting. Please take a look at my render code: void RenderCone(int steps, float height) { float unit = (2 * (float)MathTools::Pi()) / steps; Matrix4x4f m; Vector3f oldV; glBegin(GL_TRIANGLE_FAN); Vector3f n = Vector3f(0.0f, height, 0.0f); glNormal3fv(n.UnitVector().v); glVertex3f(0.0f, height, 0.0f); for (int i = 0; i < steps + 1; ++i) { m.LoadIdentity(); m.SetRotationY((float)MathTools::Rad2Deg(i * unit)); Vector3f v = Vector3f(0, 0, 1) * m; if (i > 0) { Vector3f n = CalcNormal( Vector3f(0.0f, height, 0.0f), Vector3f(v), Vector3f(oldV)); glNormal3fv(n.v); } glVertex3f(v.x, 0.0f, v.z); oldV = v; } glEnd(); } The problem is that lighting on the first and last triangle is incorrect. Is there something wrong with my code? The normals I use are face normals. How can I supply vertex normals for smooth lighting? Greetings, Guido

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!