Lighting problem
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?
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);
If I remember my OpenGL correctly it is something like glEnable(GL_LIGHTING);
it looks like there is something wrong with your normals, because your colors appear to be too bright. Are they correctly normalized (lenght = 1) ?
Also, why do you use LIGHT1 instead of LIGHT0? Not that that's the problem, I just find it odd.
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?
I am drawing series of polygone to make it appear like a cone. Do i need to specify normals to all of the polygons?
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?
I am drawing series of polygons to make it appear like a cone. Do i need to specify normals to all of the polygons?
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.
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.
Quote:Original post by vivekdThat'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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement