need help with Loading Heightmaps

Started by
12 comments, last by Twitchy 18 years, 1 month ago
Ok so I'm creating a game in Directx and I want to create my terrain using heightmaps... I've managed to create an area using the x and z axis but I can't seem to load the heightmap properly for it to add the values into the y axis. I'm using visual studio.net 2003 c++, I'll show the code that I've got for loading the RAW file in: bool GObject::ReadRAWfile(const char *RAWName) { std::vector<BYTE> in(NumVertices); std::ifstream inFile(RAWName, std::ios_base::binary); if( inFile == 0) return false; inFile.read((char*)&in[0], in.size()); inFile.close(); m_heightmap.resize(NumVertices); for(int i = 0; i < in.size(); i++) m_heightmap = in; return true; } m_heightmap is a std::vector<int> declared in my class function. The program runs but when I debug it it doesn't seem to be loading in the data, as my m_heightmap remains empty after the for loop at the end. I have no idea why it isn't working. Can Someone please help
Advertisement
Just in a quick glance, It looks like you are loading an 8 bit raw file, are you saving your heightmap as 8 bit .raw?
There is no life without honor
yes I am
when I run the code it seems that in[] doesn't seem to get the values from the file at all.
Just use D3DX to load it up as textures. There is no point anyway in writing code to read a file format.
I would but unfortunately this is for a project and I'm not allowed to use D3DX as it does all of the work for you and the terrain will play a major part in my game.
My terrain system is about 1100 lines of code, of which approximately 10 are dedicated to loading the heightmap from file.

Hardly "all" the work.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Quote:Original post by Promit
My terrain system is about 1100 lines of code, of which approximately 10 are dedicated to loading the heightmap from file.

Hardly "all" the work.


I suppose your's is a much more complex terrain system, I just don't understand why mine doesn't load the file
Well first of all, does in hold the correct data?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
that's my main problem, when I debug through, it doesn't seem to store any information at all

This topic is closed to new replies.

Advertisement