Cannot lock target bitmap
damianday

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

Post the code.

damianday
#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

Can you lock other bitmaps?

damianday

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

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

damianday

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

Allegro uses DirectX by default on Windows.

damianday

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

Thread #611379. Printed from Allegro.cc