PDA

View Full Version : Lighting makes everything white (i have normals)...



sam_14332
03-07-2003, 11:12 AM
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???

nexusone
03-07-2003, 11:37 AM
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:
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???

yaro_dup1
03-07-2003, 11:38 AM
Hi,

Did You enable GL_COLOR_MATERIAL by
glEnable(GL_COLOR_MATERIAL)
?

yaro

sam_14332
03-07-2003, 11:46 AM
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?)

sam_14332
03-07-2003, 11:47 AM
There are no textures by the way.

sam_14332
03-07-2003, 12:02 PM
The line with normal3f is: glNormal3f(pg.normal.x,pg.normal.y,pg.normal.z);

Sorry! (it doesn't work anyway)

titan
03-08-2003, 09:45 AM
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.

Demiurge
03-09-2003, 09:49 AM
Originally posted by sam_14332:
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???

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

Belgy
03-09-2003, 11:27 PM
Try enable the depth-testing

glEnable(GL_DEPTH_TEST);

Mazy
03-10-2003, 12:22 AM
The materials specular exponent might do this. try to set it to a higher value (like 40 or so)