Hi Friends,
I want to use very basic Stencil tests in a VTK application.
I’m using VTK 9.2.2 under Windows, OpenGL backend.
All is done inside vtkContext2D (scene, actor), with RenderWindow.StencilCapableOn().
Code in the main rendering pass :
state.glPush();
state.glDisable(GL_DEPTH_TEST);
state.glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
state.glEnable(GL_STENCIL_TEST);
state.glStencilMask(0xFF);
state.glClearStencil(0);
state.glClear(GL_STENCIL_BUFFER_BIT);
state.glStencilFunc(GL_ALWAYS, 1, 0xFF);
state.glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
...
//call to several "glDrawPolygon" to fill some polygonal areas
...
state.glStencilMask(0x00);
state.glStencilFunc(GL_EQUAL, 1, 0xFF);
state.glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
state.glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
...
//draw a pattern with "glDrawLines", that fills the entire viewport
What I’m expecting, is that the pattern is only visible inside the polygonal areas.
What I’m seeing, is the pattern everywhere.
So I’ve tested a simpler code :
state.glPush();
state.glDisable(GL_DEPTH_TEST);
state.glEnable(GL_STENCIL_TEST);
state.glStencilMask(0xFF);
state.glClearStencil(0);
state.glClear(GL_STENCIL_BUFFER_BIT);
state.glStencilFunc(GL_NEVER, 0, 0xFF);
...
//call to several glDrawPolygon to fill some polygonal areas
What I’m expecting, is that there is nothing visible.
What I’m seeing is all my polygons.
I’ve dug inside VTK code, and found that “vtkOpenGLLabeledContourMapper” is using such an approach, but with some Shader (weird) code.
Could you please help me on that one ?