Home > other >  Questions about opengl template test
Questions about opengl template test

Time:04-20

 glClearColor (0.2 f, f 0.3, 0.3 f, 1.0 f); 

GlStencilOp (GL_REPLACE GL_KEEP, GL_KEEP);//if the template test fails, replace with ref template buffer value

GlStencilMask (10);//set the mask to 10
GlClearStencil (13);//set the default value of stencil buffer

GlClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); The value is 10//stencil buffer & amp; 13=8

GlStencilMask (0 XFF);//set the template test fails to mask
GlStencilFunc (GL_EQUAL, 9, 0 xf);//(0 xf & amp; 8)!=(0 xf & amp; 9), the test is not through

//draw the first triangle
GlUseProgram (shaderProgramOrange);
GlBindVertexArray (VAOs [0]);
GlDrawArrays (GL_TRIANGLES, 0, 3);

GlStencilFunc (GL_EQUAL, 9, fmask);//because it is the replace, test for the first time should have changed template buffers to 9,
//that the test should be able to pass here, but is measured not by????????

//draw the second triangle
GlUseProgram (shaderProgramYellow);
GlBindVertexArray (VAOs [1]);
GlDrawArrays (GL_TRIANGLES, 0, 3);


GlBindVertexArray (0);

//Swap the screen buffers
GlfwSwapBuffers (Windows);

GlStencilMask (0 XFF);
GlClearStencil (0);//reset the stencil buffer value of 0

GlClear (GL_STENCIL_BUFFER_BIT);


The above code, the main logic is when template test fails for the first time the replace template buffers (8 to 9), and then use the new template buffers (9), the second test are supposed to pass, that is the second triangle can be mapped, but actual it is the second template test or failure, change line 18 second template testing way to "glStencilFunc (GL_EQUAL, 8, fmask)" can test pass, this means GL_REPLACE in template test fails for the first time does not replace the template buffer value! What reason is this excuse me?

Thank you first!
  • Related