Sign in to follow this  

need help with Loading Heightmaps

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

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[i] = in[i]; 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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Just use D3DX to load it up as textures. There is no point anyway in writing code to read a file format.

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
See if the loop is running, perhaps by setting a breakpoint, or using a Message box. It could be that it isnt even running the loop. For me whenever I do a <vector>.size() the compiler complains about the type is invalid, so I cast it to int

for ( int i = 0; i < (int)in.size(); i++ )

I dont know if it matters, but it seems to make the compiler happy.

The only other thing that can be happening is no info is being loaded into the in vector.

Share this post


Link to post
Share on other sites
Hi,

Are you sure NumVertices has a value?

I have rewritten your code slightly below and it works fine in place of my terrain loader, it should fill your height map as it does mine.



bool GObject::ReadRAWfile(const char *RAWName)
{
vector<BYTE> in;
ifstream inFile(RAWName, ios::binary);

// File invalid
if( inFile == 0)
return false;

// Read until EOF
while(!inFile.eof())
{
m_heightmap.push_back(inFile.get());
}

// Close file
inFile.close();

return true;
}







Hope that helped.

Share this post


Link to post
Share on other sites

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