Compiled Vertex Arrays and Octree

Started by
15 comments, last by Spearhawk 21 years, 4 months ago
quote:Original post by Basiror
id render such a terrain with triangle strip vertexarrays


Yeah that's how I do it, I just used triangles as an example as it's easier to follow.

To use triangle strips, you have to render across in one direction and then go to the next row and go back in the opposite direction and so on, with a redundant vertex at the end of each row. That way each 'patch' of terrain is rendered as a single strip. Of course, tri strips are MUCH faster than just plain old triangles

One thing to remember though, if you use an octree, you can't split a tri strip into separate triangles so you need to be careful where a strip crosses the boundary into other nodes or you might end up drawing each strip several times (think about it )

[EDIT]
This is a good reason to use a quadtree for a simple heightmap based terrain.
[/EDIT]

______________________________

Don't ask me, I'm just the code monkey

[edited by - BLUECAT on October 25, 2002 2:06:19 PM]
______________________________DGDev - The Delphi Games Development Community
Advertisement
>>Of course, tri strips are MUCH faster than just plain old triangles<<

true usually, though personally ive just ditched tri strips for plain old triangles for the terrain in my game

>>One thing to remember though, if you use an octree, you can''t split a tri strip into separate triangles so you need to be careful where a strip crosses the boundary into other nodes or you might end up drawing each strip several times (think about<<

make each node in your octree/quadtree contain one strip (no more no less)

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
I'm been trying to make my engine work with the vertex array using triangle strips, but I run into a problem that I can't understand why it appears.
It looks like it drawing to many trinagles. The first picture below is taken from above and the second from below.

Edit: Img no longer on the server
Edit: Img no longer on the server

(The rectangle in the middle and to the side is just part of the GUI).

I'm using GL_CULL_FACE GL_CCW.

Init code:

    // Create the vertex and texture cordinate arrayvertexArray = new float[mapWidth * mapWidth * 3];textArray	= new float[mapWidth * mapWidth * 2];// Init the vertex and texture coord arrayfor(y = 0; y < (unsigned)mapWidth; y++){	for(x = 0; x < (unsigned)mapWidth; x++)	{		// Calculate the vertex		vertexArray[j]	 = (float)x * scale;		vertexArray[j+1] = bitmap->Image((mapWidth * y) + x) * heightScale;		vertexArray[j+2] = (float)y * scale;		// Calculate the texture coordinte		textArray[i]   =  (float)x / (float)mapWidth;		textArray[i+1] = -(float)y / (float)mapWidth;		j += 3;		i += 2;	}}// Create the indices arrayindex = new unsigned short int[squareHeight * squareWidth * 2 + squareHeight + 1];j = 0;	// Reset the counter var// Init the indices arrayfor(y = 0; y < squareHeight; y++){	if(forward == true)	{		for(x = 0; x < squareWidth; x++)		{			index[j] = ((mapWidth * y) + x);			index[j+1] = ((mapWidth * y) + x) + mapWidth;			j += 2;		}	}	else	{		for(x = squareWidth; x > 0; x--)		{			index[j] = ((mapWidth * y) + x);			index[j+1] = ((mapWidth * y) + x) + mapWidth;			j += 2;		}	}	index[j] = ((mapWidth * y) + x);	j++;	forward = !forward;}index[j] = ((mapWidth * squareHeight) + x);  Drawing code:      glVertexPointer(3, GL_FLOAT, 0, vertexArray);glTexCoordPointer(2, GL_FLOAT, 0, textArray);glDrawElements(GL_TRIANGLE_STRIP, squareWidth * squareHeight * 2 + squareHeight + 1,			  GL_UNSIGNED_SHORT, index);    


What am I doing wrong? To me it looks like the row isn't reversed, and thus it jumps down to 0 and stars drawing the tringale form there, but I am reversing it. I been trying to figure it out for a long time now but I just cna't seem to nail it donw. So any help would be greatly aprishiated.

Thanks in advance
Leon Ljunggren


[edited by - Spearhawk on December 11, 2002 4:43:54 PM]
If you email me the whole thing I''ll see what I can do

I use Delphi usually but I can compare yours with my code and see what it does differently.

Can''t see anything obvious from the code you posted, it would be better if I could see it in action.



______________________________

Don''t ask me, I''m just the code monkey
______________________________DGDev - The Delphi Games Development Community
quote:Original post by BlueCat
If you email me the whole thing I''ll see what I can do


Hehe, thanks but i got it to work a while ago (well, actuly I didn''t get it to work but I found out that doing many tristrips was just as fast as a single one). I was just looking through old posts and notice that the imagines had been replaced by others so I edited the post, not realizing it would appear at the top again.

It look quite fine now actuly. I decided to go with a quadtree, as you recomended, and added frustum culling to that. So now I get a nice and stable fps on about 90. Now I''m only looking into using the GL_NV_vertex_array_range in order to speed it up some more.

Screenshot


Thanks for the help

You''re welcome!

Looks nice BTW
______________________________DGDev - The Delphi Games Development Community
well i don t split my polygons when they intersect 2 octrees

i assign them to the octree node in which the center of the polygon lies i can neglect that because i use fog to hide the last 256 units so it doesnt matter
http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement