I’m trying to do water reflection using a texture. I’m doing this by creating a new camera, rendering everything upside down and then binding this camera to a texture. However this is not working since the reflection positioned correctly. Here’s some relevant code:
void render_reflection(){
glViewport(0,0,512,512);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(reflect[0], -reflect[1], reflect[2], refP[0], refP[1], refP[2], 0, 1, 0);
glPushMatrix();
//glTranslatef(10.0, 0, 60);
glScalef(1.0, -1.0, 1.0);
double plane[4] = {0.0, 1.0, 0.0, 0.0};
glEnable(GL_CLIP_PLANE0);
glClipPlane(GL_CLIP_PLANE0, plane);
draw_models_for_water();
glDisable(GL_CLIP_PLANE0);
glPopMatrix();
glBindTexture(GL_TEXTURE_2D, reflection_texture);
glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,512,512);
}
void draw_water(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBindTexture(GL_TEXTURE_2D, reflection_texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0); glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0, 1.0); glVertex3f(30.0f, 0.0f, 0.0f);
glTexCoord2f(1.0, 0.0); glVertex3f(30.0f, 0.0f, 60.0f);
glTexCoord2f(0.0, 0.0); glVertex3f(0.0f, 0.0f, 60.0f);
glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0); glVertex3f(34.5f, 0.0f, 0.0f);
glTexCoord2f(1.0, 1.0); glVertex3f(64.5f, 0.0f, 0.0f);
glTexCoord2f(1.0, 0.0); glVertex3f(64.5f, 0.0f, 60.0f);
glTexCoord2f(0.0, 0.0); glVertex3f(34.5f, 0.0f, 60.0f);
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
}
An here’s a screenshot of what this produces:
https://imgur.com/ELKEtrI