Outline a surface and show a selection!
Hi everybody,
I want to do 2 things which are very similar. (I think so)
1)I want to outline the surfaces in OpenGL. How may I do that?
2)I am using OpenGL functions to select an object . How can I draw a line around the selected item? or somehow show which object is selected?
Thank you very much,
Ali
A few ways to do this:
- when you draw a face (triangle), draw the same shape with GL_LINES or GL_LINE_STRIP over the face you just drew
- since you are doing selection, you could also just draw the face with a different color (that tells the user that the face is selected because it is different).
Cheers,
- llvllatrix
- when you draw a face (triangle), draw the same shape with GL_LINES or GL_LINE_STRIP over the face you just drew
- since you are doing selection, you could also just draw the face with a different color (that tells the user that the face is selected because it is different).
Cheers,
- llvllatrix
Hi llvllatrix,
Thank you for your reply.
I did what you said. I only want those lines around my object; however it draws lines around every triangle which makes a mess. How can I fix it?
Thank you,
Ali
Thank you for your reply.
I did what you said. I only want those lines around my object; however it draws lines around every triangle which makes a mess. How can I fix it?
Thank you,
Ali
I'm not entirely sure how your engine works but i hope this helps:
You basically going to have to pass information to your drawing function that tells it if a triangle is selected. If it is, then draw the outline.
If your having problems passing this info, there are a few things you can try. Can you post more info on your project?
Cheers,
- llvllatrix
You basically going to have to pass information to your drawing function that tells it if a triangle is selected. If it is, then draw the outline.
If your having problems passing this info, there are a few things you can try. Can you post more info on your project?
Cheers,
- llvllatrix
Hi llvllatrix,
This is a part of the codes that I am using in rendering surfaces:
Thank you,
Ali
This is a part of the codes that I am using in rendering surfaces:
glColorPointer(4, GL_FLOAT, 0, NULL);glColor4fv(MyObjects[counter].Color4D);glDrawElements(GL_TRIANGLES, MyObjects[counter].TotalIndex, GL_UNSIGNED_INT, MyObjects[counter].pIndex); //Here is the codes I added (your suggestion)glColor4f(0, 1, 0, 1);glDrawElements(GL_LINE_STRIP, MyObjects[counter].TotalIndex, GL_UNSIGNED_INT, MyObjects[counter].pIndex); //////////////////////////////// glEnableClientState(GL_COLOR_ARRAY);
Thank you,
Ali
I don't think the other guy understood what you wanted.
You want to outline the object, like in a cartoon, not draw it in wireframe. If so, look into cartoon rendering / celshading. Nehe has a tutorial that draws outlines.
You want to outline the object, like in a cartoon, not draw it in wireframe. If so, look into cartoon rendering / celshading. Nehe has a tutorial that draws outlines.
Quote:
from Gamasutra.com
To build contours from a convex hull, we use a simple algo-rithm utilizing the fact that each edge in a convex hull connects exactly two faces. The algorithm is this:
1. Iterate through all polygons, and detect whether a polygon faces the viewer. (To detect whether a polygon faces the viewer, use the dot product of the polygon’s normal and direction to any of the polygon’s vertices. When this is less than 0, the polygon faces the viewer.)
2. If the polygon faces viewer, do the following for all its edges: If the edge is already in the edge list, remove the edge from the list. Otherwise, add the edge into the list.
This algorithm basically gives you a list of edges that make up the outline of a convex object. Then you just take this list and render it as GL_LINES or GL_LINES_TRIP
This lesson explains a part of what you seek.
But that doesn't draw contours around sufaces.
For that you need to precompute the edges between the different surfaces, and then store them in an array.
Lastly render them as GL_LINES, if you get some z fighting problems you could try to use polygon offset.
But that doesn't draw contours around sufaces.
For that you need to precompute the edges between the different surfaces, and then store them in an array.
Lastly render them as GL_LINES, if you get some z fighting problems you could try to use polygon offset.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
Hi snisarenko,
What is the “direction to any of the polygon’s vertices” in the dot product? Will you explain it more.
Thank you,
Ali
What is the “direction to any of the polygon’s vertices” in the dot product? Will you explain it more.
Thank you,
Ali
What you want is like a halo effect in white. What is selected should have a "border" that is bigger than the object itself. One way to do this is to draw the object regular, draw the object to the stencil buffer, then draw the object(no textures, color white or the color you want, scaled a little bigger(0.1 bigger maybe), but the negative of what is normally done with the stencil buffer. Usually the stencil buffer is used to keep something only drawn on certain pixels, but if you change the parameters of the stenciling functions nagatively, you can make it only draw outside of the area. So when you redraw the object alittle bigger in only white, it surrounds the object without covering it. Also useful for showing something's status in a game, like poisoned or something.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement