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 5 of 5

Thread: Problem with stencilling

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2011
    Posts
    3

    Problem with stencilling

    I'm trying to use stencilling to control where my reflected object is visible like I've seen in several tutorials, but I can't seem to prevent the reflection from showing up at all. Here's the relevant code snippet:

    Code :
      glClear(GL_STENCIL_BUFFER_BIT);
     
      //disable drawing
      glDisable(GL_DEPTH_TEST);
      glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
     
      //enable stencilling
      glEnable(GL_STENCIL_TEST);
      glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
      glStencilFunc(GL_ALWAYS, 1, 1);
     
      //would draw stencil for reflective surface here
     
      //reenable drawing
      glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
      glEnable(GL_DEPTH_TEST);
     
      //set up stencil
      glStencilFunc(GL_EQUAL, 1, 1);
      glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
     
      draw_reflection();
     
      //disable stencilling
      glDisable(GL_STENCIL_TEST);
    From what I understand of stencilling, since I haven't specified any area to have a stencil value of 1, the object from draw_reflection shouldn't be drawn at all. When I run the code, the reflected object shows up unchanged. What am I not understanding here?

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2006
    Location
    greece
    Posts
    181

    Re: Problem with stencilling

    Try glClearStencil(0) before glClear(GL_STENCIL_BUFFER_BIT).
    while(1){keyboardsolo(FORTE, BPM_190);}

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2011
    Posts
    3

    Re: Problem with stencilling

    Thanks for the tip, but that didn't change anything.

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,575

    Re: Problem with stencilling

    Do you actually have a stencil buffer ?
    You should ask for it at context creation (like double buffering, depth buffer, etc) otherwise the driver may or may not create one for you.
    Example for glut :
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_STENCIL|GLUT_ DEPTH|GLUT_ALPHA);

    Then once the gl window is created, you can verify how many stencil bits you actually got :

    int stencilBits=-1;
    glGetIntegerv(GL_STENCIL_BITS, &stencilBits);

    If stencilBits is 0, then you effectively have no stencil buffer available.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2011
    Posts
    3

    Re: Problem with stencilling

    Yep, that did it. Thanks for the help. Embarrassing to have missed something so simple. >.<

Posting Permissions

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