블로그 (Blog)/개발로그 (Devlogs)
Outline 그리기
ihmin
2024. 3. 12. 14:05
opengl 에서 outline을 그리는 몇가지 방법중의 하나..
바로 stencil buffer 를 이용함.
glPushAttrib(GL_ALL_ATTRIB_BITS);
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
// Set the stencil buffer to write a 1 in every time
// a pixel is written to the screen
glStencilFunc(GL_ALWAYS, 1, 0xFFFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glColor3f(1.0f, 0.0f, 0.0f);
...draw primitive...
glStencilFunc(GL_NOTEQUAL, 1, 0xFFFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
// Draw the object with thick lines
glLineWidth(4.0f);
glDisable (GL_LINE_SMOOTH);
glDisable(GL_LIGHTING);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glColor3f(1.0f, 1.0f, 1.0f);
...draw primitive...
glPopAttrib();