Results 1 to 5 of 5

Thread: reflected objects showing up below floor

  1. #1
    Guest

    reflected objects showing up below floor

    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...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
    ...

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: reflected objects showing up below floor

    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.

  3. #3
    Guest

    Re: reflected objects showing up below floor

    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

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: reflected objects showing up below floor

    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,
    Tom
    Wrong, a radeon can handle a stencil buffer. As Relic said, ensure your windows has enabled the stencil with appropriate bits size (commonly 8 bits).

  5. #5
    Guest

    Re: reflected objects showing up below floor

    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

Similar Threads

  1. Depth/Normal data from Reflected Objects using Cubemaps
    By romulogcerqueira in forum OpenGL: GLSL
    Replies: 12
    Last Post: 01-12-2018, 05:46 PM
  2. Showing subset of currently rendered objects
    By jas511 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 03-06-2012, 06:03 AM
  3. drawing reflected rays in ellipse(optical property
    By SasukeUchihas in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 01-20-2011, 02:03 PM
  4. reflected vector in combiners
    By jorge1774 in forum OpenGL: Advanced Coding
    Replies: 15
    Last Post: 03-19-2003, 03:23 AM
  5. Reflections: Reflected object appears off "mirror"
    By Structural in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-04-2003, 07:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean