PDA

View Full Version : Using QUAD_STRIP or TRIANGLE_STRIP ?



Structural
01-09-2003, 01:05 AM
I have never in my life used a quad or triangle strip so I was wondering how and which one I should use for a terrain/ripple like shape.

My idea is to make a 2D grid array that represents the height of the terrain at a certain gridpoint.

Example:



int a[][] = {
{ 0, 1, 0, 1, 0 },
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 1 },
{ 0, 1, 1, 1, 0 }

};

I was actually thinking that a QUAD strip would cause convex (if that's the right word for it, QUAD with non-coplanar points) quads and would mess up the view.
On the other hand I believe that the triangle solution would give problems with the order of giving the vertices to OGL. The order of giving the tri's to OGL should be different in the corners of the terrain.

In my book (OpenGL game programming) I have also read a bit about NURBS and curved surfaces. Would this be an option for rendering this? I don't want this to effect framerate too much so I'm having doubts
(plus I don't have a clue if this is physically possible with NURBS/curved surfaces).

Any help/tips would be very appreciated.

Thanks!

MickeyMouse
01-09-2003, 02:45 AM
I would definitely use triangle strips because of what you mentioned, that is it would look weird with quad strips for any not flat quad.

What's the problem with order of elements in triangle strip?
You can easily send whole grid with one call to OpenGL using glDrawElements(...)

Structural
01-09-2003, 03:02 AM
Originally posted by MickeyMouse:
I would definitely use triangle strips because of what you mentioned, that is it would look weird with quad strips for any not flat quad.

What's the problem with order of elements in triangle strip?
You can easily send whole grid with one call to OpenGL using glDrawElements(...)


AS you can see the diagonals on the corners are different:
Diagonal on upperleft corner goes from upperright to lowerleft and the diagonal in the upperright corner goes from upperleft to lowerright. That's what's bugging me for the algorithm I have in the back of my head...

And what do you mean by giving the grid to OGL in one go with drawelements? You mean like making a 3D array and giving that to OGL? or do you mean transferring all data to a temporary array? Don't I have to re-order the vertices before I give them to OGL (I might be missing something in my limited OGL knowledge) ?

MickeyMouse
01-09-2003, 03:55 AM
To be able to use single call to OpenGL you need to store all your vertices in one array.
Then in another single array store indices of triangle strip, so you can reuse verts that are used more than once (total - 4 http://www.opengl.org/discussion_boards/ubb/smile.gif )..
Calling glDrawElements(..) with that array as argument will do the job....

Anyway take a look at gamedev.net, there are tons of good articles http://www.gamedev.net/reference/list.asp?categoryid=40

gl!

Halcyon
01-09-2003, 11:10 AM
Yup, i agree with MickeyMouse! Use triangle strips to do your terrain. You save OpenGL a lot of potential work...well not really THAT much. If you use a quad strip where a 'segment' does not have all four vertices on a plane, OpenGL probably splits them into triangles anyway. It's more complicated to do some calculations when all the vertices are not on the plane. Plus anyway, the ordering of the vertices is the same for either one, so all you have to do is change the flag in glBegin(...) or glDrawElements(...).

For vertex array information, check out the second half of the second chapter of the red book. It has a very good explanation of them.

- Halcyon