5.1.9 - D3D Drawing to bitmap is limited to display size?

I have just found a strange problem.

I use version 5.1.9 of Allegro and for some reason it fails (partially) to draw into a bitmap when using D3D.

Code is simple like this:

1 ALLEGRO_BITMAP *Map = al_create_bitmap(1024, 1024); 2 3 ALLEGRO_BITMAP *Map1 = al_load_bitmap("images/bitmap_1024_1024.jpg"); 4 5 al_set_target_bitmap(Map); 6 7 al_draw_bitmap(Map1, 0, 0, 0); 8 9 al_set_target_backbuffer(Video::Display); // resolution set to 1024x768 10 11 al_save_bitmap("test.png", Map1);

With this display option set:

1 al_set_new_display_option(ALLEGRO_DEPTH_SIZE, 16, ALLEGRO_SUGGEST);

After executing this, image in the "test.png" file is fine but only in 1024x768 region. The rest is plain white.

Setting display resolution to 800x600 results in corrupted test.png outside of 800x600 area.

Everything is fine with OpenGL. Without depth buffer it also works fine.

Is this a bug? Where I should look at to fix this?

Thanks in advance :)

Trent Gamblin

Direct3D has the limitation that your depth buffer must be at least the same size as your render target. In this case your depth buffer is the size of the display and your texture is larger. I believe that's the problem. To correct this you have to create a depth buffer of your own the same size as the texture and set it as active when you render to that texture, or just leave it active all the time if you want. How to do that is explained well in the Direct3D 9 reference on MSDN.


Maybe we should add a flag to bitmaps telling whether they need a depth buffer when being set as target bitmap... and in that case Allegro could create one accordingly.



What if I do not need depth buffer at all when rendering to textures? Is there any easy way to disable it while drawing to texture?

Trent Gamblin

Yes, you can back it up, set it to null (or whatever the null value is, can't remember) the reset it. Check the Direct3D reference.


Thanks, this helped. I am backing it up in the same manner as previous_target in d3d_disp.cpp


Something's unclear to me... does Allegro create the depth buffer by default? Is it different between backends? Should it?

Trent Gamblin

The only depth buffer it ever creates is the one for the backbuffer, and only if you specify ALLEGRO_DEPTH_SIZE. It's the same between backends.

Thread #614025. Printed from Allegro.cc