PDA

View Full Version : 32 bit bmp



piazzesi
12-23-2003, 05:36 PM
Hi.
Iīm trying to load a 32 bit bmp, and iīm blocked, i had no problem loading 24 bit bmps, i changed GL_RGB to GL_RGBA and 3 to 4 parms. in glteximage2d, and i get an error i donīt even know how i loaded 24 bit bmps anymore.



AUX_RGBImageRec *LoadBMP(char *Filename)
{
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

FILE *File=NULL;
if (!Filename)
{
return NULL;
}
File=fopen(Filename,"r");
if (File)
{
fclose(File);

return auxDIBImageLoad(Filename);
}
return NULL;
}

int LoadGLTextures()
{
int Status=FALSE;

AUX_RGBImageRec *TextureImage[100];
int v=2;
memset(TextureImage,0,sizeof(void *)*numtextures);

for (int lop=0; lop < numtextures; lop++){

if (TextureImage[lop]=LoadBMP(textures[lop].nametex))
{
Status=TRUE;
glGenTextures(1, &amp;texture[lop]);

glBindTexture(GL_TEXTURE_2D, texture[lop]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
if (lop==3){
glTexImage2D(GL_TEXTURE_2D, 0, 4, TextureImage[lop]->sizeX, TextureImage[lop]->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImage[lop]->data);
}
else
{
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[lop]->sizeX, TextureImage[lop]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[lop]->data);
}
//return Status;
}


if (TextureImage[lop])
{
if (TextureImage[lop]->data)
{
free(TextureImage[lop]->data);
}
free(TextureImage[lop]);

}
}; return Status;
}


the fourth texture is the one in 32 bits.

Thanks

Mario Piazzesi

[This message has been edited by piazzesi (edited 12-23-2003).]

[This message has been edited by dorbie (edited 12-24-2003).]

Tom Nuydens
12-23-2003, 10:58 PM
This is hardly an advanced question, so I'm moving the thread to the beginners forum.

Which error specifically do you get from glTexImage2D()?

-- Tom

piazzesi
12-24-2003, 05:39 AM
Access Violation

dorbie
12-24-2003, 09:12 AM
You are probably running out of image data in the load. i.e. you load a smaller image than you assume.

Your code assumes the 4th image has alpha.

Do BMP files even support alpha data. I don't think you have 4 components in memory but are assuming that your bmp image loader has allocated and loaded sufficient data.

You can't simply specify 4 components if you don't have the data because the texture load call will assume you have more data in memory than you have and you'll run of the end of the array either causing a memory access violation or sending garbage to texture memory.

[This message has been edited by dorbie (edited 12-24-2003).]

piazzesi
12-24-2003, 11:24 AM
Bmps Can be made in 32 bits, however its posible that dibimg... from glaux canīt read 32 bits, i need help reading the bmps with fread or scanf or any other way, i havnīt seen a way to read and interpret the header.

thanks
Merry xmas

shielded
12-24-2003, 11:44 AM
Take a look at this url:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/bitmaps_1rw2.asp?frame=true

dorbie
12-24-2003, 01:18 PM
Even if the image is 32 bits I don't think the additional information represents alpha. Exactly how this looks in memory after a load depends entirely on the image loader. In anycase you should look at the resulting loaded image information to determing the image size, rather than assuming you've gotten 4 bytes per pixel packed in memory and certainly not that you have RGBA packed

piazzesi
12-24-2003, 01:44 PM
Anyone can make 32 bit bmps in most any drawing software, i used corel, the image reads 32 bits by windows, and has four bytes per pixel, its even one third larger than a 24 bit bmp of the same size, if theres a fourth pixel, ranging from 0 to 255 you one can read it as transparency (as corel does) or anything else.

but thanks, and thanks to shielded too, iīll check the link out.

lgrosshennig
12-24-2003, 02:10 PM
Originally posted by dorbie:
Even if the image is 32 bits I don't think the additional information represents alpha. Exactly how this looks in memory after a load depends entirely on the image loader. In anycase you should look at the resulting loaded image information to determing the image size, rather than assuming you've gotten 4 bytes per pixel packed in memory and certainly not that you have RGBA packed

I have used 32 bit BMP's (including alpha) in the past because a customer insisted on that. Just because most programs cant handle them correctly (Photoshop, ...) doesnt mean they are not valid. Our graphic department saved the images as 32 bit TGA's (including the alpha channel) using Photoshop and I wrote a converter that changed them into 32 bits BMP's. The alpha gets stored in the "reserved" channel btw (see RGBQUAD).

Its valid, its possible.

@ the intial poster
Dont use GLAUX its not only stone old, it is also known as a very buggy software. I will see I find my old bmp loading routine and will post it.

piazzesi
12-24-2003, 02:18 PM
Thanks, i want to leave glaux i now realize how "outdated" it is, i'm looking forward for your loader.

Thanks again.