Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » al_get_pixel not working with Direct3D and locking?

This thread is locked; no one can reply to it. rss feed Print
al_get_pixel not working with Direct3D and locking?
Polybios
Member #12,293
October 2010

I don't know if this is a bug in Allegro 5.0.3, but on my system, the alpha value of pixels isn't read back properly when using Direct3D and locking.

The simple example below fails to produce the expected output, which is:

a(al_get_pixel)  == 40
a(locked region) == 40

Instead, it prints:

a(al_get_pixel)  == 255
a(locked region) == 0

Red, green and blue values seem to work fine, it also works correctly when not using locking.
With OpenGL, there's no problem at all.

It would be nice if someone could try to reproduce this :)

#SelectExpand
1#include <allegro5/allegro.h> 2#include "common.c" 3 4 5int main(void) 6{ 7 ALLEGRO_DISPLAY *display; 8 ALLEGRO_COLOR c; 9 unsigned char r, g, b, a; 10 uint32_t pixel; 11 12 if (!al_init()) { 13 abort_example("Could not init Allegro.\n"); 14 return 1; 15 } 16 17// al_set_new_display_flags(ALLEGRO_OPENGL); // use OpenGL 18 19 display = al_create_display(640, 480); 20 if (!display) { 21 abort_example("Could not create display.\n"); 22 return 1; 23 } 24 25 ALLEGRO_BITMAP *bmp = al_create_bitmap(32, 32); 26 if (!bmp) { 27 abort_example("Could not create bitmap.\n"); 28 return 1; 29 } 30 31 al_set_target_bitmap(bmp); 32 al_put_pixel(0, 0, al_map_rgba(10, 20, 30, 40)); 33 al_set_target_bitmap(al_get_backbuffer(display)); 34 35 ALLEGRO_LOCKED_REGION *lr = 36 al_lock_bitmap(bmp, ALLEGRO_LOCK_READONLY, ALLEGRO_PIXEL_FORMAT_ARGB_8888); 37 38 if(!lr) { 39 abort_example("Could not lock bitmap.\n"); 40 return 1; 41 } 42 43 c = al_get_pixel(bmp, 0, 0); 44 al_unmap_rgba(c, &r, &g, &b, &a); 45 46 47 pixel = *(uint32_t *)lr->data; 48 49 printf("a(al_get_pixel) == %d", a); 50 printf("\na(locked region) == %d", (pixel & 0xFF000000) >> 24); 51 52 al_unlock_bitmap(bmp); 53 al_destroy_bitmap(bmp); 54 55 56 return 0; 57 58}

Arthur Kalliokoski
Second in Command
February 2005
avatar

Wouldn't you have to set the color depth before creating the display?

   al_set_new_display_flags(ALLEGRO_DIRECT3D);
   al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 32, ALLEGRO_SUGGEST);
   display = al_create_display(640, 480);

They all watch too much MSNBC... they get ideas.

Trent Gamblin
Member #261
April 2000
avatar

Verified, but here it's not a Direct3D issue: here I get the same results using OpenGL.

EDIT: Just noticed you have the last two parameters of al_lock_bitmap reversed.

Arthur Kalliokoski
Second in Command
February 2005
avatar

So what color depth does A5 choose by default? 8 bit like A4?

They all watch too much MSNBC... they get ideas.

Trent Gamblin
Member #261
April 2000
avatar

32 bit.

It indeed does work with the parameters in the right order..

Polybios
Member #12,293
October 2010

Ah! Thank you! :)

Go to: