Hi guys, I’m trying to get a water tile in a simple tile editor to have a reflection on it using OpenGL’s stencil buffers. However I’m getting some weird behavior.
So I turn on stencil testing, render a small 1x1 tile, then render the clouds scaled(1,-1,1).
It’s reflecting the clouds I’m drawing, but it isn’t confined to within the 1x1 tile only. It looks like its showing all of the clouds, or at least a significant proportion of it.
Any help appreciated. Apologies for the code being in Java.
The whole clouds plane is 25x25.
Here’s a picture (the water like tile is the tile i placed down):
gl.glEnable(GL.GL_STENCIL_TEST);
gl.glColorMask(false, false, false, false);
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glStencilFunc(GL.GL_ALWAYS, 1, 1);
gl.glStencilOp(GL.GL_REPLACE, GL.GL_REPLACE, GL.GL_REPLACE);
gl.glPushMatrix();
gl.glTranslatef(position.x, position.y, position.z);
gl.glBegin(GL.GL_QUADS);
gl.glVertex3f(0.0f, 0.01f, 1.0f);
gl.glVertex3f(-1.0f, 0.01f, 1.0f);
gl.glVertex3f(-(1.0f, 0.01f, 0.0f);
gl.glVertex3f(0.0f, 0.01f, 0.0f);
gl.glEnd();
gl.glPopMatrix();
gl.glColorMask(true, true, true, true);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glStencilFunc(GL.GL_EQUAL, 1, 1);
gl.glStencilOp(GL.GL_KEEP, GL.GL_KEEP, GL.GL_KEEP);
gl.glPushMatrix();
gl.glScalef(1.0f, -1.0f, 1.0f);
drawClouds(gl);
gl.glPopMatrix();
gl.glDisable(GL.GL_STENCIL_TEST);
// draw the tile again