void CLIGHT::LightOn(GLenum light, float red, float green, float blue)
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
GLfloat LightAmbient[] = {0.62f, 0.6f, 0.6f, 1.0f};
GLfloat LightDiffuse[] = {red, green, blue, 1.0f};
GLfloat LightPosition[] = {x, y, z, 1.0f};
glLightf(light,GL_CONSTANT_ATTENUATION,0);
glLightf(light,GL_LINEAR_ATTENUATION,1.0f / 10.0f);
glLightf(light,GL_QUADRATIC_ATTENUATION,0);
glEnable(GL_LIGHTING);
glEnable(light);
glPopMatrix();
}
Lighting
Hi,
I am having problems getting my scene to show lights properly. Basically I have a single light in part of my scene and various models moving around the scene but the models appear to change in brightness dependent on where I am viewing them from rather than what the light is shining on. For example,if I draw a sphere model and the light is placed in front of the sphere, then theoretically, the back of the sphere should be dark and should not change in brightness/darkness, depending on where I am viewing the sphere from but instead if I view the back, that then becomes light and the area that was previously lit, is now dark, which totally goes against what the light is shining on.
This is my lighting class:
Remember that OpenGL lights are transformed by the modelview matrix. You probably have the calls to your light in the wrong place, and/or you are pushing and popping the matrix in the wrong places; to clarify, what do you want to have?
a) A light position that remains fixed
b) A light that moves around a stationary object
c) A light that moves along with the viewpoint
If you have access to the Red Book, look up Chapter 6, section 'Controlling a Light's Position and Direction'. In fact here's a link: http://fly.cc.fer.hr/~unreal/theredbook/chapter06.html
[edit] added link
HTH,
[edited by - eSCHEn on December 26, 2003 10:38:19 PM]
a) A light position that remains fixed
b) A light that moves around a stationary object
c) A light that moves along with the viewpoint
If you have access to the Red Book, look up Chapter 6, section 'Controlling a Light's Position and Direction'. In fact here's a link: http://fly.cc.fer.hr/~unreal/theredbook/chapter06.html
[edit] added link
HTH,
[edited by - eSCHEn on December 26, 2003 10:38:19 PM]
--
Cheers,
Darren Clark
Cheers,
Darren Clark
I echo eschen''s questions, it looks from the code that you want the light to move with the "eye". Are you forgetting to set the light''s direction maybe? You need to send the 3 components of a normalized vector to GL_SPOT_DIRECTION, as this is the light''s direction whether it''s a spotlight or not.
Actually, since you set the 4th parameter of GL_LIGHT_POSITION to 1.0, it *is* a spotlight, and you also need to set the GL_SPOT_CUTOFF parameter.
Do you have access to MFC? If so, I have an MFC Modelling tool I''m working on that demonstrates all aspects of lighting. The rectangular prism piece isn''t working but you can render spheres and cylinders and shine lights at them and experiment with all of the different parameters.
Hope this helps.
Love means nothing to a tennis player
Actually, since you set the 4th parameter of GL_LIGHT_POSITION to 1.0, it *is* a spotlight, and you also need to set the GL_SPOT_CUTOFF parameter.
Do you have access to MFC? If so, I have an MFC Modelling tool I''m working on that demonstrates all aspects of lighting. The rectangular prism piece isn''t working but you can render spheres and cylinders and shine lights at them and experiment with all of the different parameters.
Hope this helps.
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
Love means nothing to a tennis player
My nothing-to-write-home-about OpenGL webpage. (please pardon the popups!)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement