PDA

View Full Version : light



zip7000
05-06-2002, 10:34 AM
hi,

still me http://www.opengl.org/discussion_boards/ubb/smile.gif I have a new problem. I create a light source and I would like that it stays at the same place after a translation or a rotation. Should I put glLightfv inside the display function or outside (in init function for example). If someone could show me a general structure of an openGL program(what in display, what in init,...) it would be great.

thank you for any help you can give!!

Azdo
05-06-2002, 11:42 AM
Originally posted by zip7000:
I create a light source and I would like that it stays at the same place after a translation or a rotation. Should I put glLightfv inside the display function or outside (in init function for example).


Light positions are modified by the modelview matrix, so translations and rotations affect them, as they were a simple point.

You must call glLightfv once if you aren't going to change light's properties. That is: you don't need to call glLightfv() every frame.

zip7000
05-07-2002, 12:00 PM
[QUOTE]Originally posted by Azdo:
[B] Light positions are modified by the modelview matrix, so translations and rotations affect them, as they were a simple point.

is there a way so that the translation, and rotation doesn't affect the light?

V-man
05-07-2002, 12:54 PM
glPushMatrix();
glLightfv(GL_LIGHTX, GL_POSITION, positionarray);
glPopMatrix();

glPushMatrix();
renderObject1();
glPopMatrix();

and so on.

or just keep modelview as identity.

V-man

zip7000
05-07-2002, 01:15 PM
Thank you V-man. I have another problem. I would like to apply materials property just for one object. I create a material function and I call this material function when I dra the object but all the objects are affected by the material properties. why?
here is my materials function
// materials
void materials()
{
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR, specular);
}

Furrage
05-10-2002, 07:46 AM
Any call to glMaterial*() remain in effect until glMaterial*() is called again with parameters to change what was initially changed. So either you call glMaterial*() again to recover from the change or you use glPush/Pop() to preserve the material settings after you've finished drawing the desired object. Unfortunately I can't remember the actual Push/Pop combination. Its something like glPushAttrib/glPopAttrib(GL_CURRENT_BIT).

Bob
05-10-2002, 08:26 AM
Material properties belongs to the lighting attribute group, so



glPushAttrib(GL_LIGHTING_BIT);
...
glPopAttrib();

will save the current material color, including all other lighting related stuff of course.

But, if you are unsure which attribute groupe a certain state belongs to, this will always work http://www.opengl.org/discussion_boards/ubb/biggrin.gif



glPushAttrib(GL_ALL_ATTRIB_BITS);
...
glPopAttrib();