Skip to main content
gamedev.net
🔒 Locked

Height Map

Started by CodeMaster000 5 replies 200+ views
Original Post
CodeMaster000
CodeMaster000
I know I am probably doing this totally wrong, but I wanted to see if I could make something neat. In this code below I am roughly trying to load a raw image and use the values of each bit as the hieght to a vertex.
    
float MAP_COORD[8][8];


void Setup_Map_Height(char* MapImage)
{
	FILE* file;	
	file= fopen(MapImage, "rb");
	

	for (int y = 0; y < 8; y++)
	{
		for (int x = 0; x < 8; x++)
		{
			fread(MAP_COORD[x][y], 1, sizeof(char), file);	
		}
	}

	fclose(file);
}
    
it keeps saying that it can't convert to float from void* in the fread function. I am not sure how the the image bytes are stored but it is an 8x8 .raw picture (64 byte size). Any thought on this would be nice. [edited by - CodeMaster000 on December 15, 2002 10:28:32 PM] [edited by - CodeMaster000 on December 15, 2002 10:29:25 PM]
CodeMaster000
CodeMaster000
It still gives me the error:

error C2664: ''fread'' : cannot convert parameter 1 from ''float'' to ''void *''


I also tryed changing that float it is talking about to an unsigned char. It gave me the same message but replaced the word "float" with "unsigned char" lol
TravisWells
TravisWells
First of all your map is float MAP_COORD[8][8];
so you are reading char's, not floats.

Secondly MAP_COORD[x][y] should be &MAP_COORD[x][y].

I think you want to read chars, and then convert them to float.
You could do something like this:

char temp;
fread(&temp, 1, sizeof(char), file);
MAP_COORD[x][y]=(float)temp;


or you could just change MAP_COORD to a char, and do
fread(&MAP_COORD[x][y], 1, sizeof(char), file);
in the loop. Probably the best answer.

[edited by - TravisWells on December 15, 2002 10:51:53 PM]
CodeMaster000
CodeMaster000
OK WOW does it work. Something is wrong with the way I am rendering the map but I should be able to work that out. (Jagged quads shooting upward) I will have to make sure I barely paint the image befor I convert.....

//2 min passed

OK I got the value /256 so no more spikes. Now I have nice rows but the rows don't coonet that should be easy to fix. (crosses fingers)

[edited by - CodeMaster000 on December 15, 2002 11:14:32 PM]
CodeMaster000
CodeMaster000
WOO HOOOO IT WORKS!!! Haha I rule the world. sure it may look like crap but it works! now I just have to add some nice lighting the get the jaggys from where the water meets the land away!

Thanks so much guys!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.