Archived

This topic is now archived and is closed to further replies.

Metal Typhoon

Reading .raw files for height maps...

Recommended Posts

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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites