[A5] How to remove pixels from a bitmap (make pixels transparent)
TeaRDoWN

In A4 it was possible to use blit() or simply the drawing primitives to paint 255,0,255 on a bitmap to make specific areas transparent and then showing the modified bitmap with masked_blit() or draw_sprite().

How do I do this in A5? I have a bitmap, I want to add transparent pixels to it (or remove existing pixels). When I use al_draw_pixel(x,y, al_map_rgba(255,0,255,255)) nothing is added to the bitmap since the color of the added pixel is transparent. Is there something similar to al_remove_pixel(), al_force_drawing_to_bitmap() or some other procedure to do this?

Hope I explained it in a way you get what I want to do. Otherwise I'll have to draw some pictures. :)

Elias
TeaRDoWN

What? How does that help with this? Of course I've already set the target or the pixels would not be placed on the bitmap. I've debugged by drawing white pixels on the bitmap and that works fine. Now I want to draw transparent pixels and by changing color it doesn't work. Of course. Drawing invisible paint on something tend to look like you didn't do anything. But I want the invisible paint to remove existing paint. :)

Here's a simplified version of my code:

void makeAllPixelsWithSpecificColorTransparent(int color)
{
  al_set_target_bitmap(mybitmap);
  for (int x = 0; x < al_get_bitmap_width(mybitmap); x++)
    for (int y = 0; y < al_get_bitmap_height(mybitmap); y++)
    {
      ALLEGRO_COLOR color1 = al_get_pixel(mybitmap, x, y);
      if (color1.r == color)
        al_draw_pixel(x+0.5,y+0.5, al_map_rgba(255,0,255,255));
    }
}

Elias

But you said the 255,0,255,255 pixels don't appear? Even though they are fully opaque?

Anyway, if what you want is draw pixels and keep the alpha value in the destination you need to use a different blending mode, something like:

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
al_draw_pixel(x, y, al_map_rgba(0, 0, 0, 0));

Audric

Alternatively, from reading the manual I get the impression you can also use al_put_pixel() instead of al_draw_pixel(), as the former will ignore the blending mode completely - I assume it means a replacement of all 4 components A R G B by the ones you provide.

TeaRDoWN

Just to be clear:

This is what I start of with:
http://www.teardown.se/allegro2_1.gif

After the operation I want to have this:
http://www.teardown.se/allegro2_2.gif

Removing all pixels with color 0,0,0.

Note that there are no white pixels in the image, they are transparent. :)

Audric

I recognize E1M1 :)

TeaRDoWN

Audric: I have NO IDEA AT ALL what you are talking about...

...but if you are skilled pixel artist willing to paint demons and other evil creatures for free for this game feel free to contact me. ;)

I tried al_put_pixel() but that didn't help. No matter which color I choose the pixels drawn with that function are always black...? ???

EDIT: The suggestion from Elias seem to work. Now I just have to fix a bug making all pixels transparent...it's never easy. :)

Audric

In your second post, the if (color1.r == color) is a cut'n'paste simplification ? Because it only checks r component of the examined pixel.

Arthur Kalliokoski
TeaRDoWN said:

Removing all pixels with color 0,0,0.Note that there are no white pixels in the image, they are transparent. :)

Surely you mean you replaced pixels, to show the white background blitted underneath each time you made a change.

[EDIT]

TeaRDoWN said:

Audric: I have NO IDEA AT ALL what you are talking about...

Quote:

if you are skilled pixel artist willing to paint demons and other evil creatures for free for this game feel free to contact me.

So you're making a Doom clone but never heard of Doom?

Thread #608822. Printed from Allegro.cc