bmp loader prob

This code from a bmp loader tut has a problem compiling, seems to be the bitmapData that is causing the prob. I’m not sure how to change it, anyone?-

16 C:\Program Files\c++\Dev-Cpp\ben-prog exturesquare3.cpp
ISO C++ forbids declaration of bitmapData' with no type 12 C:\Program Files\c++\Dev-Cpp\ben-prog exturesquare3.cpp previous declaration asunsigned char*bitmapData’

#define BITMAP_ID 0x4D42
unsigned char *bitmapData;
unsigned int texture;
unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader);
char image[] = { “texture.bmp” };
bitmapData = LoadBitmapFile(image, &bitmapInfoHeader);

unsigned char *LoadBitmapFile(char *file, BITMAPINFOHEADER *bitmapInfoHeader)
// Bitmaps are made up of 3 parts, the file header, info header, and
// the image. Once we load in the file and info headers we can then
// load the image into our unsigned char variable called bitmapData.

FILE *pFile; // Need this to open a file.
BITMAPFILEHEADER header; // This will hold the bitmap header information.

unsigned char *textureData;   // This will hold the bitmap image itself.

// This will be used to swap the image colors from BGR to RGB.
unsigned char textureColors;

pFile = fopen(file, "rb");    // Open the file.

if(pFile == NULL) return NULL;// Check and make sure there are no errors.

// Read in the bitmap header info into the BITMAPFILEHEADER variable.
fread(&header, sizeof(BITMAPFILEHEADER), 1, pFile);

// Make sure this is a real bitmap by checking the ID.
if(header.bfType != BITMAP_ID)
	   return NULL;

// Read in the second header info into the BITMAPINFOHEADER variable.
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, pFile);

// Place the pointer in front of where the image data starts.
fseek(pFile, header.bfOffBits, SEEK_SET);

// Dynamically create enough memory for the image.
textureData = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);

// Error checking.  Make sure the memory was allocated.
	   return NULL;

// Read in the image.
fread(textureData, 1, bitmapInfoHeader->biSizeImage, pFile);

// Error checking.  Make sure an image was loaded.
if(textureData == NULL)
	   return NULL;

// Bitmaps are saved in BGR format so we will make the image RGB by...
for(int index = 0; index < bitmapInfoHeader->biSizeImage; index+=3)
	   textureColors = textureData[index];
	   textureData[index] = textureData[index + 2];
	   textureData[index + 2] = textureColors;

fclose(pFile);     // We are done with the file so close it.
return textureData;  // Send the image to the function that called this.


Get rid of the original declaration of bitmapData and combine it with its initialization:

unsigned char *bitmapData = LoadBitmapFile(image, &bitmapInfoHeader);

You’re declaring it once and then trying to initialize in a later step, but that step is outside of function scope so the compiler thinks you’re declaring another global bitmapData variable and trying to initialize that one.

Alternatively, you could put the initialization part in a function.

Ok, it compiles, but I’ve got a blank white square where there should be a bitmap. Do I need to set glBindTextures to a different value?

What are you making? Screensaver or just an OpenGL framework?

yeh, just the normal glut framework, I think it’s a glBindTextures prob again, but not sure what variable to set it to.

Make sure the dimensions of your texture file are a power of 2 (e.g. 256 x 256, 1024 x 512, etc.).

Not sure what you mean by “variables set to” I set glBindTexture(GL_TEXTURE_2D); and roll with that.