A faster way to draw a square
Is there any faster way to draw squares? Would it be faster to draw a map in triangles?
Code:
int size=16
glBegin(GL_POLY)
glVertex3f(0.0, 0.0, 0.0)
glVertex3f(0.0, size, 0.0)
glVertex3f(size, size, 0.0)
glVertex3f(size, 0.0, 0.0)
glEnd()
GL_QUADS would be faster (doesn't have to think about how many points are involved), but if you have large numbers of such quads that share vertices, a much faster method is converting to triangles and using the method discussed in this thread.
That data is over a year old though, there may be an even faster way now.
That data is over a year old though, there may be an even faster way now.
"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat
Bring Alistair Cooke's America to DVD!
Depending upon what you're doing, GL_QUAD may be the simplest, quickest solution. Are you really writing a Pong game as you mentioned in that other thread, or were you joking? If you meant it, don't worry about rendering speed, because you're unlikely to be pushing the graphics card very hard unless you do the best looking version of Pong ever! 
My uDevGame entry can draw hundreds of GL_QUADs per frame at 75fps on my machine, and I'm not doing anything clever.

My uDevGame entry can draw hundreds of GL_QUADs per frame at 75fps on my machine, and I'm not doing anything clever.
No, I'm not worried, I only have 8 4 sided rectangles
. I just want to start well and work from that. It would be better to use the best way from the start so later when I use more the 8
I am doing the best thing.
. I just want to start well and work from that. It would be better to use the best way from the start so later when I use more the 8
I am doing the best thing.
If you're going to start off the best way possible, then I'd say use triangles, since it seems that triangles are a(/the most?) common primitive used when it comes to more advanced things such as collisions, culling, etc. So it's good practice to use triangles as you will most likely be running into them a lot in the future. Also I think using triangles will give your objects a much nicer look opposed to using quads, and using triangle strips could improve overall rendering speed, but don't quote me on that..
Quote:Originally posted by MacFiendThey do for two reasons:
using triangle strips could improve overall rendering speed
1. They reduce the amount of data you need to give to OpenGL
2. They allow graphics cards to keep a three-element transformed vertex cache.
While we're on the subjectk, when using glDrawElements you can form a more flexible type of triangle strip where each new triangle can be split off either open side of the previous one (either a strip or a fan). This is (almost?) as efficient as regular left/right triangle strips, but you can encode a wider range of topologies in a small number of strips. It is important that the new vertex is the last of the three triangle vertices though.
"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat
Bring Alistair Cooke's America to DVD!
If you're only rendering single quads (like I do in Yoink), there's no speed difference between GL_QUAD, GL_TRIANGLE_FAN and GL_TRIANGLE_STRIP as far as I can tell. Also, using glDrawElements() is no faster on single quads.
However, I imagine you could write a rendering mechanism which caches the quads as you send them. Once its cache is full, you could use glDrawElements() on a large number of quads simultaneously. I've never tried it, but I expect there would be a reasonable speed increase.
Any thoughts, anyone?
However, I imagine you could write a rendering mechanism which caches the quads as you send them. Once its cache is full, you could use glDrawElements() on a large number of quads simultaneously. I've never tried it, but I expect there would be a reasonable speed increase.
Any thoughts, anyone?
Quote:Originally posted by NCarterYeah, the array setup overhead is more than the function call overhead you save. I wouldn't use glDrawElements with less than at least a couple dozen polys.
If you're only rendering single quads (like I do in Yoink), there's no speed difference between GL_QUAD, GL_TRIANGLE_FAN and GL_TRIANGLE_STRIP as far as I can tell. Also, using glDrawElements() is no faster on single quads.
"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat
Bring Alistair Cooke's America to DVD!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Want good color interpolation for my square | Najdorf | 2 | 3,417 |
Nov 22, 2009 10:11 PM Last Post: Najdorf |
|
| Trying to make a square... there's a triangle! | TimMcD | 4 | 3,397 |
Jun 2, 2009 03:41 PM Last Post: AnotherJake |
|
| texture no square surface | kendric | 7 | 3,883 |
Mar 20, 2009 05:26 PM Last Post: kendric |
|
| Faster Sprites? | Blacktiger | 4 | 2,759 |
May 3, 2007 04:30 PM Last Post: AnotherJake |
|
| Non-square, non-POT, hardware-accelerated surfaces... | NekoYasha | 13 | 5,306 |
Oct 25, 2005 03:06 PM Last Post: NekoYasha |
|

