PDA

View Full Version : What wrong with this 24bit BMP loading code:



Jnz86
06-09-2004, 04:07 AM
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.

dvm
06-09-2004, 04:13 AM
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.

Jnz86
06-09-2004, 06:44 AM
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 ?

06-09-2004, 09:35 AM
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.

ben996
06-15-2004, 05:53 PM
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

dorbie
06-15-2004, 08:49 PM
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?

Jnz86
06-15-2004, 10:11 PM
Image size is power of to (its 256x256)
Its 24-bit BMP image, and i would call i "BIG" :)
Well, i tried doing my own BMP loader, and still no success.
No, i haven't tried glDrawPixels,i will try right now.

Jnz86
06-15-2004, 10:30 PM
Just tried glDrawPixels and it draws image 100% perfect. Well, that means loading of bmp is done OK, so, any ideas ?!

Inquisitor
06-16-2004, 06:29 AM
glEnable(GL_TEXTURE_2D); ??

ZbuffeR
06-16-2004, 01:06 PM
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.