Lighting makes everything white (i have normals)...

Hello

I’m a beginner who are in DESPERATE need of help, I’ve made a 3d-world wich worked exellent until I try to put on some lighting. Now all objects are white. I have normals for all verteces etc. Whats wrong???

I have not a clue, how about posting some of your code.

Have you set the material settings for the object?

Originally posted by sam_14332:
[b]Hello

I’m a beginner who are in DESPERATE need of help, I’ve made a 3d-world wich worked exellent until I try to put on some lighting. Now all objects are white. I have normals for all verteces etc. Whats wrong???[/b]

Hi,

Did You enable GL_COLOR_MATERIAL by
glEnable(GL_COLOR_MATERIAL)
?

yaro

Here we go…


void draw(Objects o){
int i,j;
GLfloat reflection[4];
GLfloat test[3];
Polygon pg;
for(j=0;j<o.size;j++)
{
pg =obs.p[j];
glBegin(GL_POLYGON);
reflection[0]=pg.r;reflection[1]=pg.g;reflection[2]=pg.b;reflection[3]=1;
glNormal3f(pg.r,pg.g,pg.b);
glMaterialfv(GL_FRONT,GL_DIFFUSE,reflection);
glMaterialfv(GL_FRONT,GL_SPECULAR,reflection);
for(i=0;i<pg.horn;i++)
{
glVertex3f(pg.p[i].x,pg.p[i].y,pg.p[i].z);
}
glEnd();
}
}

void display(void)
{
glClearColor(0.4,0.6,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(posX,posY,posZ,posX+vZ.x,posY+vZ.y,posZ+vZ.z,vY.x,vY.y,vY.z);
glPushMatrix();
glTranslatef(11.5,6.5,1.5);
glRotatef(vinkel,0,1,0);
drawRPoly();
glPopMatrix();
obs.size–;
draw(obs);
obs.size++;
glutSwapBuffers();
}

void init(){
GLfloat specular[] = {1,0,0,1};
glPolygonMode(GL_FRONT, GL_FILL);
glLightfv(GL_LIGHT0,GL_DIFFUSE,specular);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glLightfv(GL_LIGHT0,GL_SPECULAR,specular);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

(Some parts is maybe not so easy to understand, because it’s just a part of the code)

The normals seems to be ok, they are the normals for each polygon (isn’t that the correct way?)

There are no textures by the way.

The line with normal3f is: glNormal3f(pg.normal.x,pg.normal.y,pg.normal.z);

Sorry! (it doesn’t work anyway)

What is your scene ambient set to? Try ensuring your material reflects no ambient and has no emissive properties just to make sure these aren’t washing out your scene.

Originally posted by sam_14332:
[b]Hello

I’m a beginner who are in DESPERATE need of help, I’ve made a 3d-world wich worked exellent until I try to put on some lighting. Now all objects are white. I have normals for all verteces etc. Whats wrong???[/b]

reflection[0]=pg.r;reflection[1]=pg.g;reflection[2]=pg.b;reflection[3]=1;

What are the values for pg.r, pg.g, etc.?

If they’re all 1 then I know what your problem is. I ran into this a few days ago.

When you add lighting, the pixel colours of your objects don’t matter anymore. Instead, the material properties determine what colour of light will reflect off of the object, and hence, what colour the object will be.

Does this answer your question, or is it something you already knew?

–Jonathan

Try enable the depth-testing

glEnable(GL_DEPTH_TEST);

The materials specular exponent might do this. try to set it to a higher value (like 40 or so)