Original Post
Hello everyone, I read the brief article about reflections with OpenGL here at gamedev.net and am trying to include this cool looking effect into my own project. My game uses 3-dimensional tiles ( 5 x 20 for now with each a size of 2 x 1 x 3 [some exceptions] ) - will adding the reflection to all those tiles decrease performance (a lot)? Is the current "draw_scene ( )" funtion correct or do I have some mistake in there that I don't know of? This function makes my game first minimize and then when I maximize it, it is really slow...
void draw_scene ( void )
{
// clear the screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// reset the matrix
glLoadIdentity ( );
// draw the user
user.draw ( );
glLoadIdentity ( );
/* Don't update color or depth. */
glDisable(GL_DEPTH_TEST);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
/* Draw 1 into the stencil buffer. */
glEnable(GL_STENCIL_TEST);
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
glStencilFunc(GL_ALWAYS, 1, 0xffffffff);
/* Now drawing the floor just tags the floor pixels
as stencil value 1. */
// draw the tiles
for ( int x = 0; x < MAP_WIDTH; x++ )
{
for ( int y = 0; y < MAP_LENGTH; y++ )
{
tile[x][y].position.x = (float) x;
tile[x][y].position.y = 0.0f;
tile[x][y].position.z = (float) y;
tile[x][y].draw ( );
}
}
/* Re-enable update of color and depth. */
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glEnable(GL_DEPTH_TEST);
/* Now, only render where stencil is set to 1. */
glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if stencil ==1 */
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
/* Draw reflected ninja, but only where floor is. */
glPushMatrix();
glScalef(1.0, -1.0, 1.0);
// draw the user
user.draw ( );
glPopMatrix();
glDisable(GL_STENCIL_TEST);
}