Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: failed to use Stencil

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    8

    failed to use Stencil

    Hi,

    I'm trying to port a DirectX10 piece of code but I failed to use stencil correctly.

    Here is my test :
    I have a FBO with a depth stencil render buffer attached and stencil test enabled. I clear it to '1' value.
    Then I attach color buffers to the FBO and try to draw a simple fullscreen quad just for test, with stencil test func set to GL_GREATER and ref value to '1'. So I expect to have nothing drawn....but all pixels are drawn on the screen...

    Could you please help me finding where I'm wrong ?

    the code lokks like this :

    Code :
    glClearStencil(1);
     
    (...) //create the renderBufferObject, attach to the FBO
     
    glStencilMaskSeparate(GL_FRONT_AND_BACK, 0xffffffff);
    glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); //want to keep depth
     
    glEnable(GL_STENCIL_TEST);
    glStencilFuncSeparate(GL_FRONT, GL_GREATER, 1, 0xffffffff);
    glStencilMaskSeparate(GL_FRONT, 0);
    glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEPP, GL_KEEP);
     
    (...) //draw

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,723

    Re: failed to use Stencil

    You only set the values for GL_FRONT facing polygons. Are you sure you're drawing the front of your triangles? OpenGL defaults to no face culling, so if you're drawing the back, you'd never notice.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2011
    Posts
    8

    Re: failed to use Stencil

    Ok, I've found the problem.

    You're right there was a very hidden little bug in the engine I'm using that caused wrong culling & CW on my quad as a side effect. So the stencil seperate affected was effectively the GL_BACK instead of the GL_FRONT.

    I have to fix all that stuff now

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •