Archived

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

Moogle

Texture loading problem

Recommended Posts

Moogle    122
Aight! Code wont work!
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
	FILE	*filePtr;
	BITMAPFILEHEADER	bitmapFileHeader;
	unsigned char		*bitmapImage;
	int					imageIdx = 0;
	unsigned char		tempRGB;

	filePtr = fopen(filename, "rb");
	if (filePtr == NULL)
		return NULL;

	fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);

	fread(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);

	fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);

	bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);

	fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);

	for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx += 3)
	{
		tempRGB = bitmapImage[imageIdx];
		bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
		bitmapImage[imageIdx + 2] = tempRGB;
	}
	
	fclose(filePtr);

	return bitmapImage;
}
 

Share this post


Link to post
Share on other sites
GBGames    217
According to Chapter 8 of OpenGL Game Programming, I see that you did this:
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
fread(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);

when it should be:
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);

I haven''t looked at the rest

Share this post


Link to post
Share on other sites