Jump to content
  • Advertisement
Sign in to follow this  
Dave Blake

Quads or Triangles in glDrawElements

This topic is 2835 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

Using glDrawElements to colour a rectangular region, and have vertices (and colour data for each vertex ) in a regular rectilinear grid. At the moment I have it working with gl_quads because that seemed the obvious way to arrange the vertices into elements.

1) Is there any advantage in using gl_triangles instead? I could divide each square cell into two triangles but is there any reason to do so.
2) Are there any optimum ways to order the elements - row of squares (or triangles) at a time seems obvious, but is there a best sequence when for the vertices of one element next to another

At the moment with a vertex grid like

[font="Courier New"]1 --- 2 --- 3 --- 4 -- 5 ---6
| | | | | |
7 --- 8 --- 9 ---10 --11 --12
[/font]

I order as in my array of indices as 7, 1, 2, 8, 8, 2, 3, 9, 9, 3, 4, 10, 10, 4, 5, 11, 11, 5, 6, 12 etc. Does starting the next element at the last vertex of the one before like this make any difference? Or am I fussing about nothing.

Sorry if this is discussed elsewhere but I haven't found it, just point me at it!

Share this post


Link to post
Share on other sites
Advertisement
GL_QUADS is deprecated now, so it might be a good idea to get used to the idea of using triangles instead of quads. Regarding any specific benefits to your application to using quads versus triangles, there's probably no difference.

Share this post


Link to post
Share on other sites
the best way would probably be to use triangle strips. When using indexed vertex data, make sure that every use of an index is as near to each other as possible to use the strength of the post transform cache of your GPU.

Share this post


Link to post
Share on other sites
To clarify - don't use "glDrawElements (GL_TRIANGLE_STRIP", use "glDrawElements (GL_TRIANGLES" but lay out your indexes in triangle strip order. That way you don't have to mess with primitive restart or degenerate triangles but still get all the advantages of both approaches. To quote Tom Forsyth:

...stripping was designed for hardware that did not have indexed primitives, just strips, so it has rather different goals. While still acceptable on indexed hardware, it only gets a ratio of around 1 vert/tri, which is a long way off the practical best of 0.6. However, it is still better than a totally random order!

Let me say this just once, because academics are still spending time and money researching this subject. You're wasting your time. Strips are obsolete - they are optimising for hardware that no longer exists. Indexed vertex caches are much better at this than non-indexed strips, and the hardware is totally ubiquitous. Please go and spend your time and money researching something more interesting.[/quote]

Share this post


Link to post
Share on other sites
So triangles not squares.... :)
Beginning to wonder if I am approaching this the wrong way. I have a rectangular region that I want to colour depending upon a calcuated value for each point within it. I can calculate the colour for any point but don't want to do so for evey pixel as neighbouring points are similar. Rather than apply a rectilinear grid of vertices, would it be better to use a a hexagonal one e.g. staggered rows of vertices, and use GL_TRIANGLES in glDrawElements. Will that give a better (more evenly graduated) distribution of colour?

And triangle strip order, would that be

[font="Courier New"]1 ------ 2 ------ 3 ------ 4 ----- 5 ------6

7 -- 8 ----- 9 ------10 ------11 -----12[/font]

(staggared rows of vertices) as indices 1, 7, 8, 8, 1, 2, 2, 8, 9, 9, 2, 3, 9, 10, 10, 3, 4, 4, 10, 11, 11, 4, 5, 5, 11, 12, 12, 5, 6 etc.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!