texture mapping problem (based on Opengl Game Programming book)

Started by
11 comments, last by mrfusion 21 years, 1 month ago
The problem is that our bitmap loading code wasn''t really robust. The problem is with this line:
	bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
For an uncompressed RGB image, it is valid for biSizeImage to be zero. In this case, you should use a combination of the biWidth, biHeight, and biBitcount members to determine how many bytes you really need for the bitmap. e.g.

  	// allocate enough memory for the bitmap image data	int imageSize = bitmapInfoHeader->biSizeImage;	if (imageSize == 0)		imageSize = bitmapInfoHeader->biWidth * bitmapInfoHeader->biHeight * bitmapInfoHeader->biBitCount/8;	bitmapImage = (unsigned char*)malloc(imageSize );...	// read in the bitmap image data	fread(bitmapImage, 1, imageSize, filePtr);  
Advertisement
Thanks SO much for answering that! I thought I was going crazy.
Thanks SO much for answering that! I thought I was going crazy.
Great book by the way. I''ve really learned a lot.
Tom

This topic is closed to new replies.

Advertisement