Sign in to follow this  

terragen and directx

This topic is 3626 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

Hi, I have terragen 2 (free version) and 0.9. I want to create terrain to load into directx c++. To do this i see the terragen files are saved as .tdg and i believe i need it in RAW format. q)How to I get the terragen files in a format I can load into directx? q)I need to create a height map with terragen yes as directx can handle this?

Share this post


Link to post
Share on other sites
I've never used terragen, so I can't tell you how to make it save the file in .raw format. I can tell you, however, that Direct3D doesn't know anything about heightmaps or terrain, so you'll have to implement that yourself. Here's one tutorial that will show you how.

Share this post


Link to post
Share on other sites
Hi,

i have a directx book that says you need to create a height map saved in raw format. Directx can load this in.

I dont care what software can do this as i see terragen is popular but there may be better ones i dont know.
I dont want to create 10000 triangles by hand to represent the terrain and create textures for all so i look for software that can do this (for free initially)

i will check your website

Share this post


Link to post
Share on other sites
hi,

you can import your terragen terrains into blender,
which is a freeware 3d editing software.

blender: http://www.blender.org
ter2blend: http://home.pacbell.net/c_keith/projects/blender/misc/Terragen.html

with blender, you can export them as .x file.

have phun, shrooms

Share this post


Link to post
Share on other sites
hi,

Why would i do that as wouldnt i lose a lot of quality by importing terragen file into blender to make a .x file?

q) does terragen (or anything else)create the terrain with textures or color? for directx i need to know this information and how to get access to colors used or textures used. Just getting a RAW file doesnt tell me this information

Share this post


Link to post
Share on other sites
is there a common way to render terrain? i was told to use a terrain app and export as RAW then load into directx? i have code on how to do this and a working program on such a method

Share this post


Link to post
Share on other sites
i used terragen to export a landscape 8 bit raw file landscape and import this into directx. Th landscape is nothing like the one i created in terragen and even when i import the same raw file back in terragen it has completely changed and i am frustrated.

When people create terrain for games are they really creating the whole thing in photoshop or 3dsMax or no set method? I dont want to waste days on unproved techniques nobody uses.


q)do i create a RAW file or .x file with terrain? what is the difference?

terrain making seems to be a grey area (and greyscale)in gameplay with directx

Share this post


Link to post
Share on other sites
The RAW file you're exporting is probably a grey scale height map of the terrain you created in Terragen.

What you have to do now is in directx, create a vertex buffer with a width and height equal to the width and height of your image. Then you manually adjust each vertex to the height that is saved in your height map.

Share this post


Link to post
Share on other sites
You can have terregen export the heightmap data in their native *.ter file format, and create a simple parser for it. This is what I am currently doing, and it works quite well. The best benefit is that it isnt *.raw.

I can give you my current codec, if you like. PM me if you are interested. It is API independent.

If you would like more information, this should help.

Hope this helps!

Share this post


Link to post
Share on other sites
the problem with terragen is that when i import again my saved RAW file it is different. I am not saving what i am creating with this product hence the confusion.

what i was after was a common approach to terrain building. after that then i will want to have a look at your stuff.

is it more common to have the terrain imported as an .x file?

Share this post


Link to post
Share on other sites
Hi mate,

I would also like some of the answers to the questions you have brought up!

This is because I am also going to be in the same shoes as you are now soon.

At the moment i have just started with direct3D in the last few weeks after doing a few things with directX in 2D.

But soon I am also going to create my terrain and I also want to know the best route for this, from my understanding and from some help from this forum in my last topic post I have discovered that you can go in a variety of different ways!

Im not sure which method is the best or which one gets used most often.

1. You can create a level in a modelling package like 3DSMax and then export the scene as .x file for direct X to read in. But this is usually only good for small areas and offers no scene interaction.

2. You can create a grey scale image (.RAW i think) and read that into directX program. The Tutorial in the second post in this topic explains this route with how to texture also.

3. Create a level in a map editor like HAMMER (Source Engine) or Unreal Editor 3 and then read that into direct X as a ".bsp" which i havnt been able to find out how to do yet.

4. Which is essentially what your trying to do is use terragen to create a map and read the data in from this. Ive never used this program before but it seems very effective if it can be done without too much trouble!
Again the tutorial in the second post mentions that he used terrgen to create his .RAW and texture!


Anyhow let me know how you get on and if you manage to find anything else out that can also help me in my search!

Share this post


Link to post
Share on other sites
Quote:
Original post by jagguy2
the problem with terragen is that when i import again my saved RAW file it is different. I am not saving what i am creating with this product hence the confusion.

what i was after was a common approach to terrain building. after that then i will want to have a look at your stuff.

is it more common to have the terrain imported as an .x file?


In what way is it different?
Is it just creating a lower res height map then what you see in Terragen?
Is there any export options so that you can save a larger height map if this is the case?

Share this post


Link to post
Share on other sites
a word of warning with terragen and the tutorial in 2nd post . teragen v2 doesnt support raw eports and terragen v .9 (previous) also fails to do this. In terragen v.9 it does have an export raw file option but it doesnt work properly as you get a different file when you import it again.
I have been on the terragen forums asking about this and yes it has a bug with raw files.

So use world machine instead.

The tutorial in 2nd post doesnt properly explain how to load in a raw file and use it with a camera as you still need a of of changing(by yourself) to the code which in total is well over 1000 lines of code in 10files and impossible to learn IMHO. You only get a distant view of an terrain you can properly interact with, NO GOOD!

I have a program from F.Luna on how to do this in 500 lines and i can move across the terrain and load any raw file in with just a few simple parameters. So i can get it to work. However i lose a lot of quality which is the problem.

I think the best way is to have a simple terrain(raw) and add mountains /water from a 3d model program. a combination if you like but correct me if a better way.

Share this post


Link to post
Share on other sites
My personal recommendation is to stay away from using *.raw files. They mean nothing, seriously. *.raw files are just raw binary - they do not have any format or structure to them at all. This is the same problem with *.dat and *.bin files...They are to generic to be useful, and can contain anything. There is no possible way to test if the file is valid either.

This is a benefit of using a structured format (such as Terregans *.ter codec) over plain *.raw files.

Just export the terrain (Terragen saves it as a *.ter), and parse it in your game. Copy the heightmap data loaded from the file, and use it for your terrain. There are other methods besides this, if you do not want to use Terragens *.ter file format.

Share this post


Link to post
Share on other sites
The preferred method is going to be to fore go the "raw" file and just write an importer for the "ter" files (or use an existing one, like Crypter has said twice now.)

Find the file format description, the author of the program probably makes it available with the program or on their site, then write a loader for it. Just like loading a bitmap file from scratch. As long as the format isn't compressed, writing a loader is almost always straight forward once you have the spec.

Share this post


Link to post
Share on other sites
IT is a good idea but i have no idea where to start to write a loader for a ter file!

How is this simpler than a raw file? as at least with a raw file i have code to load it in.


Share this post


Link to post
Share on other sites
Quote:

IT is a good idea but i have no idea where to start to write a loader for a ter file!

File format specification

If you know how to read binary files, simply parse the file for its many section names...

The only thing the link does not directly state is the file header information.

The first 8 bytes should = "TERRAGEN"
The second 8 bytes should = "TERRAIN " < Note the space


The sections start immediately after the header strings.

Quote:

How is this simpler than a raw file?

No one said it would be simpler, however it is better. Remember: *.raw files have no structure whatsoever - they mean nothing. The data can contain anything. This makes it almost impossible to help anyone using *.raws, as we do not know the file structure being used.

*.ter files have a documented structure to them.


[Edited by - Crypter on January 8, 2008 9:31:36 PM]

Share this post


Link to post
Share on other sites
when loading in a large volume of data is it better to use a mesh, X file or vertice buffer? It says textures but the code is not straightforward.

I ask because i am wanting to convert this vertice buffer with colors to textures and it seems easier if i use a mesh so i can match up subsets with texture array.


hr = D3DXCreateTexture(
l_device,
texWidth, texHeight,
0, // create a complete mipmap chain
0, // usage
D3DFMT_X8R8G8B8,// 32 bit XRGB format
D3DPOOL_MANAGED, &l_tex);

if(FAILED(hr))
return false;

D3DSURFACE_DESC textureDesc;
l_tex->GetLevelDesc(0 /*level*/, &textureDesc);

if( textureDesc.Format != D3DFMT_X8R8G8B8 )
return false;

D3DLOCKED_RECT lockedRect;
l_tex->LockRect(0/*lock top surface*/, &lockedRect,
0 /* lock entire tex*/, 0/*flags*/);

DWORD* imageData = (DWORD*)lockedRect.pBits;
for(int i = 0; i < texHeight; i++)
{
for(int j = 0; j < texWidth; j++)
{
D3DXCOLOR c;

// get height of upper left vertex of quad.
float height = (float)getHeightmapEntry(i, j) / l_heightScale;

//hard to match up here with this code colors to different textures?

if( (height) < 42.5f ) c = BEACH_SAND;
else if( (height) < 85.0f ) c = LIGHT_YELLOW_GREEN;
else if( (height) < 127.5f ) c = PUREGREEN;
else if( (height) < 170.0f ) c = DARK_YELLOW_GREEN;
else if( (height) < 212.5f ) c = DARKBROWN;
else c = WHITE;

// fill locked data, note we divide the pitch by four because the
// pitch is given in bytes and there are 4 bytes per DWORD.
imageData[i * lockedRect.Pitch / 4 + j] = (D3DCOLOR)c;
}

Share this post


Link to post
Share on other sites
i think i might learn blender and create an x file as this is too time consuming to solve the textures problem with colors from above code as i would have to re write too much.

Unless anyone knows a simple solution i would need to create a mesh file to get textures on each subset. I might as well create an x file.

Share this post


Link to post
Share on other sites
ok i have changed the code to load a mesh file instead of vertexbuffer and it displays textures instead of colors.

It runs 10 frames per second and terrain file to load is 64X64. With colors the FPS is 60 .

Also i do get a color appearing covering part of the screen i cant get rid but i have had enough with it as i need another approach to terrain with textures and smaller sizes.

Share this post


Link to post
Share on other sites

This topic is 3626 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this