Triangles vs. Quads?

So, from what I have read, the base of the rendering system of openGL is triangles, so there is no extra processing step when rendering them. The con is that a shape made from triangles instead of quads could have more faces. My question is: Are triangles more efficient to draw with?

In this day and age I don’t think it matters unless you have a massive number of quads which need to be broken down. But yes, technically triangles would be more efficient depending how you use them.

Quads are bad.

A tetrahedron has 4 vertices right?
So it can be passed in as a quad.

But how would OpenGL render it?

Triangles, since thats what it is made of.

No, I mean passing the vertices of a tetrahedron as a quad. It’s impossible, as the maximum vertices you can have on any plane is 3.

Therefore, OpenGL has to split quads into triangles, but how do you know which way that will split?

It cannot be done in openGL with only 4 vertices. If you tried, it would create something like a triangle on the lower plane, and loft itself up to the 4th vertex on the upper plane.

EDIT: I think.

If you’re doing 2d game, use quads. It is simpler and all that. LWJGL or OpenGL will convert them to triangles anyway. Don’t bother.
If it is a 3d game with a lot of triangles, than you should use triangles.

Anyone who knows some of the inner workings of OpenGL care to confirm whether quads are bad or not?

https://www.opengl.org/wiki/Primitive

I think quads basically become 2 triangles. The key is that they can be specified to be coplanar. I have exclusively used quads in many things and have seen no difference in performance when rendering sprites. This is only for sprite rendering nothing else.

Your only problem is the potential for unexpected behaviour. And unexpected behaviour in OpenGL can cause anything from rendering artifacts to random crashes.

As HeroesGraveDev already hinted, you should use triangles just because you are then in total control of the effects. And when you think about it, it shouldn’t really matter, because you can just write yourself a little helper function which generates two triangles out of 4 vertices.

So to some it up:

  • speed is the same
  • very easy to split quads yourself
  • otherwise can have some strange uncontrolled behavior

It doesn’t matter for the frames per second whether you use the one or the other. Although, if you use triangles you can turn on cull facing for a small performance increase. You also need to use triangles to do some effects, like glsl shadowing. Use triangles and you might save yourself a lot of hassle down the road :slight_smile:

Mike

Use triangles. Quads don’t exist in OpenGL ES and part of the reason is they have a few quirks that tend to catch people out.

Cas :slight_smile:

Use quads only if you’re sure it gives you a noticeable speedup (it does in the alpha version of TUER) but even in my case I switched to triangles (in the pre-beta version of TUER). I agree with princec and triangles are easier to manage, for collisions too.

Go with triangles.

As mentioned above OpenGL ES doesn’t have quads, further OpenGL 3.0 depreciated GL_QUADS and they were removed from the core profile in OpenGL 3.1.

There is no real advantage in using quads directly since most drivers converts them to triangles anyway. If you must have a method for drawing quads, just create a wrapper method that draws them using GL_TRIANGLES or GL_TRIANGLE_STRIP.

If you compare quads to indexed triangles (= 6 indices forming two triangles using 4 vertices), there are only a few main differences that I know of in addition to the ones mentioned by kappa and princec. Performance differences are hardware specific and should not be measurable on non-ancient hardware.

  • If you use glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) to draw a wireframe, there won’t be a diagonal line across the quad formed by GL_QUADS, but since the one made from indexed triangles actually are just triangles, you’ll get a diagonal line where the seam is between the two triangles.

±-+
| |
| | GL_QUADS
| |
±-+

±-+
|\ |
| \ | GL_TRIANGLES
| |
±-+

  • On AMD hardware, GL_QUADS is not pixel perfect for some reason, so GL_TRIANGLES is to prefer.

  • When doing instancing on Nvidia hardware (this ONLY concerns instancing!), indexed rendering is much slower than normal rendering. Even though the driver does the exact same thing internally, glDrawArraysInstanced(GL_QUADS, …) is much faster than glDrawElementsInstanced(GL_TRIANGLES, …).

TL;DR: Use indexed triangles.

Gl triangles are more efficient for a few reasons I found these out when rendering 3d using good ol math. The algorithms for rendering and setting the verticies depending on the rotation are a lot simpler and efficient , they do not require as much gpu hardware and give more accurate results than using a square, mainly because on a square the delta x,y,z differ however on a triangle they stay the same. Also triangles are a lot easier to mold into other shapes such as decaheadrons and spheres.

FTFY. You can use {code}{/code} for monospace text art.

Well, I am glad I asked this question. Continuing to use triangles then.

GPUs can’t actually render quads. It’s entirely possible to create a quad where all 4 vertices do not lie on the same plane in which case the math is no longer linear, so GPUs just split them up into two triangles. You can easily see it in action by drawing “impossible” quads, perhaps using a heightmap.