Results 1 to 4 of 4

Thread: stencil buffer

  1. #1
    Member Contributor
    Join Date
    Apr 2002
    Posts
    94

    stencil buffer

    I have a bunch of different objects in the scene that I need to use the stencil buffer to fill their interiors. I have a different texture to overlay for each one. The problem is, I don't want one texture to write on top of another object's stencil.

    Should I use glClearStencil before drawing each one? That sounds slow.

    Is there a better way?
    P4 2Ghz, GEFORCE4, 512 Meg RAM, WIN2000, VStudio 6.0

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: stencil buffer

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glClearStencil is used to tell OpenGL what value the stencil should be cleared to, when you use the above.
    Deiussum
    Software Engineer and OpenGL enthusiast

  3. #3
    Member Contributor
    Join Date
    Apr 2002
    Posts
    94

    Re: stencil buffer

    I think I will still have the same problem though. I'll try to explain better:

    Say that I have 2 stenciled areas and I want a different texture drawn for each stencil. The stencils might be close together and when I draw my big texture, it will draw into the other stencil.

    How do I avoid this?

    I could clear the stencil buffer before drawing each stencil but that doesn't seem very optimal. I want to generate all of my stencils and THEN draw them all with different textures.

    Thanks!
    P4 2Ghz, GEFORCE4, 512 Meg RAM, WIN2000, VStudio 6.0

  4. #4
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: stencil buffer

    When you draw each area you can specify a replace in stencil op with a ref value in stencil func.

    Then when you want to fill you can perform a stencil equals test with a ref value that is equal to the region value used earlier for the area you want to fill.

Similar Threads

  1. Replies: 1
    Last Post: 09-11-2013, 11:35 AM
  2. copy app generated stencil data to stencil buffer
    By guilder in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 12-23-2010, 06:46 PM
  3. Coping from FBO's stencil to main stencil buffer ?
    By gregory_x in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 08-30-2010, 01:09 AM
  4. Depth buffer and stencil buffer / Alpha test
    By greg2 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 08-05-2004, 01:50 AM
  5. How to clear stencil buffer after stencil test?
    By in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 06-14-2003, 09:04 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