How to copy a bitmap?
boulifb

Hello guys,

I'd like to know how can I clone a bitmap that has been programmatically created?

1int main()
2{
3 allegro_init();
4 install_keyboard();
5 set_color_depth(32);
6 set_gfx_mode(GFX_AUTODETECT_WINDOWED, SCALE*160, SCALE*100, 0, 0);
7 
8 PLEVELDESC level=LoadLevel("level");
9 BITMAP* map=BuildMap(level); // the map itself calculated 1 time
10 BITMAP* frame=NULL; // copy of the map
11 
12 while (!key[KEY_ESC])
13 {
14 // how to do a fresh copy of the map without recalculate it???
15 frame= CloneBitmap(map); // reset the frame
16 DrawOtherStuffs(frame);
17 blit(frame, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
18 destroy_bitmap(frame);
19 }
20
21 destroy_bitmap(map);
22 
23 remove_keyboard();
24 allegro_exit();
25 
26 return 0;
27}

How should I write the "CloneBitmap" function ???

I have seen nothing in the doc to do a bitmap copy...

Thanks for helping me.

Best regards.

Fred.

gnolam

A bitmap copy is also known as a blit...

Onewing
manual said:

The origin of the term "blit" is also rather interesting. This was originally BitBlt, an abbreviation of BITmap BLock Transfer, which was a function designed (possibly) by the people at Xerox who did so much of the pioneering work on graphics display systems, and subsequently copied by virtually everybody doing computer graphics (the Microsoft Windows GDI still provides a BitBlt function with identical functionality to the original). This routine was a workhorse for all sorts of drawing operations, basically copying bitmap graphics from one place to another, but including a number of different ROP modes (Raster OPerations) for doing things like XOR, inverting pixels, etc. A whole family of related words grew up around the BitBlt function, but "blt" is impossible to speak (try saying "bltter" or "bltting" :-) so people added the vowel to make it easier to pronounce.

Emphasis mine.

CursedTyrant

My best shot would be:

1. Create a BITMAP.
2. Blit to it.
3. Return a pointer to the BITMAP.

Maybe:

BITMAP *CloneBitmap(BITMAP *BMP)
{
  BITMAP *Tmp = create_bitmap(BMP->width, BMP->height);
  blit(BMP, Tmp, 0, 0, 0, 0, BMP->width, BMP->height);
  return Tmp;
}

Now I might be wrong with the width and height, I can't remember their names, but I think the example should work.

Matthew Leverton

It is w and h.

boulifb

ah yes, blitting.... why should have not thought about it before...

many thanks :)

Fred.

Thread #585688. Printed from Allegro.cc