outline a model

Started by
20 comments, last by songho 17 years, 11 months ago
I have models of tanks and stuff in my game and want there to be a thin green outline around them when they're selected. I thought about drawing each model again in GL_LINE mode but that draws all the polys as lines, not just the outline so it looks more like a net. How can I do it? Thanks. (please ask if I wasn't clear)
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Advertisement
one easy method can be found in nehe lesson 37. check out the "outline" code right at the end.
This space for rent.
Thanks for that link.
So if I have code that draws a 3D model: DrawModel();
to get the outline I'd do:

glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA ,GL_ONE_MINUS_SRC_ALPHA);
glPolygonMode (GL_BACK, GL_LINE);
glLineWidth (outlineWidth);
glCullFace (GL_FRONT);
glDepthFunc (GL_LEQUAL);
glColor3fv (&outlineColor[0]);
DrawModel();

and I'd get the outline?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
On a similar note... are lines the "accepted" way to apply outlines to cell shading (to produce a cartoonish image)? Or is it a screen space normal direction test? (ie see which pixels are within a certain degree of perpendicular to the view direction)?

thanks
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out his new home he rounded a corner and saw someone in Marine Dress Blues. He ran back to St. Peter and yelled "You lied to me! There are Marines in heaven!" St. Peter said "Who him? That's just God. He wishes he were a Marine."
I tried and it didn't work. I did:
Display(tank,0,false);  //outline:  glDisable(GL_TEXTURE_2D);  glEnable (GL_BLEND);						  glBlendFunc (GL_SRC_ALPHA ,GL_ONE_MINUS_SRC_ALPHA);  glPolygonMode (GL_BACK, GL_LINE);		  glLineWidth (5);			  glCullFace (GL_FRONT);  glDepthFunc (GL_LEQUAL);			    glColor3f (0,1,0);	    Display(tank,0,false);    glDepthFunc (GL_LESS);				  glCullFace (GL_BACK);				  glPolygonMode (GL_BACK, GL_FILL);		    glLineWidth (1);	    glDisable (GL_BLEND);	  glEnable(GL_TEXTURE_2D);

were Display() renders a model. But instead of drawing a green outlin the whole tank cameout green, it eas even textured? It was like the front facing culling wasn't working or something.
What did I do wrong?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
daniel_i_l,
The other simple method is shifting(shaking) the object slightly left/right/up/down, then drawing it 4 times on the stencil buffer to make a silhouette. There is an old example at SGI site, silhouette.c It resizes glViewport instead moving the object. The result is not same as nehe lessen #37. It creates the outlines only, not all edges of the object.
The way i did it is similar to songho's method, but without drawing it 4 times. The process goes like this:

1. Disable color writes and draw (filled) to create a mask in the stencil buffer
2. Enable color writes, set linewidth to something big (like 7) and draw again in wireframe where the stencil is not set.

This produces the same effect as his method, ie only the outline.
Gaenor, that method sounds good. I don't know much about the stencil buffer though. Do you think that you (or someone else) could explain more? Maybe with a little code?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
anyone?
Thanks.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
http://www.opengl.org/resources/features/StencilTalk/
can also be gotten as a pdf in one file

This topic is closed to new replies.

Advertisement