Issue with stencil buffer

Hi.I am working on Linux environment and I am using OpenGLES2.0. My target GPU is Fujitsu Ruby MB86298 . I am developing a small application using stencil buffer. It works perfectly but its rendering 4 small primitives which are in shape of the stencil pattern,I mention in the code.If stencil pattern is circle ,the it renders 4 small dark circles on the screen ,if stencil pattern is square it draws four small squares.This problem happens when I run the code in a loop.If the code is run only for one time I am not getting those small primitives.Kindly please help me to solve this problem.

There is flickering with ghost image of the stencil

I’m afraid I don’t really understand your problem description, perhaps you could post a pseudo code description showing your stencil test settings and the general steps you are doing? Since you mentioned it only happens when running things in a loop, as a random guess: are you perhaps not clearing the stencil buffer between frames or steps of your algorithm?

glEnable(GL_STENCIL_TEST);

glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glDepthMask(GL_FALSE);
glStencilFunc(GL_ALWAYS, 1, 0xFF); // Set any stencil to 1
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilMask(0xFF); // Write to stencil buffer
glClear(GL_STENCIL_BUFFER_BIT); // Clear stencil buffer (0 by default)

/*** Draw Stencil pattern *******/
 draw_stencil pattern();

glStencilFunc(GL_EQUAL, 1, 0xFF); // Pass test if stencil value is 1
glStencilMask(0x00); // Don't write anything to stencil buffer
glDepthMask(GL_TRUE); // Write to depth buffer
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

/*********************** draw actual network ************************/
draw_actual_content();
glDisable(GL_STENCIL_TEST);

There is flickering of ghost images of stencil pattern when I execute the above piece of code in a loop

Thanks, that makes it clearer to me what you are doing :slight_smile: - please use [noparse]


[/noparse] around source snippets to preserve formatting.

Hmm, unfortunately I don’t see what could be the problem here. Is the depth test enabled for the whole duration of the posted code? When is the depth buffer cleared with respect to the above, e.g. before the shown part?

depth color and stencil buffer bits are cleared in every run of the loop using glClear(). I read somewhere that stencils doesn’t work properly on few GPU’s.The same piece of code is working properly on inte(R) HD graphics but its not working properly on ruby.When I checked the errata of the graphic card (refer E17), they suggest to use flush command before setting the masks,but it didn’t give the desired output.http://www.fujitsu.com/downloads/MICRO/fme/displaycontrollers/es-mb86298-rev1-21.pdf