Hello, what I'm looking for is how to change selected pixel alpha in the stored bitmap.
My draw method draws the terrain as stored bitmap and I'm trying to remove selected pixels on click and then draw the bitmap again.
I have a method called removePixel(posX, posY) the purpose of this method is to change pixel alpha to 0.
Any ideas how to edit pixels in stored bitmap ?
Are you using allegro 4 or 5?
Allegro 5
I found some post stuff but it doesn't work...
ALLEGRO_LOCKED_REGION *lr = al_lock_bitmap_region(image, x, y, 1, 1, al_get_bitmap_format(image), ALLEGRO_LOCK_READONLY);
This should lock the pixel I need to access but...
unsigned char *ptr = (unsigned char *)lr->data; << THIS RETURNS
ptr 0xcccccccc <Bad Ptr> unsigned char *
You can just set it as the target bitmap and draw:
al_set_target_bitmap(bmp); al_put_pixel(x,y,c); al_set_target_bitmap(al_get_backbuffer());
If you only need to change a single pixel, this is probably faster than locking.
If I call in main each frame al_set_target_bitmap(al_get_backbuffer(Display));
Will this slow down my program a lot ? I would need to pass Display as parameter of the method that I'm using since its part of a separate class. If so ill do it if necessary.
I'm having some weird problem sometimes when I use put pixel nothing shows up when I use draw line and do x , y, x +1 , y +1 for the starting and end point it draws a dot.
Also I have 2 bitmaps 1 'locked' READONLY for calculations etc. Second for drawing which I am trying to update. Yet when I set 'locked' one as target it works as well even if all im calling in the main loop is al_draw_bitmap(image);
What I'm looking for is the fastest possible way to edit pixels in the bitmap as I'm trying to update a lot of them.
If you have a lot of pixels to update then you want to lock the bitmap, or the smallest region that all the pixels you want to update fits inside, and then use direct memory access or al_put_pixel.
Could you give me example how to use direct memory access ?