Reading .raw files for height maps...

Started by
3 comments, last by Metal Typhoon 21 years, 8 months ago
shoudlnt this load a raw file ?? i keep gettin errors saying i cant access the blah huge number...


#define SIZE 1024

unsigned char MAP[SIZE*SIZE];

bool Load_RAW (char *filename, int size, unsigned char *Texture)
{
	FILE * File = NULL
	File = fopen (filename,"rb");

	if (File == NULL)
	{
		fclose (File);
		return false;
	}

	fread (Texture,1,(size),File);

	int result = ferror (File);

	if (result)
	{
		fclose (File);
		return false;
	}
	
	fclose (File);
	return true;
}

..................... som where on the code

Load_RAW ("Terrain.raw",SIZE*SIZE,MAP); 
 
thx in advance
Metal Typhoon
Advertisement
When you read in the file, you are only reading in 1 row of data. You want to do this:

fread (Texture,1,(size*size),File);

Edit: My bad. Got confused between function parameter "size" and the define "SIZE".

[edited by - Estese on August 14, 2002 1:38:43 PM]
"If I have seen farther than other men, it is because I have stood on the shoulders of giants." -- sir Isaac Newton
You should be more precise about your error, and where you call the code from.

Also, the above poster isn''t correct, as you specify the size argument properly.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
Hmm, I had the same problem...
fread()''s size parameters are short int, and you are trying to read 1024*1024=2^20 wich is larger than 2^16 (maximum number that can be retained using short). You should use something like

fread(texture,SIZE,SIZE,File);

This way both parameters (count and size) from fread are smaller than the maximum value. Oh, another thing: if you have to read something (size smaller than 2^16) it''s faster to use

fread(buffer,size,1,File);

than

fread(buffer,1,size,File);

Good luck!
Have FUN,FeeL E!
fread should take size_t as parameters, which as far as I know on VC++ is a 32 bit int.

What compiler are you using?

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

This topic is closed to new replies.

Advertisement