BMP Question?

Started by
7 comments, last by TheMightyDude 20 years, 1 month ago
Hello All I am just asking what format is the stored image in FontTexture in the code below: I know sizeX and sizeY are for, but when ever I try to save FontTexture->data into a binary file and then load it up in PaintShop Pro also adding the relivent X and Y etc it comes up all messed up. AUX_RGBImageRec FontTexture = auxDIBImageLoad("data\images\font.bmp"); Looking in file "glaux.h" AUX_RGBImageRec is defined the following: typedef struct _AUX_RGBImageRec { GLint sizeX, sizeY; unsigned char *data; } AUX_RGBImageRec; I am asking this because I am tring to create a datafile for all my Images, Music, Sound etc. So all the images will be in a file called Images.MPF and Music.MPF etc. Can anyone help me with this please. Thanks in advance. Paul Kirby
Advertisement
Bitmaps contain a header specifying version, color depth, probably size and such. If you want to know what a bitmap headers looks like take a loot at this code posted in this forum a while ago:
BITMAPFILEHEADER bf;
BITMAPINFOHEADER bi;
FILE *file;
file = fopen( filename, "wb");

memset( &bf, 0, sizeof( bf ) );
memset( &bi, 0, sizeof( bi ) );

bf.bfType = ''MB'';
bf.bfSize = sizeof(bf)+sizeof(bi)+m_render_x*m_render_y*3;
bf.bfOffBits = sizeof(bf)+sizeof(bi);
bi.biSize = sizeof(bi);
bi.biWidth = m_WindowWidth;
bi.biHeight = m_WindowHeight;
bi.biPlanes = 1;
bi.biBitCount = 24;
bi.biSizeImage = m_render_x*m_render_y*3;
fwrite( &bf, sizeof(bf), 1, file );
fwrite( &bi, sizeof(bi), 1, file );
fwrite( image, sizeof(unsigned char), m_render_x*m_render_y*3, file );
fclose( file );
Thanks for the reply.
But I don’t think you understood what I was trying to say and do.

I know all the image header formats and all, but didn’t know the format the image is stored in the following:

// in header file
typedef struct _AUX_RGBImageRec
{
GLint sizeX, sizeY;
unsigned char *data;
} AUX_RGBImageRec;
//

// In my Header file
#define FONT_TEXTURE 1
//

AUX_RGBImageRec *TextureImage[5];
memset (TextureImage, 0,sizeof(void *)*5);

TextureImage[FONT_TEXTURE] = auxDIBImageLoad("data\images\font.bmp");

glGenTextures(4, &texture[0]);
...
Blah
...
I then build the image font etc...
All fine here.

I also load up other images as well as other image fonts.
And what I wanted to do was have all the images in one big file called Images.MPF (My Packed File) and same goes for all the music files that I may use will all be in a file called Music.MPF etc.

My problem is I needed to know what the format of the image data in TextureImage->data ??

I know it says it''s as unsigned char * but what’s the format of the image stored there?
And also how can I save that Image Information from that unsigned char * so that I can just result = fseek( stream, StartPos, SEEK_CUR); to get to the start of the file to be extracted?

I’m hoping to import the images in using something like the following:
TextureImage[FONT_TEXTURE]->sizeX=nSizeX;
TextureImage[FONT_TEXTURE]->sizeY=nSizeY;
TextureImage[FONT_TEXTURE]->data=rawData;

nSizeX,nSizeY and rawData are read from my Images.MPF file.
This is no problem as far as I can see.
But I don’t seem to be able to save the ImageData from TextureImage[FONT_TEXTURE]->data

Has anyone tried this and have gotten it to work.

Thanks in advance.
Paul Kirby
I''m pretty sure that it''s 24-bit rgb format.

eg. each pixel is like this

struct pixel
{
unsigned char r, g, b;
};

so, to calculate the size of the whole image(in bytes), it would be width*height*3
quote:Original post by Melekor
I''m pretty sure that it''s 24-bit rgb format.

eg. each pixel is like this

struct pixel
{
unsigned char r, g, b;
};

so, to calculate the size of the whole image(in bytes), it would be width*height*3


Thanks that worked a treat

The only problem that I am having now is it will only work if I load an image into it first
With the following line:
TextureImage[FONT_TEXTURE]=auxDIBImageLoad(IMAGE_PATH"Dummy.bmp");

Dummy.bmp is a 1x1 2 colour image.

...

My code that I am using:

GLint nSizeX,nSizeY;
void *data;

FILE *stream;
AUX_RGBImageRec *TextureImage[5];
memset(TextureImage,0,sizeof(void *)*5);

nSizeX = 256;
nSizeY = 256;

data = (void *)malloc((nSizeX*nSizeY)*3);

stream = fopen( IMAGE_PATH"FONT.raw", "rb" );
fread(data, (nSizeX*nSizeY)*3,1, stream);
fclose(stream);

TextureImage[FONT_TEXTURE]->sizeX=nSizeX;
TextureImage[FONT_TEXTURE]->sizeY=nSizeY;
TextureImage[FONT_TEXTURE]->data = (unsigned char *)data;

// After all this I do all the glGenTextures,glBindTexture etc.


Anyone know why I need to load an image into it first, because the are only sizeX,sizeY and data in there that need to be set?

Thanks in advance
Paul Kirby
The reason it isn''t working is because TextureImage[FONT_TEXTURE] is an AUX_RGBImageRec* (a pointer) and it doesnt point to anything.

You could allocate some memory there (like auxDIBImageLoad does) with malloc/new.

When you think about it though, AUX_RGBImageRec is for use with auxDIBImageLoad, and you''re not using that to load the font texture, so, I think a better solution would not to use the AUX_RGBImageRec structure at all.

Just pass data, nSizeX, and nSizeY directly to glTexImage2D.
Well Im using gluBuild2DMipmaps(), But I can see where you heading

All I need to do is load and extract all the images out of the Images.MPF file and import them into an array of nSizeX,nSizeY and data and read them in the following for loop:

for (n=0;n<=nMax;n++)
{
glBindTexture ( GL_TEXTURE_2D, texture[n] );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, imgMPF[n]->sizeX, imgMPF[n]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, imgMPF[n]->data);
}

I will need to make sure the order the images are in the Images.MPF file are located, due to I cant see any way to identify what image is what one all loaded in.

Unless it done with glBindTexture, which it looks like it is
So i think this should be ok

Does this seem right to you?

Thanks in advance.
Paul Kirby
Well, it doesnt look like you''ve fixed the problem of there being nothing at the pointer.

My suggestion is drop the whole AUX_RGBImageRec thing..

Also, I wouldn''t load them like that, because that way requires them to all be in memory at once. A better way would be to load each image one by one and delete them right away once you''ve uploaded them to opengl, thus requiring at max the size of your largest image.
Ok I will try that the next time I get some time

Thanks for the help

Paul Kirby

This topic is closed to new replies.

Advertisement