PDA

View Full Version : Render to texture



^DaNiEl^
06-09-2003, 01:05 PM
I've made a reflective water with the render to texture technique but i've got a problem:
when the camera moves also the cube rendered into the water texture moves. Why happen this?

Here's the code:

void RenderToWaterTexture ( void )
{
double Clip[] = { 0, 1, 0, 0 };

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glViewport( 0, 0, 512, 512 );

glMatrixMode( GL_TEXTURE );
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
glScalef( 1, -1, 1 );

glEnable( GL_CLIP_PLANE0 );
glClipPlane( GL_CLIP_PLANE0, Clip );
DrawCube( 2, 0.0, 5.0, 0.0, 5.0, 5.0, 5.0, 1.0, 1.0 );
glDisable( GL_CLIP_PLANE0 );

glBindTexture( GL_TEXTURE_2D, texture[0] );
glCopyTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 512, 512, 0 );

glViewport( 0, 0, 800, 600 );
}

int DrawGLScene ( void )
{
RenderToWaterTexture();

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();

camera.Look();

glMatrixMode( GL_TEXTURE );
glPushMatrix();
glLoadIdentity();
glMatrixMode( GL_MODELVIEW );
DrawCube( 2, 0.0, 5.0, 0.0, 5.0, 5.0, 5.0, 1.0, 1.0 );
glMatrixMode( GL_TEXTURE );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );

glDepthMask( GL_FALSE );

DrawWater();

glDepthMask( GL_TRUE );

return TRUE;
}

dawn
06-10-2003, 05:33 AM
Maybe you need to reset the modelview matrix when you render the "water-texture" ?