Jump to content
  • Advertisement

Archived

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

dev578

Problem rendering terrain

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


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

Share this post


Link to post
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    3

4 5 6 7

8 9 10 11

12 13 14 15


And what you need is this:

0     1,4,6    7,10,12    13,16


2,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.

For your vertices:

0      1


2 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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!