Sign in to follow this  
stuh505

create 3d outline?

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
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
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
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
Guest Anonymous Poster
Disable Depth Writes (depth testing is still on, just the buffer will not be altered)
Draw the scaled up colord "hilight" version of the mesh.
Enable Depth Writes.
Draw the normal mesh.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
P.S.
the above method does not use wireframe for the 'hilight' mesh, draw that as normal polygons, just scaled bigger

Share this post


Link to post
Share on other sites
Anonymous Poster,

scaling up the mesh doesn't work to create a uniform outline.

however, your trick fixes the method proposed by TheSeb.

I just put this around the draw func and now it works perfectly :)

glDepthMask(GL_FALSE);
---
glDepthMask(GL_TRUE);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this