Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Combining Bitmaps

This thread is locked; no one can reply to it. rss feed Print
Combining Bitmaps
Frankincense
Member #14,367
June 2012

Is there any way to add multiple bitmaps together to make one bitmap?

I.e have them next to each other without having to draw the same thing twice.

[image][image clone][image clone 2] etc.

I am doing this just to make my life easier when drawing a bullet tracer.

Arthur Kalliokoski
Second in Command
February 2005
avatar

Create the large bitmap and blit the smaller ones onto it? Which version Allegro?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Frankincense
Member #14,367
June 2012

Allegro 5, I have no idea how to do that :/

Arthur Kalliokoski
Second in Command
February 2005
avatar

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Gabriel Campos
Member #12,034
June 2010
avatar

you can make a function that return the bitmap combined...

ALLEGRO_BITMAP combineBitmaps(ALLEGRO_BITMAP *a, ALLEGRO_BITMAP *b)
{
  ALLEGRO_BITMAP *bitmapCombined;
  // here the code to combine bitmaps as Arthur links suggests
  return bitmapCombined;
}

nyergk
Member #14,129
March 2012

i'm novice too, but it's easy to make a routine for this !

use the instruction putpixel(*bitmap,x,y) and getpixel(*bitmap,x,y) for example.

int addition_image(*BITMAP source, *BITMAP additional ,int color_transparence)
{ int longx=(additional->w) ; int longy=(additional->h) ; int x,y ;
for(x=0;x<longx;x++)
for(y=0;y<longy;y++)
if (getpixel(additional,x,y)!=color_transparence)
if (x<source->w && y<source->h)
putpixel(source,x,y)=getpixel(additional,x,y) ;

return 0;
}

SiegeLord
Member #7,827
October 2006
avatar

nyergk said:

i'm novice too, but it's easy to make a routine for this !

Good job, you re-implemented draw_sprite :P.

Is there any way to add multiple bitmaps together to make one bitmap?

What you should get from this thread is that there's no way easier than to draw them twice. I'd suggest not combining the two bitmaps into one bitmap, but just create a function that draws those bitmaps instead of copy-pasting the two draws all over the place:

void repeat_bitmap(ALLEGRO_BITMAP* bmp, float x, float y, size_t num_x, size_t num_y)
{
  bool was_held = al_is_bitmap_drawing_held();
  al_hold_bitmap_drawing(true);
  for(size_t ii = 0; ii < num_y; ii++)
  {
    for(size_t jj = 0; jj < num_x; jj++)
    {
      al_draw_bitmap(bmp, x + jj * al_get_bitmap_width(bmp), y + ii * al_get_bitmap_height(bmp), 0);
    }
  }
  if(!was_held)
    al_hold_bitmap_drawing(false);
}

The hold bitmap stuff is to make it draw faster.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: