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

## Recommended Posts

I have searched the forums and found something(a bit advanced for me??). But since im a total newb i want something easier. So is there a tutorial out there for me? I have started with DX10 (Wendy Jones's book), i know how to load texture and make vertices for a generated map(based on math, heigh random with limit. The output landscape is boring and i want to create more fun maps for my DX10 applications. [EDIT] I have been at Chad Vernons place, http://www.chadvernon.com/blog/tutorials/directx9/terrain-generation-with-a-heightmap/, its a very good tutorial i think but first of all its based on DX9, and i want to start right on DX10. In addition he builds up an framework and when you get to the heighmap part(or skip right to it) it gets complicated. So anybody? :-)

##### Share on other sites
Wow... being the "new guy on the block" is fun. Lots of ppl read my post but non replies!

ANYWAYS... been banging my head to the wall a couple of times. I dont get it to work. Gonna post some code:

std::ifstream ifs;
ifs.open("CUheightap.raw", std::ios::binary);

for(int z=0; z < NUM_VERTSX; ++z)
{
for(int x=0; x < NUM_VERTSX; ++x)
{
vertices[x + z * NUM_VERTSX].Pos.x = (float)x * CELL_WIDTH;
vertices[x + z * NUM_VERTSX].Pos.z = (float)z * CELL_HEIGHT;
vertices[x + z * NUM_VERTSX].Pos.y = ifs.get();
vertices[x + z * NUM_VERTSX].Color = D3DXVECTOR4(1.0, 1.0f, 1.0f, 0.0f);
vertices[x + z * NUM_VERTSX].Tex.x = x / (float)NUM_VERTSX;
vertices[x + z * NUM_VERTSX].Tex.y = z / (float)NUM_VERTSY;
}
}

I was hoping this would do the trick... Could anybody guide me?

##### Share on other sites
Its not that your new don't worry about that, its that most people are only familiar with d3d9 and down. Depending on your experience height maps could be a little advanced but I havn't done much D3D10 at all. I'm sure somone here will know :)

##### Share on other sites
well... maybe im wrong, but the method getting the hightmap is more c++ in general. Should be able to apply to both(D9 and D10), but thank for the respons! (started to wonder if the forum was dead :P:P haha)

##### Share on other sites
Also what specifically doesn't work?

##### Share on other sites
Unless you're going for advanced effects (e.g. procedural or 'vertex texture fetch') only available in D3D10 then pretty much any heightmap and terrain article you can find for D3D9 will also work for D3D10.

The basic ideas behind a height-mapped terrain haven't changed substantially in 10 years - sure, there are more optimal ways of doing it and ways of generating bigger/prettier results but really the basic idea of generating geometry (both the vertices and indices) is unchanged.

I wrote a couple of journal enties on optimal terrain rendering in D3D9. I would imagine it'll be easy enough to translate to D3D10 and/or extract the geometry manipulation code...

hth
Jack

##### Share on other sites
well... its official, im a newb! im going to share this information with you all, but this is actually going to hurt my reputation around here alot.

So here it is: I did not store the .RAW file i was using in the right directory!

(yes, i know what you are thinking: oh my god, please shot me in the foot).

Maybe it was something else. I rewrote something, checked my dirs and whola... it works 50%. i say 50% because from a 2D perspective height only works along the x-axis. Going to supply a screen.

http://larsey.net/galleri/Humor/screen.jpg

and here is some code:

std::ifstream ifs;

ifs.open("heightmap.raw", std::ios::binary);

// Fill the vertices array with the terrain values
for(int z=0; z < NUM_VERTSX; ++z)
{
for(int x=0; x < NUM_VERTSX; ++x)
{
vertices[x + z * NUM_VERTSX].Pos.x = (float)x * CELL_WIDTH;
vertices[x + z * NUM_VERTSX].Pos.z = (float)z * CELL_HEIGHT;

// Adding height from the .RAW file(heightmap)
vertices[x + z * NUM_VERTSX].Pos.y = ifs.get();

// Create the default color
vertices[x + z * NUM_VERTSX].Color = D3DXVECTOR4(1.0, 1.0f, 1.0f, 0.0f);

// Create the texture coordinates for the terrain
vertices[x + z * NUM_VERTSX].Tex.x = x / (float)NUM_VERTSX;
vertices[x + z * NUM_VERTSX].Tex.y = z / (float)NUM_VERTSY;
}
}

I may be asking alot, but what seems to be the problem now?

Also want to thank for all the response i got! :X

##### Share on other sites
Tell us what format your raw heightmap is stored in, because the line where you read the next value from you map seems a little suspicious. I suppose that the Pos variable stores 3 floats x, y and z, so y scales from -127. to 127. inclusive. You'll get reliable results only if the format is something like 8 bits-per-pixel in a single channel (for example a grayscale map).

EDIT: as a little clarification, your map might appear as grayscale, but could internally be stored as an 32-bpp RGBA map (depending on how it was saved), which might explain those periodical 'lanes' in your screenshot.

Also, some code tidying:
1) first line, I guess you meant NUM_VERTSY instead of NUM_VERTSX (see third line from the bottom);
2) use of a reference
3) third and fourth lines from the bottom, -1, because 0 <= x < NUM_VERTSX (same for z)

std::ifstream ifs;ifs.open("heightmap.raw", std::ios::binary);// Fill the vertices array with the terrain valuesfor( int z = 0; z < NUM_VERTSY; ++z ){  for( int x = 0; x < NUM_VERTSX; ++x )  {    // You can use a pointer here (vertex = *nextVertex++) or even an iterator    Vertex & vertex = vertices[x + z * NUM_VERTSX];    vertex.Pos.x = (float)x * CELL_WIDTH;    vertex.Pos.z = (float)z * CELL_HEIGHT;    // Adding height from the .RAW file(heightmap)    vertex.Pos.y = (float)ifs.get();    // Create the default color    vertex.Color = D3DXVECTOR4( 1.0f, 1.0f, 1.0f, 0.0f );    // Create the texture coordinates for the terrain    vertex.Tex.x = (float)x / (float)( NUM_VERTSX - 1 );  // -1, because 0 <= x < NUM_VERTSX    vertex.Tex.y = (float)z / (float)( NUM_VERTSY - 1 );  // as above  }}

##### Share on other sites
i get an error on

Vertex & vertex = vertices[x + z * NUM_VERTSX];

error C2065: 'Vertex' : undeclared identifier;

Updating the rest of the code gives no solution to the problem :( but thank you for your response.

About .RAW file, how should it be saved? 8 / 16 / 32 bit? Interleaved or Non-Interleaved? PC IBM or MAC?

in advance, thanks for the response

##### Share on other sites
Finally:

http://larsey.net/galleri/SpillMekking/mapfinal.jpg

My problem was that i was using a 1024x1024 map when the map itself only was 256x256. But i fixed the problem as you can see on the result above. And to be my first heightmap im satisfied with it.

I get overflow if i try to reach up to 1024 (512, 1024). Something is not able to hold 1024x1024 in my sourcecode. But as I said im happy with the result and will be taking another look at it when ive done some other things(user controller and so on).

Wanna thank all of you for all your response!

• 17
• 11
• 15
• 9
• 49
• ### Forum Statistics

• Total Topics
631393
• Total Posts
2999774
×