Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » 5.1.9 - D3D Drawing to bitmap is limited to display size?

Credits go to Trent Gamblin for helping out!
This thread is locked; no one can reply to it. rss feed Print
5.1.9 - D3D Drawing to bitmap is limited to display size?
Vi_112
Member #15,539
March 2014

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:

#SelectExpand
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:

#SelectExpand
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
Member #261
April 2000
avatar

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.

Elias
Member #358
May 2000

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.

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

Vi_112
Member #15,539
March 2014

Thanks!

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
Member #261
April 2000
avatar

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.

Vi_112
Member #15,539
March 2014

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

SiegeLord
Member #7,827
October 2006
avatar

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

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Trent Gamblin
Member #261
April 2000
avatar

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.

Go to: