Draw contour around object in Opengl
Posted
by
Maciekp
on Game Development
See other posts from Game Development
or by Maciekp
Published on 2011-06-27T10:33:42Z
Indexed on
2012/12/11
17:24 UTC
Read the original article
Hit count: 243
I need to draw contour around 2d objects in 3d space. I tried drawing lines around object(+points to fill the gap), but due to line width, some part of it(~50%) was covering object. I tried to use stencil buffer, to eliminate this problem, but I got sth like this(contour is green):
http://goo.gl/OI5uc (sorry I can't post images, due to my reputation)
You can see(where arrow points), that some parts of line are behind object, and some are above. This changes when I move camera, but always there is some part, that is covering it. Here is code, that I use for drawing object:
glColorMask(1,1,1,1);
std::list<CObjectOnScene*>::iterator objIter=ptr->objects.begin(),objEnd=ptr->objects.end();
int countStencilBit=1;
while(objIter!=objEnd)
{
glColorMask(1,1,1,1);
glStencilFunc(GL_ALWAYS,countStencilBit,countStencilBit);
glStencilOp(GL_REPLACE,GL_KEEP,GL_REPLACE );
(*objIter)->DrawYourVertices();
glStencilFunc(GL_NOTEQUAL,countStencilBit,countStencilBit);
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
(*objIter)->DrawYourBorder();
++objIter;
++countStencilBit;
}
I've tried different settings of stencil buffer, but always I was getting sth like that. Here is question: 1.Am I setting stencil buffer wrong?
2. Are there any other simple ways to create contour on such objects?
Thanks in advance.
EDIT:
1. I don't have normals of objects.
2. Object can be concave.
3. I can't use shaders(see below why).
© Game Development or respective owner