Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Triangles vs. Quads?  (Read 902 times)
0 Members and 1 Guest are viewing this topic.
Offline zFollette

Junior Member


Exp: 2 years


I like jokes


« Posted 2014-01-22 03:20:18 »

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?

Humor will keep you alive.
Offline opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2014-01-22 03:22:11 »

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.

Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #2 - Posted 2014-01-22 03:25:25 »

Quads are bad.

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

But how would OpenGL render it?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline zFollette

Junior Member


Exp: 2 years


I like jokes


« Reply #3 - Posted 2014-01-22 03:30:27 »

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.

Humor will keep you alive.
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #4 - Posted 2014-01-22 03:36:20 »

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?

Offline zFollette

Junior Member


Exp: 2 years


I like jokes


« Reply #5 - Posted 2014-01-22 03:41:16 »

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.

Humor will keep you alive.
Offline trollwarrior1
« Reply #6 - Posted 2014-01-22 06:11:26 »

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.
Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #7 - Posted 2014-01-22 07:05:30 »

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

Offline StumpyStrust
« Reply #8 - Posted 2014-01-22 07:17:18 »

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.

Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #9 - Posted 2014-01-22 07:23:57 »

Quote
A quad is a 4 vertex quadrilateral primitive. The four vertices are expected to be coplanar; failure to do so can lead to undefined results.

A quad is typically rasterized as a pair of triangles. This is not defined by the GL spec, but it is allowed by it. This can lead to some artifacts due to how vertex/geometry shader outputs are interpolated over the 2 generated triangles.

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Danny02
« Reply #10 - Posted 2014-01-22 07:28:46 »

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
Offline Mike

JGO Wizard


Medals: 84
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #11 - Posted 2014-01-22 08:08:24 »

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 Smiley

Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Online princec

JGO Kernel


Medals: 389
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #12 - Posted 2014-01-22 10:03:44 »

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 Smiley

Offline gouessej
« Reply #13 - Posted 2014-01-22 10:27:26 »

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.

Offline kappa
« League of Dukes »

JGO Kernel


Medals: 77
Projects: 15


★★★★★


« Reply #14 - Posted 2014-01-22 10:42:15 »

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.
Offline theagentd
« Reply #15 - Posted 2014-01-22 12:46:17 »

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.

Myomyomyo.
Offline lcass
« Reply #16 - Posted 2014-01-22 15:53:04 »

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.
Offline wessles

JGO Wizard


Medals: 66
Projects: 4
Exp: 3 years


Profile picture isn't relevant.


« Reply #17 - Posted 2014-01-22 16:23:19 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
+---+
|   |
|   | GL_QUADS
|   |
+---+

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

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

Offline zFollette

Junior Member


Exp: 2 years


I like jokes


« Reply #18 - Posted 2014-01-22 18:04:13 »

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

Humor will keep you alive.
Offline theagentd
« Reply #19 - Posted 2014-01-22 21:25:23 »

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.
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.

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (63 views)
2014-09-21 02:42:18

BurntPizza (33 views)
2014-09-21 01:30:30

moogie (41 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!