Original Post
i've created the shadow volume for the model (i've implemented also silouhette determination), but i've got some problem when i try to render the shadow...i'm trying to implement the depth pass algo. this is my code: the most part of RenderScene is taken from the shadow volumes demo on codesampler.com (thank you guys!) What can i do? EDIT: thank you nife :) Here's the two screenshots: Volume Error [Edited by - b3rs3rk on March 19, 2005 5:10:52 PM]
void DrawScene()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt( 50, 90, -50.0f, 0, 0, 0, 0, 1, 0);
glBegin(GL_QUADS);
glColor3f(0.8f, 0.8f, 0.8f);
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(90.0f, 90.0f, 60.0f);
glVertex3f(-90.0f, 90.0f, 60.0f);
glVertex3f(-90.0f, -50.0f, 60.0f);
glVertex3f(90.0f, -50.0f, 60.0f);
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(90.0f, -50.0f, 60.0f);
glVertex3f(-90.0f, -50.0f, 60.0f);
glVertex3f(-90.0f, -50.0f, -60.0f);
glVertex3f(90.0f, -50.0f, -60.0f);
glEnd();
if(Rotate_Model)
g_RotateX += g_RotationSpeed;
glRotatef(g_RotateX, 0, 1.0f, 0);
g_Model.DrawModel();
glDisable( GL_LIGHTING );
glDisable(GL_TEXTURE_2D);
glPushMatrix();
glLightfv( GL_LIGHT0, GL_POSITION, lightPosition );
glTranslatef( lightPosition[0], lightPosition[1], lightPosition[2] );
glColor3f(1.0f, 1.0f, 0.5f);
glutSolidSphere( 2, 8, 8 );
glPopMatrix();
glEnable( GL_LIGHTING );
}
void RenderScene( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
DrawScene();
glEnable( GL_CULL_FACE );
glEnable( GL_STENCIL_TEST );
glDepthMask( GL_FALSE );
glStencilFunc( GL_ALWAYS, 0, 0 );
glStencilOp( GL_KEEP, GL_KEEP, GL_INCR );
glCullFace( GL_BACK );
g_Model.DrawShadows(lightPosition);
glStencilOp( GL_KEEP, GL_KEEP, GL_DECR );
glCullFace( GL_FRONT );
g_Model.DrawShadows(lightPosition);
glDepthMask( GL_TRUE );
glDepthFunc( GL_LEQUAL );
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE );
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
glCullFace( GL_BACK );
glDisable( GL_CULL_FACE );
glStencilFunc( GL_EQUAL, 1, 1 );
glDisable( GL_LIGHT0 );
DrawScene();
glStencilFunc( GL_EQUAL, 0, 1 );
glEnable( GL_LIGHT0 );
DrawScene();
glDepthFunc( GL_LESS );
glDisable( GL_STENCIL_TEST);
if( Draw_Volume ) {
// glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
g_Model.DrawShadows(lightPosition);
// glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
}
SwapBuffers( g_hDC );
}