# Rendering a Heightmap

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

## Recommended Posts

Hey all, I've figured out how to READ a heightmap, but now i'm not sure how to create teh vertices for one. For now, I'm using a LineList (I hope to do a TriangleList next, and then a TriangleStrip once i understand those 2 other methods) I've already locked the vertex buffer and created it....etc... now I'm confused as to why this isn't working:
        For y As Integer = 0 To MapHeight - 1
For x As Integer = 0 To MapWidth - 1
ReDim Preserve Vertices(count)
Vertices(count) = New CustomVertex.PositionColored(map(x, y), Color.White.ToArgb)
count = count + 1
Next
Next

map is a Vector3 which stored the data read from the RAW file. When I render, I simply:
        dxDevice.VertexFormat = CustomVertex.PositionColored.Format
dxDevice.SetStreamSource(0, vBuffer, 0)
dxDevice.DrawPrimitives(PrimitiveType.LineList, 0, count-1) 'I say Count-1 becuase count is incremented in the last loop. Count - 1 is the same as mapHeight * mapWidth.


All I see is 1 line. That's IT! If I put in the value of (lets say) 6000, i see a TON of lines going everywhere, most of which originate from the center. My question is: Now that I've got my heightmap read, how must I create my vertices? -The Pentium Guy

##### Share on other sites
I'll bet there is a problem with how you set up the vertices. It sounds like you're overwriting them, so that when it renders you're left with only the last one.

I'd *highly* suggest you walk through your code and watch your loop counters *very* closely. Setting up a grid is easy once you figure you the nuances, but until then it's a nightmare. I'll bet money it's in how you set up the vertices, though. Too bad I have none [wink]

Mushu - trying to help those he doesn't know, with things he doesn't know.
Why won't he just go away? An question the universe may never have an answer to...[/

##### Share on other sites
I'm not overriding them :).

Redim Preseve Vertices(count)
the PRESERVE command preserves the data :).

##### Share on other sites
Quote:
 Original post by The Pentium GuyI'm not overriding them :).Redim Preseve Vertices(count)the PRESERVE command preserves the data :).

..overwriting.

Yes, you can still preserve the array (which, IMO, is very slow then just binding it once), but if you...
redim preserve myArray(0)myArray(0) = 2redim preserve myArray(2)myArray(0) = 4

That's the kind of overwriting I'm talking about. I'd suggest you use the locals viewer to make sure you have all the vertices set up properly, then assume that you're not rendering correctly.

As far as rendering is concerned, you can always try to render with drawprimitiveUP to see if the vertex buffer isn't made properly, and if that renders wrong, and the vertices are set up correctly, it's most likely a problem with you're renderstates or your matrices.

Make sure that your cameras are set up so that all the lines are in plain view. Make sure you're not culling them somehow. Make sure that the z-enabled is set to true. Check to see that you don't have any other wierd stuff going on.

But I still think it's in how you set up the vertices. Post that code in <source> tags.

Mushu - trying to help those he doesn't know, with things he doesn't know.
Why won't he just go away? An question the universe may never have an answer to...

##### Share on other sites
Heh, overwriting :). I really don't think I am.. I looked through the loop, it doesn't seem as if I am...

Whats drawprimitiveUP and how do i enable it?

What exactly do you mean by how I set them up, the code I posted was how I set them up right?

##### Share on other sites
Oh right - didn't see that. Some how mine is a lot longer [wink] but then again I'm using triangle lists, which increases the number of vertices sixfold!

Try using D3DPT_LINESTRIP, not D3DPT_LINELIST: line list draws lines such that

{0,1,2,3}->{0,1} {2,3}

But since you're only adding one vertex per line, when, if you're doing that then you need line_strip which does this:

{0,1,2,3}->{0,1} {1,2} {2,3}

And, actually, reviewing your code, I think I see a bigger problem:
Allow me to illustrate how you're setting out your vertices0  1  2 3  4  56  7  8Now, if we add in the lines as would be in D3DPT_LINELIST:0 - 1   2  - - -3   4 - 56 - 7   8Which is not what you want. Changing it to D3DPT_LINESTRIP probably won't help much either:0 - 1 - 2  - - -3 - 4 - 5  - - -6 - 7 - 8

What you're missing is the lines in between the lines: those that run along the z-axis. Now, I think you may have to set up another loop to put those in (its actually easier with triangle primitives, IMHO) or figure out some other way. But I think that might *actually* be the problem.

Sorry for being so slow on the intake.

DrawPrimitiveUP is just another rendering method:
object.DrawPrimitiveUP( _     PrimitiveType As CONST_D3DPRIMITIVETYPE, _     PrimitiveCount As Long, _     VertexStreamZeroDataArray As Any, _     VertexStreamZeroStride As Long)

is the SDK prototype. It basically just takes an array of vertices and renders them instead of taking a vertex buffer. It does not render them immediately, but batches the calls. Which makes it useful in different situations...

But I'd take a look at how you lay out your vertices; take a piece of paper and chart them. You may find some other way to do it or something else you missed... or a pot of gold! You'll never know until you try!

Mushu - trying to help those he doesn't know, with things he doesn't know.
Why won't he just go away? An question the universe may never have an answer to...

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632984
• Total Posts
3009715
• ### Who's Online (See full list)

There are no registered users currently online

×