Outline 그리기

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();

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다


This site uses Akismet to reduce spam. Learn how your comment data is processed.