Skip to main content
GameDev.net gamedev.net
🔒 Locked

Vertex array question

Started by alnite Nov 18, 2004 at 7:46 PM 9 replies 750+ views
Original Post
alnite
alnite
I am learning vertex array now and have a few questions [totally]. Just to make it simple, I created a square patch of 4x4 vertices (or 9 quads). I call glDrawArrays() in GL_POINTS mode to draw the vertices and the vertices turns out OK. I see 16 dots on the screen. Now I am going to turn these dots on the screen to a solid square. I remember people saying that triangle strip is the fastest way to render meshes, but I am not sure how I am going to render a 4x4 square in one call with GL_TRIANGLE_STRIP. The best possible solution I can come up is to render each row/column separately. Or, I can switch to GL_TRIANGLES and render them in one call, but that would mean each vertex is rendered multiple times. This project will eventually turn into a terrain engine. So I am really concerned with the speed. Should I be persistent with GL_TRIANGLE_STRIP or should I go with GL_TRIANGLES? How do people normally render their meshes? edit: I think I got confused with the order the vertices are rendered. Take a look at this illustration: That's how you normally render triangle strips, right? I have read some tutorials that it would just proceed rendering vertex[0], vertex[1], vertex[2], ... vertex[n]. At the end of the row, you are supposed to go back to the beginning, and "reset" your triangle strip to start with vertex[0] and vertex[12]. You can't just keep going on otherwise a big triangle will cover your entire plane like this: This is the reason why I come up with rendering each row/colum separately. Tell me I am wrong. I still don't understand how you can render a bunch of vertices with no particular order with triangle strips. [Edited by - alnite on November 18, 2004 8:57:20 PM]
alnite
alnite
Quote:
Original post by Foxostro
Render rows of triangle strips back and forth, joining them with degenerate triangles.

http://www.gametutorials.com

So that means there is one extra triangle (rendered as a line) at the end of every two rows?
Myopic Rhino
Myopic Rhino
There are actually two degenerate triangles at the end of every row. Look at DigiBen's code in the tutorial he linked to and try drawing it out by hand using only 6 or 9 vertices (2 strips). And the degenerate triangles aren't drawn as lines; OpenGL shouldn't draw them at all, since they are zero-area.
Myopic Rhino
Myopic Rhino
Here's a little sketch:
0---3---6| / | / |1---4---7| / | / |2---5---8
You'd draw this using glDrawElements (you can't do this with glDrawArrays) with an index array that looks like:

0, 3, 1, 4, 2, 5, 8, 5, 7, 4, 6, 3

This would produce the following triangles:

(0, 3, 1)
(3, 1, 4)
(1, 4, 2)
(4, 2, 5)
(2, 5, 8) <- degenerate
(5, 8, 5) <- degenerate
(8, 5, 7)
(5, 7, 4)
(7, 4, 6)
(4, 6, 3)
EvilCrap
EvilCrap
here is how i do it, where vx is a vertex, and three verticies are a triangle, and two vertices are the extra components of a degenerate, or linking triangle:
(v1-v2-v3)-(v3-v4)-(v4-v5-v6);
zedzeek
zedzeek
use quad strips then u dont need any degenearants!

anyways for performance, if u use GL_TRIANGLES just right theres prolly not gonna be any difference at all (certainly not in a real world app)
_the_phantom_
_the_phantom_
indexed triangle lists is the prefered method for ATIs hardware (as long as its kept in strip order), while NVs apprently prefer indexed triangle strips, however at the end of the day the speed difference between the two systems is, these days, likely to be tiny.

Teh biggest reason to use gl_triangle_strip was to keep the size of data transfers down, however if you use a VBO this is a non-issue anyways and depending on your target hardware even doing it from a standard VA shouldnt be an issue. Also as long as its indexed the extra 2 verts wont be re-transformed as the post-T&L cache on the cards will have a copy (thus the strip order to take proper advantage of it).
alnite
alnite
Ah thanks. I got it working just now.

Quote:
Original post by Myopic Rhino
And the degenerate triangles aren't drawn as lines; OpenGL shouldn't draw them at all, since they are zero-area.

So, OpenGL doesn't process the degenerate triangles because they have zero area? Does that mean the degenerate triangles can be omitted? Doesn't OpenGL still need to calculate normal, texture coord, etc in degenerate triangles?
Ademan555
Ademan555
well, you know their purpose right? their there to allow triangle strip continuity. I honestly dont get the entire concept of how to do them, but i also think its possible for them to get drawn as lines because... well... floats are innacurate... and unless you copy over the info (which you probably would do) you ARE at risk of getting a line (unless openGL has an epsilon)

woo, ramble ramble ramble pointless post

-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
Myopic Rhino
Myopic Rhino
You have to use degenerate triangles in order to have continuous adjacent strips. If not, you go back to your original problem. The fact that they aren't drawn is the whole point of using them in the first place. Assuming that your strips are reasonably long, the overhead is negligible. The OpenGL driver should be able to detect and stop processing them early in the pipeline, as well. Note that even though it's rejecting them, they DO have an effect: they essentially allow you to have your strips "turn the corner".

Also, if you're using glDrawElements, what Ademan555 said about floating point precision is wrong. OpenGL wouldn't be comparing two floating point numbers; it'd be comparing two integer indices.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.