Image Library

Does anybody know of an OpenGL BMP Loading Library that works with C++ Builder?

Let me clarify on my problem

I’m having huge problems trying to load a simple texture map into C++ Builder. Here’s my code for loading the BMP file.

unsigned char *data;
unsigned char color;

FILE *pfile;

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

fread(&header, sizeof(BITMAPFILEHEADER), 1, pfile);
if(header.bfType != BITMAP_ID)
	return 0;

fread(&biHeader, sizeof(BITMAPINFOHEADER), 1, pfile);
fseek(pfile, header.bfOffBits, SEEK_SET);

data = new unsigned char[biHeader.biSizeImage];
fread(data, 1, biHeader.biSizeImage, pfile);

int index;
for(index=0; index < (int)biHeader.biSizeImage; index+=3)
	color = data[index];
	data[index] = data[index+2];
	data[index+2] = color;

This works perfectly fine in Visual C++, but in Borland C++ Builder if I check the values of biHeader.biWidth, biHeader.biHeight, and/or biHeader.biSizeImage they all have either 0 or really “high” values, like 88083838 or something along those lines. I have the images in the current directory of the project so that’s not the issue, and I check to make sure it loads, but for some reason this code doesn’t grab the information correctly. I even tried outputing the contents of data to a file and it turned up blank!

I know texture mapping is working because I constructed my own texture map manually and loaded it and it displayed fine, but with this code all I get is a white triangle. Any ideas?

Check your compilers documentation about how it packs and aligns memory in structures.

Well I figured out a different way to do it, so for anyone out there who has had the same problem here’s the code:

Graphics::TBitmap bitmap = new Graphics::TBitmap;
unsigned char data = new unsigned char[bitmap->Widthbitmap->Height

for(int i=0; i < bitmap->Height; i++)
    for(int j=0; j < bitmap->Width; j++)
            data[(i*bitmap->Width+j)*3] = (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
            data[(i*bitmap->Width+j)*3+1] = (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
            data[(i*bitmap->Width+j)*3+2] = (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmap->Width, bitmap->Height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);

Hope it helps someone else like it did me.

There’s a number of major assumptions in that code. Nasty, very nasty.

Personally, I think that BMP (uncompressed) is worthless.

Try (formerly DevIL). It can handle quite a few things.

yeah, i’ve been looking into devil but I’m having a hard time getting it to compile under BCB, but I’m new to BCB so i’ll keep trying. Visual C++ is such a pain in the @ss when you need to use a gui

Then don’t compile it. Link to VC-compiled dll (use implib)