Advertisement

Lighting problems

Started by May 31, 2000 03:03 AM
6 comments, last by Magallo 24 years, 5 months ago
I have a big problem with lighting. I had a cube (it is not exactly a cube, it''s a sort of cube but it''s longer than wide, in italian I call it a "parallelepipedo" I don''t know the english translation) that would represent a corridor in witch the camera is in. In practice it should simulate a room in witch a person is in. In my DrawGLScene the code is this. int DrawGLScene() { glClear(GL_COLOR_BUFFER_BIT / GL_DEPTH_BUFFER_BIT); glLoadIdentity(); //draw around the origin 0,0,0 glBegin(GL_TRIANGLES); //pavement glNormal3f(0.0f, 1.0f, 0.0f); glVertex3f(-2.0f, -2.0f, -50.0f); glVertex3f(-2.0f, -2.0f, 50.0f); glVertex3f( 2.0f, -2.0f, 50.0f); glNormal3f(0.0f, 1.0f, 0.0f); glVertex3f(-2.0f, -2.0f, -50.0f); glVertex3f( 2.0f, -2.0f, 50.0f); glVertex3f( 2.0f, -2.0f, -50.0f); //ceiling glNormal3f(0.0f, -1.0f, 0.0f); glVertex3f(-2.0f, 2.0f, 50.0f); glVertex3f(-2.0f, 2.0f, -50.0f); glVertex3f( 2.0f, 2.0f, -50.0f); glNormal3f(0.0f, -1.0f, 0.0f); glVertex3f(-2.0f, 2.0f, 50.0f); glVertex3f( 2.0f, 2.0f, -50.0f); glVertex3f( 2.0f, 2.0f, 50.0f); //left side wall glNormal3f(1.0f, 0.0f, 0.0f); glVertex3f(-2.0f, 2.0f, 50.0f); glVertex3f(-2.0f, -2.0f, 50.0f); glVertex3f(-2.0f, -2.0f, -50.0f); glNormal3f(1.0f, 0.0f, 0.0f); glVertex3f(-2.0f, 2.0f, 50.0f); glVertex3f(-2.0f, -2.0f, -50.0f); glVertex3f(-2.0f, 2.0f, -50.0f); //right side wall glNormal3f(-1.0f, 0.0f, 0.0f); glVertex3f(2.0f, 2.0f, -50.0f); glVertex3f(2.0f, -2.0f, -50.0f); glVertex3f(2.0f, -2.0f, 50.0f); glNormal3f(-1.0f, 0.0f, 0.0f); glVertex3f(2.0f, 2.0f, -50.0f); glVertex3f(2.0f, -2.0f, 50.0f); glVertex3f(2.0f, 2.0f, 50.0f); //front wall glNormal3f(0.0f, 0.0f, -1.0f); glVertex3f( 2.0f, 2.0f, 50.0f); glVertex3f( 2.0f, -2.0f, 50.0f); glVertex3f(-2.0f, -2.0f, 50.0f); glNormal3f(0.0f, 0.0f, -1.0f); glVertex3f( 2.0f, 2.0f, 50.0f); glVertex3f(-2.0f, -2.0f, 50.0f); glVertex3f(-2.0f, 2.0f, 50.0f); //back wall glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(-2.0f, 2.0f, -50.0f); glVertex3f(-2.0f, -2.0f, -50.0f); glVertex3f( 2.0f, -2.0f, -50.0f); glNormal3f(0.0f, 0.0f, 1.0f); glVertex3f(-2.0f, 2.0f, -50.0f); glVertex3f( 2.0f, -2.0f, -50.0f); glVertex3f(2.0f, 2.0f, -50.0f); glEnd(); return 1; } I wrote only the drawing of the "room" without writing all the stuff about the camera and so on. Anyway the problem is this: If I don''t use lighting, all is perfect, my room appear exacly how I want and I can move myself inside it without problems. But when I start to enable lighting all my surfaces magically disappear and only the pavement is still viewable. Only if I move the camera outside the cube and far enought to see it entirely I can see it correctly. What is the problem ? Please help, I''m desperate!!!
Hi,

At first sight, your drawing code is ok . May be it''s due to your light position or something like that. Can you show us your lighting code?

lunasol
Advertisement
Thank for your support

Sure, the lighting code is the following:

float Ambient[] = {0.6f, 0.6f, 0.6f, 1.0f};
float Diffuse[] = {1.0f, 0.0f, 0.0f, 1.0f};
float LightPos[] = {0.0f, 0.0f, 20.0f, 1.0f};

glLightfv(GL_LIGHT0, GL_AMBIENT, Ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, Diffuse);
glLightfv(GL_LIGHT0, GL_POSITION, LightPos);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);


This code is on the InitGL funcions.

Maybe do I put it in the DrawGLScene or maybe thare is something that I forgot ?

your light position has o hieght! ist on/inm the floor try this as light pos

float LightPos[] = {0.0f, 1.5f, 20.0f, 1.0f};

can try 32 to put it right on the celing but make sure u got some height. dont think you need the 4th argument either

~prevail by daring to fail~
i think there is a problem also with your orientation of front facing polygon : the basement and the left side are counter clock wise(CCW) and all the other have a clock wise orientation (CW)

triangle of the basement (CCW):
0
/\
/ \
/ \
1___2

triangle of the ceiling (CW):

0
/\
/ \
/ \
2___1


if you have enable GL_CULL_FACE (do not draw inside of polygon) you may have problem with CW polygon.
one way is to put the line "glFrontFace(GL_CW);":

//basement
...

glFrontFace(GL_CW);
//ceiling
glNormal3f(0.0f, -1.0f, 0.0f);
...


....or redraw all the triangles with CCW !

i hope this tips can help you to solve your problem...



lunasol
It''s not true that I specified some trianlges in CW order but they are all in CCW order.

In fact, if I run the program without lighting, when I am inside the room, all the walls are visible and then, when I walk out, one or more walls disappear (it depends where I go, for example if I move on the right, the right wall disappears and I can see the inside of the room).

Whe you specify the widing order you have to enter inside the cube and not to stay out of it, so you think that the widing order is CW. It would have been CW if I wanted to draw a cube and see it from outside, but considering that I am inside the cube and I want to see the internal face of it, I have to specify the widing just like I''ve done. I''m sure about it, it is right. The problem is that if I enable lighting, all walls disappear (except for the pavement) then if I disable lighting, all is ok.

I tried the program on many computers and I saw that on a P166MMX with a S3 Virge 2MB it is ok. Then I send the exe to Nehe and he told me that in his computer works well. Only on my PC PIII 550 with a Matrox G400 it doesn''t work correctly. Maybe a driver problem ? I don''t think so, maybe there''s sometihng mysterious to find out....

Advertisement
Ooops, sorry for this stupid answer... i hope you didn''t lose your time with verifying your orientation...

confused lunasol


Don''t worry about it French friend,
I thanks you for your support anyway, all kind of suggestion is useful for me, also if they are not correct. In fact I spent a bit of time to understand it well so it''s easy to be confused. Anyway I still have the same problem. Just yesterday I updated my code to use per-vertex normals instead of face normals, I''ll try to use them to see if the problem persits. The strange thing is that on others computer it works correctly but I think it''s impossible that it''s my video card''s fault (G400).

Anyway I''ll try again....

This topic is closed to new replies.

Advertisement