I am attempting to render a "reflection" of a scene for water:

enter image description here

To create this illusion, I need to render the scene from below, and then ignore all geometry below the water line.

enter image description here

As such, I need to move the camera below the water, and invert the pitch.

I have one problem: My entire framework is based on the fixed-function pipeline. Basically, I need to call the correct glTranslatef() calls and glRotatef() calls to be able to simulate the camera being in the new position, and then render the scene.

Unfortunately, I have so far failed to achieve this. Calling the glRotatef() function obviously just rotates the entire scene, so I am struggling to just simulate the camera rotation.

The water is at a height of 300. I believe I may be moving the camera down correctly by calling glTranslatef(0, -(2 * (camera.y() - 300))), but it has been impossible for me to get them to both work.


I am not sure if this will be helpful for you but there is a really simple way how to achieve a reflection in water.

Using fixed pipeline all you need is to make water transparent (using GL_BLEND) and then render the scene upside down (using glScale(1,-1,1)). To prevent rendering objects above the water you can use glClipPlane.

For example:

glScalef(1,-1,1); //everything is now rendered upside down
double plane[4] = {0.0, 1.0, 0.0, 0.0}; //water at y=0
glClipPlane(GL_CLIP_PLANE0, plane); //preventing rendering objects above the water
RenderSceneAgain(); //renders scene once again
glScalef(1,-1,1); //everything is now rendered normally again

Its really one of the simplest way to achieve reflections and because you have to render your scene twice you can expect performance drop.

| improve this answer | |
  • \$\begingroup\$ I really like the idea of rendering everything upside down, but unfortunately that just isn't the case. I'm above the terrain still, because scaling the object simply moves the coordinates lower rather than actually flipping the object. \$\endgroup\$ – joehot200 Nov 21 '15 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.