PDA

View Full Version : Problems with glPushAttrib(GL_LIGHTING_BIT)



bensch128
07-23-2002, 09:10 PM
Hi all,
I have a ATI All-In_Wonder 128 pro card with 4.13.7129 drivers (the latest ones) on Win98. I have a program that uses the stencil buffer to mirror a torus through a plane. (finally figured out the affine transformation for it too, yes!!) The stencil works fine. The problem is that I want to transform the light so the lighting looks correct on the mirrored object. I use a spotlight with a position and direction. So my code for drawing the mirrored object looks like this:

// Render the mirrored object
glPushMatrix();
{
// This does the affine transform for // mirroring everything
mirrorPlane(plane);

// reposition the light
// since the shading has to look like it's
// correct glPushAttrib(GL_LIGHTING_BIT);
{
// Position the light glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
#if SPOTLIGHT MATHLIB::V3 lightDir(lightPos);
lightDir *= -1.0f;
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDir.xyz);
#endif

glRotatef(rotateCube, 0.0f, 1.0f, 0.0f);
glRotatef(30.0f, 0.0f, 1.0f, 0.0f); glutSolidTorus(0.275f, 0.725f, 16, 16);
} glPopAttrib();
}
glPopMatrix();

Then I render the real torus:

// Render the cube
glColor4f(cColor[0], cColor[1], cColor[2], 1.0f);
glPushMatrix();
{
glPushAttrib(GL_LIGHTING_BIT);
{
// Position the light // glLightfv(GL_LIGHT0, GL_POSITION, // lightPos);
#if SPOTLIGHT
// This is a problem, double check!
// Doesn't seem to set the light direction correctly.
// NOTE: Send this to opengl forum and
// ask people what they think
MATHLIB::V3 lightDir(lightPos);
lightDir *= -1.0f;
// glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, lightDir.xyz);
glGetLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, tempDir);
printf("After real change: Light Direction = (%0.3f, %0.3f, %0.3f)\n", tempDir[0], tempDir[1], tempDir[2]);

#endif
glRotatef(rotateCube, 0.0f, 1.0f, 0.0f);
glRotatef(30.0f, 0.0f, 1.0f, 0.0f);
glutSolidTorus(0.275f, 0.725f, 16, 16);
} glPopAttrib();
}
glPopMatrix();

I have to manually set the direction of the light before rendering the real torus, otherwise it isn't lit correctly.
Checking using glGetLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, ...) says that the direction is correct but it doesn't render correctly.
Has anyone else incountered this problem on the ATI drivers? SHould I email ATI about this?

THanks!!
Ben Schleimer

Dan82181
07-24-2002, 06:07 AM
First thing I would try would be to set LIGHT0 as the light for your object at it normally is, and set LIGHT1 as the light for your reflected tourus. Then you can just enable and disable each light as needed (or set lighting colors to {0,0,0} if you are worried about expensive state changes). Try this out and see if you get what you're looking for.

Dan

Dan82181
07-24-2002, 08:16 AM
Also, readup on the glLight?v functions. GL_POSITION is multiplied by the current modelview matrix when glLight?v is called. GL_SPOT_DIRECTION is multiplied by the current inverse-modelview matrix when glLight?v is called.

Dan

bensch128
07-24-2002, 09:23 AM
Hi,
Well, enabling light1 and disabling light0 worked however....

glEnable(RANT_BIT)
I think that the lights direction is not correctly pop off the attribute stack.
There's no way to tell (besides ask ati to verify) so forget about it.
glDisable(RANT_BIT)

Thanks!
Ben

Dan82181
07-24-2002, 03:26 PM
Well, looking at the glPushAttrib() spec...

GL_LIGHTING_BIT GL_COLOR_MATERIAL enable bit
GL_COLOR_MATERIAL_FACE value
Color material parameters that are tracking the current color
Ambient scene color
GL_LIGHT_MODEL_LOCAL_VIEWER value
GL_LIGHT_MODEL_TWO_SIDE setting
GL_LIGHTING enable bit
Enable bit for each light
Ambient, diffuse, and specular intensity for each light
Direction, position, exponent, and cutoff angle for each light
Constant, linear, and quadratic attenuation factors for each light
Ambient, diffuse, specular, and emissive color for each material
Ambient, diffuse, and specular color indices for each material
Specular exponent for each material
GL_SHADE_MODEL setting


direction is listed, so it should be pushed and popped.

Drop a line to devrel@ati.com and let them know.

Dan

bensch128
07-24-2002, 09:40 PM
Well, I checked with glGetLightfv and IT says that the direction is being pushed and popped correctly BUT it renders as if the Direction doesn't get popped.

I'll contact Jeff at ati again. sigh!!

Ben Schleimer