Stencil test fails second time?

Hi!

I’m going a bit crazy… :frowning:

My “scene” consist of two vertex buffers, which renders correctly when I render without any stencil test. So I know that there should be nothing wrong with depth/alpha tests etc…

But as soon as I turn on stencil test, it seems only one of the vertex buffers is rendered, i.e. the other one fails the test somehow. :frowning:

This is my “workflow” so to speak;

  1. Enable stencil test, disable depth test.

  2. Set depth and color masks to false.

  3. Clear the stencil buffer to 0x0.

  4. Set the stencilfunc to GL_ALWAYS and use 0x1 as ref. Also set the stencilop to GL_REPLACE (all three tests).

  5. Now render two quads to the screen, where I want the stencil buffer to be set to ones.

  6. Set stencilfunc to GL_EQUAL, and 0x1 as ref, and this time set stencilop to GL_KEEP (all three tests).

  7. Set depth and color masks back to true, and clear depth and color buffers.

  8. Now finaly render my two vertex buffers.

The result is that only one of the vertex buffers are rendered, actually the last one rendered. Am I missing something?