Jump to content
  • Advertisement
Sign in to follow this  
vivekd

OpenGL Lighting problem

This topic is 4546 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've gotta deal with a problem which almost all OpenGL coders face: Lighting. I have two images. Link below refers to the one is the one which is currently being rendered: http://www.geocities.com/vivekdharm/ImgCurrent.jpg Link below refers to the one which is the desired effect, i.e the effect I wish to have for my rendering: http://www.geocities.com/vivekdharm/ImgDesired.jpg My lighting initializations go as follows: public float[] LightAmbient = {0.5f, 0.5f, 0.5f, 1.0f}; public float[] LightDiffuse = {1.0f, 1.0f, 1.0f, 1.0f}; public float[] LightSpecular = {1.0f, 1.0f, 0.0f, 1.0f}; public float[] LightPosition = {10.0f, 3.0f, 6.0f, 1.0f}; GL.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, this.LightAmbient); GL.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, this.LightDiffuse); GL.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, this.LightSpecular); GL.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, this.LightPosition); GL.glEnable(GL.GL_LIGHT1); I apply material as follows: GL.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE, mcolor); mcolor is the array of color of the material to be applied. Could anyone help me in how to achieve the desired effect?

Share this post


Link to post
Share on other sites
Advertisement
Have you enabled lighting as a whole? You appear to be creating a light, but without switching lighting on nothing is going to appear different.

If I remember my OpenGL correctly it is something like glEnable(GL_LIGHTING);

Share this post


Link to post
Share on other sites
it looks like there is something wrong with your normals, because your colors appear to be too bright. Are they correctly normalized (lenght = 1) ?

Share this post


Link to post
Share on other sites
Also, why do you use LIGHT1 instead of LIGHT0? Not that that's the problem, I just find it odd.

Share this post


Link to post
Share on other sites
Yes, I have enabled Lighting as whole. It is with this effect with which I get this result.
I am drawing series of polygone to make it appear like a cone. Do i need to specify normals to all of the polygons?

Share this post


Link to post
Share on other sites
Yes, I have enabled Lighting as whole. It is with this effect with which I get this result.
I am drawing series of polygons to make it appear like a cone. Do i need to specify normals to all of the polygons?

Share this post


Link to post
Share on other sites
Yes you must define normals for each polygon, or better (if you want a smooth surface) for each vertex. And like michaweyel said, the length of the normal should be 1.

Share this post


Link to post
Share on other sites
But for me, the surface of the cone seems to be smooth. The problem according to me lies in the diffuse light source, which I think is located in a wrong place to have a highly bright effect on the cone.

Share this post


Link to post
Share on other sites
Quote:
Original post by vivekd
But for me, the surface of the cone seems to be smooth. The problem according to me lies in the diffuse light source, which I think is located in a wrong place to have a highly bright effect on the cone.
That's possible. We can't really tell from the small amount of code you posted if that's a problem or not. What we can tell you right now though is that not having normals certainly is a problem. Proper normals are required for proper OpenGL lighting.

Share this post


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