This topic is 4289 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I can't seem to get this to work and its kind of frustrating. Here are the relevant pieces of code: In Seperate Header File
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
FILE *filePtr;
unsigned char *bitmapImage;
int imageIdx = 0;
unsigned char tempRGB;

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

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

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

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;
}


In Main.cpp
BITMAPINFOHEADER bitmapInfoHeader;
unsigned char* bitmapData;
.
.
.
int initGL(GLvoid)
{
.
.
.
}
.
.
.
int DrawGLScene(GLvoid)
{
.
.
.
glPushMatrix();
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glRasterPos2i(1,-1);
glPopMatrix();
.
.
.
}

.
.
.


I don't get what the problem is. I know that my bitmap is in the right folder. The program compiles, but everytime I run the program, it has a Windows warning menu and forces me to quit the program. Can someone help me out here?

##### Share on other sites
I can't see where are you loading data for bitmapInfoHeader variable. But you are using it (for example: bitmapInfoHeader->biSizeImage).

##### Share on other sites
OH. So what should that be declared as?

##### Share on other sites
Heres what I use to load my Windows BitMap Files -

void BMPImageFile::read(){	DWORD bytesRead;	bool  isitGood  = false;		ReadFile        (fileHandle,&fileHeader,sizeof(BITMAPFILEHEADER),&bytesRead,NULL);			// read file header	ReadFile        (fileHandle,&infoHeader,sizeof(BITMAPINFOHEADER),&bytesRead,NULL);		// read info header	image 	=       VirtualAlloc(NULL,infoHeader.biSizeImage,MEM_COMMIT,PAGE_READWRITE | PAGE_NOCACHE);		ReadFile        (fileHandle,image,infoHeader.biSizeImage,&bytesRead,NULL);			// read image	BGRFilter	(infoHeader.biSizeImage,image);	height	=	infoHeader.biHeight;	width 	=	infoHeader.biWidth;};void File::assign(char* filePath){	strcpy(fileName,filePath);};void File::open(){	fileHandle 	= CreateFile(fileName,GENERIC_READ | GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);	fileSize 	= GetFileSize(fileHandle,NULL);};void File::close(){	CloseHandle(fileHandle);};class BMPImageFile : public File		// Windows Bit Map (GDI) Format IMPLIMENTATION{	public :		BITMAPFILEHEADER		fileHeader;		BITMAPINFOHEADER	infoHeader;		void*	image;		long int	width;		long int	height;		void 	read		();		};

BGR Filter, reorders the bits, because windows bit maps are oposite order instead of RGB, its BGR.

Why do you use Fseek instead of Fread? why not fread the file and infoheader?

##### Share on other sites
well...I'm not sure but...I have seen an error in your first code:

if(filePtr = NULL)    return NULL;

You must not use '=' here and yes '=='.

if(filePtr == NULL)    return NULL;

I really cant beleive this is the error but...It can be :P

##### Share on other sites
Usually I cant compile if such an argument is present.

##### Share on other sites
Ok. I got it to work. Somehow, it was the == thing.

Anyway, here's the new problem: when I display the bitmap, it shows up too big. So I tried using glScalef() and that didn't do ANYTHING. then I tried translating the position so its farther away: that didn't work either. How do I make the bitmap look smaller?

##### Share on other sites
did you call glFlush? and are you "swapping the buffers"? did you generate a texture?

Do you have the Red Book?