PDA

View Full Version : Bitmap loading problem.



zenon
02-23-2003, 06:38 AM
I'm doing a village, just for fun. And I'm learning how to put textures and so, but first I have to load the bitmap, and I'm reading the OPENGL GAME PROGRAMMING book.

So, I just copied the following code from the example in the book OPENGL GAME PROGRAMMING
chapter 8.Texture Mapping - An Overview of
Texture Mapping page 232-233

------------
BITMAPINFOHEADER bitmapInfoHeader;
unsigned char* bitmapData;
unsigned int texture;

unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmpaInfoHeader)
{
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);
if(bitmapFileHeader.bfType != BITMAP_ID){
fclose(filePtr);
return NULL;
}

/*--------(1)-------*/
/*--------(2)-------*/
fread(bitmapInfoHeader,sizeof(BITMAPINFOHEADER),1, filePtr);

fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);

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

if(!bitmapImage){
free(bitmapImage);
fclose(filePtr);
return NULL;
}

fread(bitmapImage, 1, (bitmapInfoHeader.biSizeImage), filePtr);
if(bitmapImage == NULL){
fclose(filePtr);
return NULL;
}

for(imageIdx = 0; imageIdx < (bitmapInfoHeader.biSizeImage); imageIdx += 3){
tempRGB = bitmapImage[imageIdx];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;
}

fclose(filePtr);
return bitmapImage;
}

//**********ERRORS********************
(1) Error: ville.cpp(55,63):Cannot convert 'tagBITMAPINFOHEADER' to 'void *'
(2) Error: ville.cpp(55,63):Type mismatch in parameter '__ptr' in call to 'fread(void *,unsigned int,unsigned int,FILE *)'
(3) Error: ville.cpp(59,33):Expression syntax


Well,, the error markings are pretty clear.. so.. can someone über help me?
Thanks//Zen.

shinpaughp
02-23-2003, 09:21 AM
In your code where you have:




/*--------(1)-------*/
/*--------(2)-------*/
fread(bitmapInfoHeader,sizeof(BITMAPINFOHEADER),1, filePtr);



try changing it to:




/*--------(1)-------*/
/*--------(2)-------*/
fread(&amp;bitmapInfoHeader,sizeof(BITMAPINFOHEADER),1 , filePtr);



fread expects a pointer.