PDA

View Full Version : Polygon with more than 3 vertices?



mast4as
08-07-2014, 09:42 AM
I used OpenGL in the past, but I am just in the process of catching up on the later development with GL4. I understand the concept of VBO, etc. but it seems to me like the only way of drawing something to the screen now, is if the geometry is triangulated? Is this correct?

What I'd like to do, is display for example a 'cube' shaded but with the wireframe on top. So if define the cube by 8 vertices and 6 faces, I will need to triangulate the faces. If I render this in wireframe, I will see the triangles which I don't want. I want to see the ORIGINAL cube faces.

How can I do this? It seems to me that the only solution is to render the mesh in fill mode, then draw the lines on top to show the original edges of the original model. Is that how it's supposed to be done?

Thank you.

Agent D
08-07-2014, 09:51 AM
it seems to me like the only way of drawing something to the screen now, is if the geometry is triangulated? Is this correct?
Yes, unless you use compatibillity profile where all the old cruft is still available.


What I'd like to do, is display for example a 'cube' shaded but with the wireframe on top. So if define the cube by 8 vertices and 6 faces, I will need to triangulate the faces. If I render this in wireframe, I will see the triangles which I don't want. I want to see the ORIGINAL cube faces.

How can I do this? It seems to me that the only solution is to render the mesh in fill mode, then draw the lines on top to show the original edges of the original model. Is that how it's supposed to be done?
Either that, or use a texture.

mast4as
08-07-2014, 09:54 AM
Thank you very much. Using a texture? How would that work more specifically. It seems to me that you need to know where the edges are in texture space, which requires your geometry to have texture coordinates? Is that what you were thinking about?

Thanks again.

Agent D
08-07-2014, 09:57 AM
You could map a texture to the cube with the texture coordinates set up in a way that the edges of the texture match the edges of the cube. The texture image itself has somehow highlighted edges (e.g. a white line on the edge and black every else).

mast4as
08-07-2014, 10:34 AM
okay yes sure. That would involve to have texture coordinates though. But yes it's an idea;-) Thanks for your answers.

mast4as
08-07-2014, 11:46 AM
I have another related question, and I think it's better if I don't start another thread. So I draw the (triangulated) faces of the cube then I need to draw the lines for the faces. I have never used GL_LINES or GL_LINE_LOOP before. Is it possible to draw multiple line loops in one single glDrawElement calls or do I need 1 glDrawElement call per loop? Thanks.

Carmine
08-07-2014, 12:08 PM
You could map a texture to the cube with the texture coordinates set up in a way that the edges of the texture match the edges of the cube. The texture image itself has somehow highlighted edges (e.g. a white line on the edge and black every else). Do you mean 'black' everywhere else, or transparent every where else? 'Black' would result in a cube with white edges, but opaque faces. I assume that the OP wants a true wireframe effect, where you can see right through the cube.

mhagain
08-07-2014, 12:10 PM
I have another related question, and I think it's better if I don't start another thread. So I draw the (triangulated) faces of the cube then I need to draw the lines for the faces. I have never used GL_LINES or GL_LINE_LOOP before. Is it possible to draw multiple line loops in one single glDrawElement calls or do I need 1 glDrawElement call per loop? Thanks.

You can do it with a single glDrawElements using primitive restart. You specify an index to be the restart index (typically -1 is chosen, which is equivalent to 0xffff if using unsigned short or 0xffffffff if using unsigned int indices), then fill your element array buffer with indices for your line loop, placing a restart index between each line loop. Then when you issue your glDrawElements call, each time it hits this restart index it will begin a new line loop. Don't forget to enable primitive restart too.

Agent D
08-07-2014, 12:20 PM
Do you mean 'black' everywhere else, or transparent every where else? 'Black' would result in a cube with white edges, but opaque faces. I assume that the OP wants a true wireframe effect, where you can see right through the cube.
And you could also do it procedurally in a fragment shader instead of wasting texture memory and so on and so forth....
Your mileage may vary.... (http://www.catb.org/jargon/html/Y/Your-mileage-may-vary.html)

mast4as
08-07-2014, 02:02 PM
Cool, thank you I didn't know about the restart feature.