PDA

View Full Version : colour and lighting problem



fox
02-01-2002, 08:51 AM
Hi

I'm having problems with colour and lighting - red doesn't seem to display and also when rotating the scene - part of it seem to get dimmer than other parts - this seems to be related to the parameter in diffuselight - below is some code - any ideas?


//in InitOpenGl


GLfloat LightAmbient[] = {0.5f, 0.5f, 0.5f, 0.5f}; //Ambient light values
GLfloat LightDiffuse[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Diffuse light values
// x y z
GLfloat LightPosition[]= {0.0f, 0.0f, 10.0f, 1.0}; //Light position

if(!object.LoadGLTextures())
{
return FALSE;
}

glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient); //Setup the Ambient light
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse); //Setup the Diffuse light
glLightfv(GL_LIGHT0, GL_POSITION, LightPosition); // Position the Light
glEnable(GL_TEXTURE_2D); //Enable texture mapping
glEnable(GL_POLYGON_SMOOTH);
glShadeModel(GL_SMOOTH); //Enable smooth shading
glEnable(GL_LINE_SMOOTH); //makes grids on floor look smooth
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Black background
glClearDepth(1.0f); //Depth buffer setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); //Nice perspective calculations

glEnable(GL_LIGHT0); //brightens the scene
glEnable(GL_LIGHTING);

In onPaint()
problem of colour appearing brighter and then dimmer

glPushMatrix();
glEnable(GL_BLEND);
glDisable(GL_LIGHTING);
glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
glBlendFunc(GL_ONE, GL_ONE);
object.DrawFloor();
glEnable(GL_LIGHTING);
glDisable(GL_BLEND);
glPopMatrix();

cheers

Furrage
02-01-2002, 11:37 AM
I am no lighting guru but you specified your light source as a point and not directional. This means the intensity will fade as the distance increases, hence you red getting darker as it is rotated away from the light. If this is deliberate then you're getting the correct effect, otherwise change

GLfloat LightPosition[]= {0.0f, 0.0f, 10.0f, 1.0}; //Light position

to

GLfloat LightPosition[]= {0.0f, 0.0f, 10.0f, 0.0}; //Light position

Bob
02-01-2002, 12:19 PM
A point light will only fade if you set the attenuation factors (GL_LINEAR_ATTENUATION and GL_LINEAR_ATTENUATION) to non-zero. By default, these parameters are zero, which is the same as no attenuation.