Original Post
I have a problem..again. This time with projective shadows.
The problem is that my shadow just doesn't look like a shadow but rather than a black 3d cube. Also, if I move camera around (with gluLookAt) shadow changes position.
I am almost sure that the problem occurs because of wrong-placed glPushMatrix/glPopMatrix functions. Yet, I don't know what exactly is wrong.
Please help.
Here is the code which draws a plain (floor):
// draw floor
void str_Render::rSurface (const float pos [3], const float size [3], const float rot [3], float deg)
{
glBindTexture (GL_TEXTURE_2D, floor_tex->Tex);
glPushMatrix ();
glTranslatef (pos [0], pos [1], pos [2]);
glRotatef (deg, rot [0], rot [1], rot [2]);
glScalef (size [0], size [1], size [2]);
// draw....
glPopMatrix ();
}
The next code draws shadow-casting cube - notice the "shadow" parameter (if set to true later -> glMultMatrixf()):
///// rObject () /////
void str_Render::rObject (const float pos [3], const float size [3], float rot [3], float deg, bool shadow)
{
glBindTexture (GL_TEXTURE_2D, obj_tex->Tex);
glPushMatrix ();
if (shadow)
{
glMultMatrixf (shd_matrix);
}
glTranslatef (pos [0], pos [1], pos [2]);
glRotatef (deg, rot [0], rot [1], rot [2]);
glScalef (size [0], size [1], size [2]);
glBegin (GL_TRIANGLE_STRIP);
...// draw
glPopMatrix ();
}
And finally, function that displays scene:
///// fncRender () Function /////
void fncRender ()
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glLoadIdentity ();
gluLookAt (x_p, y_p, z_p, x_l, y_l, z_l, 0.0f, 1.0f, 0.0f);
fncGetInput (); // irrelevant here
glEnable (GL_STENCIL_TEST);
glStencilFunc (GL_ALWAYS, 1, 1);
glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE);
glColorMask (0, 0, 0, 0);
glDepthMask (0);
// specify drawing area
Render.rSurface (floor_pos, floor_size, floor_rot, 90.0f);
glColorMask (1, 1, 1, 1);
glDepthMask (1);
glStencilFunc (GL_EQUAL, 1, 1);
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
// draw "real" floor
Render.rSurface (floor_pos, floor_size, floor_rot, 90.0f);
glStencilOp (GL_KEEP, GL_KEEP, GL_INCR);
glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable (GL_DEPTH_TEST);
glDisable (GL_TEXTURE_2D);
glColor4f (0.0f, 0.0f, 0.0f, 0.5f);
// draw shadow - because the last parameter is set to true, glMultMatrixf () is called
Render.rObject (cube_pos, cube_size, cube_rot, cube_degrot, true);
glColor3f (1.0f, 1.0f, 1.0f);
glDisable (GL_BLEND);
glEnable (GL_DEPTH_TEST);
glEnable (GL_TEXTURE_2D);
glDisable (GL_STENCIL_TEST);
// draw rotatin cube
Render.rObject (cube_pos, cube_size, cube_rot, cube_degrot, false);
}
[edited by - Wingman on August 7, 2003 12:41:20 PM]