![]() |
|
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 ? |
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 |
jmasterx
Member #11,410
October 2009
|
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. Agui GUI API -> https://github.com/jmasterx/Agui |
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
Major Reynaldo
May 2007
![]() |
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. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Alon3k
Member #15,476
January 2014
|
Could you give me example how to use direct memory access ? |
|