What wrong with this 24bit BMP loading code:

What wrong with this 24bit BMP loading code:

bool Texture::Load(char *file)
{
FILE *File = NULL;
File = fopen(file, “rb”);

if (!File) 
{
	char msg[1024];

	sprintf(msg, "Couldn't load texture because file was not found: %s", file);
	
	MessageBox(NULL, msg, "ERROR", MB_OK);
	return false;
}

fclose(File);

AUX_RGBImageRec *img = NULL;

img = auxDIBImageLoad(file);

glGenTextures(1, &ID);


glBindTexture(GL_TEXTURE_2D, ID);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexImage2D(GL_TEXTURE_2D, 0, 3, img->sizeX, img->sizeY, 0, GL_RGB8, GL_UNSIGNED_BYTE, img->data);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img->sizeX, img->sizeY, GL_RGB, GL_UNSIGNED_BYTE, img->data);

if(img)
{
	if(img->data)
		free (img->data);
    free(img);
}

return true;

}

it returns true, but when i bind it with glbindtexture, i simply see white texture, and i am sure that BMP file is OK.

You probably want to play around a little bit with either of these lines:

glTexImage2D(GL_TEXTURE_2D, 0, 3, img->sizeX, img->sizeY, 0, GL_RGB8, GL_UNSIGNED_BYTE, img->data);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img->sizeX, img->sizeY, GL_RGB, GL_UNSIGNED_BYTE, img->data);

Depending on your compiler and implementation, you could change GL_RGB to another value, maybe GL_BGR or GL_RGB_EXT and see if you can see the texture. You can also try changing the GL_UNSIGNED_BYTE but since your program loads this is 90% ok (it usually crashes the program if it is wrong).
Also you could check through a watch the variable that holds the bitmap data. See if you have a logical value for the address. If it is NULL (try initializing to NULL to make certain) then you have trouble loading your bitmap.

Well, i played with that values as you said, but no luck…
I also look’ed with the debbuger at the img, it seems that it has some kind of data, it isn’t NULL…
The strangest thing is that i have used this code before in my other projects and i had no problems at all, and now it isn’t working… That’s very strange…
Well, anybody, any ideas ?

if u have checked up the texture building lines of code then i can only suggest 2 things.

  1. opengl seems to have problems (atleast i had problems) with textures that have dimensions which are not powers of 2.
  2. if that isnt the case then u may want to write the bitmap file reding code yourself. image data starts at byte 54. the image starts from the lower left corner of the screen.

I am doubt if it is because your bmp is too big? or your bmp is a 8 or 16 bit’s bmp,
you should call the glGetInteger( );
function i fouget which parameters you should use ,but it can get the max bmp size you can use in your program

The width and height must be a power of two to work, for example 2, 4, 8, 16, 32 etc. however I think glubuild2Dmipmaps should resize OK. Try an image size of 2^n image just for kicks. Have you tried displaying the images with gldrawpixels just to confirm the data are good?

Image size is power of to (its 256x256)
Its 24-bit BMP image, and i would call i “BIG” :slight_smile:
Well, i tried doing my own BMP loader, and still no success.
No, i haven’t tried glDrawPixels,i will try right now.

Just tried glDrawPixels and it draws image 100% perfect. Well, that means loading of bmp is done OK, so, any ideas ?!

glEnable(GL_TEXTURE_2D); ??

A white texture ? Try disabling mipmaps :

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, img->sizeX, img->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, img->data);
//gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img->sizeX, img->sizeY, GL_RGB, GL_UNSIGNED_BYTE, img->data);

And put some glGetError to check if itsays something useful.