Hi,
I am trying to use the stencil buffer so that the reflections are only drawn where the floor is. However, this is not working. I do get a reflection in the floor, but the reflected objects are still visible below the floor. I am rendering a chess scene and the floor in this case is the chess board and I am reflecting the chess pieces into the board. I’ve included some of my code below. It is in python but it makes the same OpenGL calls as a C application would. The init() function initializes the clipping planes and the drawScene() function renders the scene. I looked at four different ways of doing this. They all use the stencil buffer but they do it slightly differently. The last tutorial I used was http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=26.
Any suggestions would be appreciated!
Thanks,
Tom
def init(self, parent=None, name=None):
…
self.boardPlaneUnder = (0.0, -1.0, 0.0, -0.001)
self.boardPlaneOver = (0.0, 1.0, 0.0, 0.01)
def drawScene(self):
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
glPushMatrix()
self.polarView()
glColorMask(0,0,0,0)
glEnable(GL_STENCIL_TEST)
glStencilFunc(GL_NEVER, 1, 1)
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE)
glDisable(GL_DEPTH_TEST)
self.drawBoard()
glEnable(GL_DEPTH_TEST)
glColorMask(1,1,1,1)
glStencilFunc(GL_EQUAL, 1, 1)
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP)
glEnable(GL_CLIP_PLANE0)
glClipPlane(GL_CLIP_PLANE0, self.boardPlaneUnder)
glPushMatrix()
glScalef(1.0, -1.0, 1.0)
self.setLights()
self.drawPieces()
glPopMatrix()
glDisable(GL_CLIP_PLANE0)
glDisable(GL_STENCIL_TEST)
self.setLights()
# draw scene normally
…