Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro put_pixel

This thread is locked; no one can reply to it. rss feed Print
Allegro put_pixel
Alon3k
Member #15,476
January 2014

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 ?

Edgar Reynaldo
Member #8,592
May 2007
avatar

Alon3k
Member #15,476
January 2014

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 *

jmasterx
Member #11,410
October 2009

You can just set it as the target bitmap and draw:

If you only need to change a single pixel, this is probably faster than locking.

Alon3k
Member #15,476
January 2014

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.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Alon3k
Member #15,476
January 2014

Could you give me example how to use direct memory access ?

Go to: