Jump to content
  • Advertisement
Sign in to follow this  
stuh505

create 3d outline?

This topic is 4402 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to create an outline around a 3d object to show that it is selected. my idea to do this was to render a slightly scaled up and colored version of the object below it. however, Im not sure how to do that with depth testing -- I need to have depth testing enabled on the real object, but it would be enveloped inside the highlight object.

Share this post


Link to post
Share on other sites
Advertisement
Hi,
I have ever done this (not by selecting something but just like that) so i think i can help you :
to do that you can render two times your mesh : the first will be your simple mesh without back faces, and the second is the same in wireframe but without front faces. For this second mesh, you also have to increase the width of the lines, a command helps you to do that in opengl it is glLineWidth(...) which you call before the rendering of the mesh. both meshes have to be rendered at the same place, so the widthest lines are around the first mesh.

Share this post


Link to post
Share on other sites
First draw the mesh scaled up with front face culling enabled and only a color, then draw your mesh regular sized, with textures with the normal backfaced culling enabled.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thank you both for the suggestions. I have tried both methods and they both have problems.

TheSeb, after culling front faces and going into wireframe mode (glPolygonMode(GL_BACK, GL_LINE)) the edges on the front of the model are still displayed and overlap the model.

rick, this "works" but scaling creates an inconsistent thickness of the edge which doesn't look right.

Share this post


Link to post
Share on other sites
heres what my code looks like

//draw pyramid highlight
if (pyramid_selected){
//cull front faces
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);

//go into wire mode
glPolygonMode(GL_BACK, GL_LINE); //wireframe mode
glEnable(GL_LINE_SMOOTH);
glLineWidth(5); //fat lines
glColor3f(1,0,0);

//draw the object
draw_pyramid();

glLineWidth(1);
glDisable(GL_LINE_SMOOTH);
glPolygonMode(GL_BACK, GL_FILL); //back to solid mode
glDisable(GL_CULL_FACE);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by stuh505
heres what my code looks like

//draw pyramid highlight
if (pyramid_selected){
//cull front faces
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);

//go into wire mode
glPolygonMode(GL_BACK, GL_LINE); //wireframe mode
glEnable(GL_LINE_SMOOTH);
glLineWidth(5); //fat lines
glColor3f(1,0,0);

//draw the object
draw_pyramid();

glLineWidth(1);
glDisable(GL_LINE_SMOOTH);
glPolygonMode(GL_BACK, GL_FILL); //back to solid mode
glDisable(GL_CULL_FACE);
}


for the solid mode you have to recall glCullface with GL_BACK and glPolygonMode with GL_FRONT

Share this post


Link to post
Share on other sites
Quote:
Original post by TheSeb

for the solid mode you have to recall glCullface with GL_BACK and glPolygonMode with GL_FRONT


No I don't because I disabled opengl culling before drawing the solid one, and it is not necessary to use culling to display regular objects.

I also don't need to change polygon mode back to gl front because the previous call only changed the value for gl_back, and I set that back.

The object in the front is rendering properly, it is the wire object that is not rendering right

Share this post


Link to post
Share on other sites
perhaps i'm doing a mistake but if both meshes are in the same polygon mode it is normal that they are overlaped, the lines of the first one have to be hidden by the front filled faces of the second one. i'm not sure that glCullFace is needed if you don't set glPolygonMode to GL_FRONT_AND_BACK.

Share this post


Link to post
Share on other sites
your code works fine for me, assuming your drawing the object immediatly after that block. maybe something outside that code block? got any screenshots?

Share this post


Link to post
Share on other sites
I am drawing he object immediately after.

Quote:
perhaps i'm doing a mistake but if both meshes are in the same polygon mode it is normal that they are overlaped, the lines of the first one have to be hidden by the front filled faces of the second one. i'm not sure that glCullFace is needed if you don't set glPolygonMode to GL_FRONT_AND_BACK.


They arent in the same polygon mode. The outline-object is in BACK/WIRE mode andthe regular object is in FRONT+BACK/FILL mode.

Screenshot:
http://img452.imageshack.us/img452/4923/sh1pu0.jpg

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!