Advertisement

Lightning

Started by November 21, 2001 08:28 AM
9 comments, last by xill 23 years, 3 months ago
I have created a ''room'' (cube) with some textures on it and put a light in the upper right corner... with the mouse you can look around. The problem is that while looking around a texture i look away from becomes darker and visa versa. In a game this should really not happen! How can I prevent this? The brightness of a texture should only be infected by the distance between the light and the texture and not by the direction the ''camera'' is looking in... If you need the a little code, ill post it but maybe someone knows the awnser without any code .... well thx anyway!
I think it has something to do with light position. Look at OpenGL.org in the FAQs for lighting.
Advertisement
I don''t know how you''re doing movement/mouselook, but I think that''s where the problem may be. When you move or look around the entire world moves/rotates, but your lights don''t.

Say you push down the mouse up your viewpoint goes up. That means the world (= the little room you''re in) rotates a bit and goes down. But if the lights don''t move with the geometry, the light ends up going up trough the roof or in other directions, depending how you''re moving around.

If this is the problem, you''ll have to adjust the light position relative to the viewpoint on ever frame, just like you do with the rest of your world model.
_________"Maybe this world is another planet''s hell." -- Aldous Huxley
Thats correct indeed...

So I call glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
every frame

But its still not like it should be..

My room is sized -7 to 7 in all directions so 0,0,0 is in the middle.. when I put my light at 0,0,0 anything is fine, but when I move my light to 7, 7, 7 ( in the upper corner ) the polygons in the oposite corner are all black
and the ceiling is lit but not becoming darker :/
the result is that you have a point where 3 polygons are joining, and only one of them is lit and the other 2 are black :D very strange, cant find it in the nehe tuts well cya
Does nobody even know something about this?
well...i''m not an expert in opengl programming ( yet...''grin'' ), but first you have to enable normals in the init function ( if you haven''t already )
glEnable(GL_NORMALIZE);
in nehe''s tutorial no. 10 you have an excelent explanation of moving in 3d...
now try ( in every frame ) adding the following code:
.
.
.
LightPosition[]={-x,-y,-z};
glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
.
.
.
-x,-y,-z: negatives of the values you use to rotat/translate your scene...
the result should be a fixed light position...

follow the yellow brick road
Advertisement
Don''t be . You code shall be fine but you must post your code(in which u r drawing ur scene) as well as some screem shots of ur program. Then some one can help you better . Got me now ? Good luck & keep on trying

manni
manni
Sounds like you''re doing two things:

1. Each wall is one huge quad.

2. You''re using face normals.

Try breaking the walls into 10 quads and using vertex normals. Should look better.

Luck.
Ok, here''s the important code:


float LightDiffuse[] = {4.0f, 4.0f, 4.0f, 1.0f};
float LightPosition[] = {0.8f, 0.8f, 0.8f, 1.0f};


glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);

glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
//back
glNormal3f( 0.0f, 0.0f,-1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(4.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(4.0f, 4.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 4.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glEnd();

glBegin(GL_QUADS);
//front
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(4.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(4.0f, 4.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 4.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glEnd();

glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
//right
glNormal3f(-1.0f, 0.0f, 0.0f);
glTexCoord2f(4.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(4.0f, 4.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 4.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glEnd();

glBegin(GL_QUADS);
//left
glNormal3f( 1.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(4.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glTexCoord2f(4.0f, 4.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(0.0f, 4.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();

glBindTexture(GL_TEXTURE_2D, texture[2]);
glBegin(GL_QUADS);
//down
glNormal3f( 0.0f, 1.0f, 0.0f);
glTexCoord2f(6.0f, 6.0f); glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 6.0f); glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f);
glTexCoord2f(6.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);
glEnd();

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[3]);
glBegin(GL_QUADS);
//up
glNormal3f( 0.0f,-1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);
glEnd();

Here''s some pics, the first is one upper corner and the second is the oposite upper corner, note that the floor is also fully bright.




I hope this is better thx for your help so far!

-xill

pleassse some-one reply to this :/

This topic is closed to new replies.

Advertisement