PDA

View Full Version : reflected objects showing up below floor



07-29-2005, 04:27 AM
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
...

Relic
07-29-2005, 05:04 AM
Make sure your pixelformat has stencil bits.
Check glGetIntegerv(GL_STENCIL_BITS, &stencilBits).
Some hardware doesn't support stencil in 16 bits color resolutions.

Also notice that the glScalef(1.0f, -1.0f, 1.0f) changes the handedness of your coordinate system. You need to toggle the glFrontFace() setting too if you want rendering and esp. lighting to be correct.

07-30-2005, 06:04 AM
The glGetIntegerv(GL_STENCIL_BITS) returned 0. That would indicate why the pieces were showing up below the board. My ATI Radeon 9200 must not have a stencil buffer.

Using glFronFace doesn't seem to have a noticeable effect, but I'm using it anyway.

Thanks for the help,
Tom

jide
07-31-2005, 05:24 AM
Originally posted by <dh>:
The glGetIntegerv(GL_STENCIL_BITS) returned 0. That would indicate why the pieces were showing up below the board. My ATI Radeon 9200 must not have a stencil buffer.

Using glFronFace doesn't seem to have a noticeable effect, but I'm using it anyway.

Thanks for the help,
TomWrong, a radeon can handle a stencil buffer. As Relic said, ensure your windows has enabled the stencil with appropriate bits size (commonly 8 bits).

07-31-2005, 08:23 PM
I finally got the stencil buffer to work. I found the documenation on QQLFormat. This is what I had to add to the beginning of my application:

glformat = QGLFormat()
glformat.setStencil(True)
QGLFormat.setDefaultFormat(glformat)

Thanks,
Tom