Advertisement

Copying Bitmaps

Started by September 28, 2003 02:48 AM
5 comments, last by trager 21 years, 5 months ago
I have asked this on another thread but as it was a secondary request it seems to be getting ignored and I am really stuck until I work this out, so please help! Can I create a bitmap without loading one? (ie make a bitmap which is 512x512 and bright purple). Can I paste a smaller bitmap to a large one? (ie a 21x24 to a 32x32) Can I convert a bitmap to a TGA? Can I create a TGA without loading one? Can I paste a TGA to another TGA? I know its a lot of requests but I will be sincerely greatfull for any help. Thanks Trager
That depends on what you are trying to do. If you want to turn it into a texture, you dont need a real bitmap object in the memory, but a struct containing width, height and data.

data has the size of width * height * 3, of the type char, meaning each pixel is represented as r, g, b

So:
char *data = new char[3]; // 1 pixel

// make the pixel white:
*data[0] = 255;
*data[1] = 255;
*data[2] = 255;

After you set all the pixels to whatever you wanted (purple?) You can use the normal opengl code found on this site to turn it into a texture.
Advertisement
Yes the bitmap will eventually be used as a texture.

So would I need a struct array like this

struct bitmap_struct
{
char r;
char g;
char b;
} bitmap[64][64];

Is that right or does the structure has to be a specific format? If so please give me an example I am new to openGl and haven''t used C in a while.

If that is right how then do I turn that data into a texture?

Thanks for you effort

Trager
Basically you need this for each texture you want to use:
[code
unsigned short width;
unsigned short height;
unsigned char* data;

It doesn''t matter how you fill in the above information, as long as you fill it in. (Note: data = new unsigned char[width*height*3])

After you fill it with the information you want, you can make a texture out of it using the basic texture tutorial found on nehe. Take a look at the tutorial if you dont understand the code

        glEnable(GL_TEXTURE_2D);        glGenTextures(1, &texture[0]);        glBindTexture(GL_TEXTURE_2D, texture[0]);        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);        // Mipmapping        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, *data); 
Now we''re cooking.

I didn''t realise it was so simple thanks for the help ruudje, much appreciated.

I guess if I then change the rgb values in texture[0]->data and recreate the texture I can effectively copy and paste sections of a bitmap to another bitmap.

Am I right, or am I barking up the wrong tree here?


Thanks again.

Trager

your welcome

and yes you''re right, if you implement it right but do note, that you have to rebuild your texture(s) if you want to use the modified bitmaps. (that is, if you modify them after you created the initial textures. if you do it before, you only have to build em once)
Advertisement
yup got that ruudje, thanks.

This topic is closed to new replies.

Advertisement