A faster way to draw a square

Nibbie
Posts: 1
Joined: 2010.11
Post: #1
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()
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #2
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.

"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!
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #3
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! Wink

My uDevGame entry can draw hundreds of GL_QUADs per frame at 75fps on my machine, and I'm not doing anything clever.

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2010.11
Post: #4
No, I'm not worried, I only have 8 4 sided rectangles Grin . 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 Grin I am doing the best thing.
Quote this message in a reply
Member
Posts: 148
Joined: 2003.03
Post: #5
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..Blink
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #6
Quote:Originally posted by MacFiend
using triangle strips could improve overall rendering speed
They do for two reasons:

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!
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #7
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?

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #8
Quote:Originally posted by NCarter
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.
Yeah, 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.

"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!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Want good color interpolation for my square Najdorf 2 4,020 Nov 22, 2009 10:11 PM
Last Post: Najdorf
  Trying to make a square... there's a triangle! TimMcD 4 3,874 Jun 2, 2009 03:41 PM
Last Post: AnotherJake
  texture no square surface kendric 7 4,548 Mar 20, 2009 05:26 PM
Last Post: kendric
  Faster Sprites? Blacktiger 4 3,127 May 3, 2007 04:30 PM
Last Post: AnotherJake
  Non-square, non-POT, hardware-accelerated surfaces... NekoYasha 13 5,844 Oct 25, 2005 03:06 PM
Last Post: NekoYasha