



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Two algorithms for rendering object silhouettes using opengl stenciling. The first algorithm involves translating the image in four directions and counting pixels that pass the depth test. The second algorithm renders the offset depth image and toggles the stencil bit at each pixel for the remaining facets. Both algorithms are explained in detail.
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!




** save the depth buffer and turn off the color buffer */ glReadPixels(0, 0, winWidth, winHeight, GL_DEPTH_COMPONENT, GL_FLOAT, depthSave); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
/* ** clear the stencil buffer for this object / glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 0, 0); / clear stencil for this object */ glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO);
/* ** set the polygon offset a tiny bit */ glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.5, 1.0);
drawMyObject();
glDisable(GL_POLYGON_OFFSET_FILL);
/* ** set up for stenciling, write a ’1’ whereever there is ** a line */ glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_ZERO, GL_ZERO, GL_REPLACE);
/* ** disable writes to the Z−buffer test ** test for less than or equal to */ glDepthFunc(GL_LEQUAL); glDepthMask(GL_FALSE);
** render all polygons in outline mode without updating the ** color buffer or the depth buffer, ** this sets the stencil bit where for all the non−hidden ** lines in the object */ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); drawMyObject();
/* ** now the stencil only has the bit set for the non−hidden lines ** Turn on the color buffer ** restore the depth buffer ** write only were the stencil bit is set ** now the depth buffer and color buffer are current **/
glDepthMask(GL_TRUE); glDepthFunc(GL_ALWAYS); glDisable(GL_STENCIL_TEST);
** now the stencil only has the bit set for the non−hidden lines ** Turn on the color buffer ** restore the depth buffer ** write only were the stencil bit is set ** now the depth buffer and color buffer are current **/
glDepthMask(GL_TRUE); glDepthFunc(GL_ALWAYS); glDisable(GL_STENCIL_TEST); pushOrthoView(0, 1, 0, 1, 0, 1); glRasterPos2f(0, 0); glDrawPixels(winWidth, winHeight, GL_DEPTH_COMPONENT, GL_FLOAT, depthSave); popView(); glEnable(GL_STENCIL_TEST);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glColor3f(1,1,1); drawMyObject();
/* ** Turn off stenciling, enable writes to the color buffer, then ** render all polygons again in outline mode using foreground color */ glDisable(GL_STENCIL_TEST); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDepthFunc(GL_LESS);
Stenciling
Alg 1:
stencil values meaning 0 no object 1 outline of object 2 silhouette 3 silhouette 4 interior
Alg 2.