Sign in to follow this  

incorrect lighting

This topic is 4297 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 have only one light, light0, and it's set with all the default settings (this is a 2d program). i have a textured quad that's textured fine with the correct colors, but i'm trying to draw lines and rectangles with different colors, but everything is coming out to be white... why is that? glTranslatef(m_fCenterX, m_fCenterY, 0.0f); glBegin(GL_QUADS); glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glVertex2f(m_fBase / 2.0f, m_fHeight / 2.0f); glVertex2f(-m_fBase / 2.0f, m_fHeight / 2.0f); glVertex2f(-m_fBase / 2.0f, -m_fHeight / 2.0f); glVertex2f(m_fBase / 2.0f, -m_fHeight / 2.0f); glEnd();

Share this post


Link to post
Share on other sites
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

that's it for enabling, just those two lines; i kinda assumed you knew i enabled them since i said the texture is being lit correctly. why would the texture be lit correctly, but the lines and rects, without textures, be lit fully, or just drawn, completely white?

as for using source tags, it was only what, 7 lines? .. i didn't see the need

edit: and i said was using all the defaults values for the light. which are:

Parameter Name Default Value Meaning
GL_AMBIENT (0.0, 0.0, 0.0, 1.0) ambient RGBA intensity of light
GL_DIFFUSE (1.0, 1.0, 1.0, 1.0) diffuse RGBA intensity of light
GL_SPECULAR (1.0, 1.0, 1.0, 1.0) specular RGBA intensity of light
GL_POSITION (0.0, 0.0, 1.0, 0.0) (x, y, z, w) position of light
GL_SPOT_DIRECTION (0.0, 0.0, -1.0) (x, y, z) direction of spotlight
GL_SPOT_EXPONENT 0.0 spotlight exponent
GL_SPOT_CUTOFF 180.0 spotlight cutoff angle
GL_CONSTANT_ATTENUATION 1.0 constant attenuation factor
GL_LINEAR_ATTENUATION 0.0 linear attenuation factor
GL_QUADRATIC_ATTENUATION 0.0 quadratic attenuation factor

Share this post


Link to post
Share on other sites
Once lighting is enabled, the vertex color will be ignored. Instead materials will be used.

In order to use glColor*() with lights, just enable GL_COLOR_MATERIAL, for example:
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

The above code tells to OpenGL to track the material ambient and diffuse from vertex color.

Or, respecify new material for your polygon with glMaterial*(). Note that glMaterial*() is more expensive than glColor*().

Share this post


Link to post
Share on other sites

This topic is 4297 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this