#### Archived

This topic is now archived and is closed to further replies.

# Problem rendering terrain

This topic is 5282 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Alright, here is what I have so far: int Tracker = 0; for( int x = 0; x < terrain.GetSize(); x++ ) { for( int y = 0; y < terrain.GetSize(); y++ ) { float z = terrain.GetCell( x, y ); pVertices[Tracker].x = (float)x; pVertices[Tracker].y = z; pVertices[Tracker].z = (float)y; pVertices[Tracker].color= 0xffffffff; Tracker+=1; } } First, it will take care of all the z''s in the x=0 row (variable y in the terrain generator), then it will shift x over one and take care of all the z''s in that row...etc. It works completely fine, I am just having a problem rendering it. If I do DeviceD3D->DrawPrimitive( D3DPT_POINTLIST,...); It will come out just fine, as points (it actually looks pretty cool I wan''t to draw the primitive with triangles, but it comes out really screwy. I need to switch the order in which pVertices gets filled, but I have no idea how. If anyone could help me out, that would be great. -Dev578

##### Share on other sites
It depends if you are wanting to render a strip or fan or indexed triangles etc. Normally I wouild expect to render terrain using indexed so you need an index buffer and you need to fill it with the indices of each vertex for each triangle,

##### Share on other sites
You''re either going to need to index into that list, or duplicate your vertices.

##### Share on other sites
What these guys are trying to tell you is that right now you have this (vertices are numbered):

0    1    2    34    5    6    78    9    10   1112   13   14   15

And what you need is this:

0     1,4,6    7,10,12    13,162,3   5,8,9    11,14,15    17(etc)

Then render using triangle list. Basically, you have to duplicate vertices because it''s not smart enough to determine "oh, this is a height field and I want to make triangles between all of the points"--you have to tell it what to make. The other option, which is a lot easier to read and think about but is a bit harder to implement is to use indices. Indices are stored using the IDirect3DIndexBuffer9 interface, and act like a vertex "table of contents" if you will.

0      12      3

You want to have two triangles. To do this, add these indices to your index buffer (note that we are rendering using triangle lists, not strips or fans, and that the function called must be "DrawIndexedPrimitive"):

0, 1, 2,2, 1, 3

"0,1,2" represents your first triangle. "2,1,3" is the second. This should be repeated throughout your terrain so that for each quad (set of 4 vertices) the two triangles created have the indices "n, n+1, n+width" and "n+width, n+1, n+width+1" where ''n'' is the top left-hand vertex and width is the number of *vertices* wide the terrain is.

This may be a bit hard to comprehend at first but I hope you get this gist of it.

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633420
• Total Posts
3011792
• ### Who's Online (See full list)

There are no registered users currently online

×