Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Cannot lock target bitmap

This thread is locked; no one can reply to it. rss feed Print
Cannot lock target bitmap
damianday
Member #14,620
October 2012

Hello I am trying to read pixels from the target bitmap (al_get_target_bitmap), by locking it.

Unfortunately locking always fails. So I tried cloning the target bitmap and then locking the clone, this also fails :(

I need to read the target bitmap before saving it to a file, is there any other way I can do this?

SOLVED - SEE POST FOR SOLUTION

Elias
Member #358
May 2000

Post the code.

--
"Either help out or stop whining" - Evert

damianday
Member #14,620
October 2012

#SelectExpand
1procedure TGame.TakeScreenShot; 2var 3 i, checksum: integer; 4 flname: string; 5 zcopy: PAnsiChar; 6 7 bmp: PAllegroBitmap; 8 format: ALLEGRO_PIXEL_FORMAT; 9 lr: PAllegroLockedRegion; 10begin 11 bmp := al_get_target_bitmap; 12 if bmp = nil then Exit; 13 format := al_get_bitmap_format(bmp); 14 15 flname := 'Screenshot.bmp'; 16 zcopy := PAnsiChar(AnsiString(flname)); 17 18 checksum := 0; 19 try 20 lr := al_lock_bitmap(bmp, format, ALLEGRO_LOCK_READONLY); 21 if lr = nil then Exit; 22 23 // Note: Never reach this point lr is always nil.. 24 for i := (SCREENHEIGHT - 200) to SCREENHEIGHT - 1 do begin 25 // TODO: calculate checksum with lr.data 26 27 end; 28 finally 29 al_unlock_bitmap(bmp); 30 end; 31 32 al_save_bitmap(zcopy, bmp); 33end;

Elias
Member #358
May 2000

Can you lock other bitmaps?

--
"Either help out or stop whining" - Evert

damianday
Member #14,620
October 2012

Yes I've just tested and there is no problems with
locking any bitmaps.

On a side note I'm using Allegro 5.0.7 until 5.1 is stable.

Curiously this case works fine in a simple test project, but not in my main, I think it could be a bug in my code :( somewhere..

Ok I've tracked it down to:

#SelectExpand
1al_set_new_display_option(ALLEGRO_DISPLAY_OPTIONS.ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); 2al_set_new_display_option(ALLEGRO_DISPLAY_OPTIONS.ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);

Commenting these lines out makes it go away :)

Elias
Member #358
May 2000

Intersting to know. Are you using DirectX? I don't think multi-sampling should prevent reading the backbuffer, in general.

--
"Either help out or stop whining" - Evert

damianday
Member #14,620
October 2012

I'm just using vanilla Allegro code on Windows 7 X64,
I assume by default it uses OpenGL.

It seems the code below creates the bug in question.

#SelectExpand
1al_set_new_display_option(ALLEGRO_DISPLAY_OPTIONS.ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST); 2 al_set_new_display_option(ALLEGRO_DISPLAY_OPTIONS.ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);

J-Gamer
Member #12,491
January 2011
avatar

Allegro uses DirectX by default on Windows.

" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo
"If your body was a business, thought would be like micro-management and emotions would be like macro-management. If you primarily live your life with emotions, then you are prone to error on the details. If you over-think things all the time you tend to lose scope of priorities." - Mark Oates

damianday
Member #14,620
October 2012

Is there a way to override this behaviour and make it use opengl?
nvm found it al_set_new_display_flags(ALLEGRO_OPENGL);

Go to: