Skip to main content
gamedev.net
🔒 Locked

Bitmap loading problem.

Started by zenon 2 replies 300+ views
Original Post
zenon
zenon
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; } ------------ And these are the errors i receive on compilation, each one listed and the position in the code. //**********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. #include <me.h>
include
SwSh
SwSh
There is a typo in:
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmpaInfoHeader)
shouldn''t it be *bitmapInfoHeader ? (If you copypasted the code from your editor, that could solve the problem)
Also consider using new instead of malloc.


Click NOW!
Californium
Californium
quote:
Original post by zenon

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

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



Maybe your typecasting is wrong. See "(unsigned *char)mal..." Should not it be "(unsigned char*)mal...?"

EDIT: ...Or "((unsigned char)*)...?" Or maybe you could type define it like so: "typedef (unsigned char) uchar; (uchar*)mal..." Or maybe like this: "typedef (unsigned char)* uchar; (uchar)mal...?" Yes? No?

[edited by - Californium on February 23, 2003 11:27:06 AM]
This post will self-destruct in 5 seconds...Actually, it's just Benjamin Bunny doing his thing.
zenon
zenon

Aight!
Fixed the typo (thanks SwSh), but like you (Californium) suspected, there''s somethin weird going on with the syntax of
that line..

I received an exprecion syntax error on the malloc line.
So I changed the typecasting and voila.. you where also
right Californium. That did the trick..

Thank you so mutch for hepling me out, I was getting desperate
over here.

I''ll wine again if something f*cks up.

Thanks//zen.

---------
It''s never the computers fault, it''s the one using it
---------


#include <me.h>
include

Topic Locked

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

Sign in to reply to this topic.