View Full Version : Lighting Problem

04-20-2009, 04:37 PM
Hi. I can't seem to get my scene's lighting to work. I have enabled lighting with glEnable(GL_LIGHTING); .. and i think i have put in proper settings for light zero and done glEnable(GL_LIGHT0); Also tried glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Setting); with high values to see if it has any effect. But none.. what could I be doing wrong?

Here is the code:

void SetLighting(void)
GLfloat LightAmbient[]= { 0.4f, 0.4f, 0.4f, 1.0f };
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
GLfloat Pos0[]= { 0.0f, 0.0f, 0.0f};
glLightfv(GL_LIGHT0, GL_POSITION, Pos0);
float Setting[4] = {0.5f, 0.5f, 0.5f, 1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Setting);


04-20-2009, 08:22 PM
Hi Blain,

Can you try this:

GLfloat Pos0[]= { 0.0f, 0.0f, 0.0f, 1.0f};

Essentially we're sending in an additional value to the position vector besides the x,y,z position.

The 4th value we send indicates that we want the light to be a "Positional" light as opposed to a "directional" light.

I hope that works.

ps: you might want to change your ambient settings to something like:

GLfloat LightAmbient[]= { 0.4f, 0.0f, 0.0f, 1.0f };

Then if you get a reddish tint, you'll know for sure you lighting condition is working. :)

04-21-2009, 06:04 AM
And don't forget glNormal!