Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 10

Thread: Polygon with more than 3 vertices?

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2014
    Posts
    19

    Polygon with more than 3 vertices?

    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.

  2. #2
    Junior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    233
    Quote Originally Posted by mast4as View Post
    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.

    Quote Originally Posted by mast4as View Post
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2014
    Posts
    19
    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.

  4. #4
    Junior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    233
    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).

  5. #5
    Junior Member Newbie
    Join Date
    Aug 2014
    Posts
    19
    okay yes sure. That would involve to have texture coordinates though. But yes it's an idea;-) Thanks for your answers.

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2014
    Posts
    19
    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.

  7. #7
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    204
    Quote Originally Posted by Agent D View Post
    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.

  8. #8
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,268
    Quote Originally Posted by mast4as View Post
    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.

  9. #9
    Junior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    233
    Quote Originally Posted by Carmine View Post
    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....

  10. #10
    Junior Member Newbie
    Join Date
    Aug 2014
    Posts
    19
    Cool, thank you I didn't know about the restart feature.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •