Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Reusing bitmaps after creating a new display

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Reusing bitmaps after creating a new display
Thomas Fjellstrom
Member #476
June 2000
avatar

Yeah, I don't know how likely it is that he's actually running out of video memory, unless he's leaking, or allegro is.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

torhu
Member #2,727
September 2002
avatar

I guess the question is: is Allegro leaking something?

Thomas Fjellstrom
Member #476
June 2000
avatar

I don't think it is. Other people would have likely had problems by now.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

torhu
Member #2,727
September 2002
avatar

Guess I'll have to produce a test case then :P

UPDATE:
I did some debugging. al_clone_bitmap returns null because it calls al_lock_bitmap, which calls al_lock_bitmap_region, which contains this piece of code:

if (bitmap->locked)
      return NULL;

Kind of embarrassing for me, don't you think? ::) My collision testing code locks the bitmaps before using al_get_pixel on them, but didn't always unlock them. My original toggle_fullscreen_mode() function works fine after all, cloning the bitmaps once is enough.

Thanks for trying to help, guys ;D

I have a bonus question: After toggling fullscreen, I would like to redraw the last frame. The menu screens in the game are just static images being drawn once, which means that the screen turns black after toggling the fullscreen mode. There is no way to get a copy of the front buffer, right?

Thomas Fjellstrom
Member #476
June 2000
avatar

I'm not sure you can get the frontbuffer, its not always supported IIRC. But you can grab the backbuffer, just draw the screen again on switch?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

torhu
Member #2,727
September 2002
avatar

The backbuffer tends to not be the last frame, that's the problem...

It's not hard to work around, but it means that my toggle_fullscreen_mode function can't be completely self-contained. There has to be code outside of it that knows about the switching. And just always copying the backbuffer before blitting seems like a waste.

Trent Gamblin
Member #261
April 2000
avatar

Can you just call your "render" function again, if it's not all over the place?

torhu
Member #2,727
September 2002
avatar

I don't have a render function for the menu stuff, since it's just static. I guess I'll just make the menu code save the frame before calling al_flip_display(). When the actual game loop is running, I have to do some extra stuff anyway. Before calling toggle_fullscreen_mode() I stop the timers, and after calling it I call graphics_update() and then restart the timers. Unless the game was already paused, that is.

Trent Gamblin
Member #261
April 2000
avatar

If it's static why can't you just draw it?

torhu
Member #2,727
September 2002
avatar

Well, it's not a single image, it's some text on a background, on another background. It's just that there's no animation. And there are several different screens like that. I can just add a global last_frame variable and make the menu code update that.

Each menu has its own event loop, so the alternative would be to add code for handling the fullscreen switch in several places.

UPDATE:
I did it like this in my menu system:

static void update_display(void)
{
  /* save the frame first, in case of a fullscreen switch */
  al_set_target_bitmap(last_frame);
  al_draw_bitmap(al_get_backbuffer(display), 0, 0, 0);
  al_set_target_backbuffer(display);
  al_flip_display();
}

But this function takes about half a second to run, which is very noticeable. The display is only 800x600x32. Why would it take so long, and is there a better way of doing this?

Edgar Reynaldo
Member #8,592
May 2007
avatar

torhu
Member #2,727
September 2002
avatar

Thanks, that's better. I just draw the menu to a bitmap, then draw that to the backbuffer.

Edgar Reynaldo
Member #8,592
May 2007
avatar

Assuming you don't use dirty rectangles and you make a full update of the display on every frame, then you don't need to draw twice, just call your display function on a different target just before you toggle fullscreen.

torhu
Member #2,727
September 2002
avatar

The original problem was that I don't have a single update_display() function, so that won't work ;)

Edgar Reynaldo
Member #8,592
May 2007
avatar

Thomas Fjellstrom
Member #476
June 2000
avatar

If this is A5, drawing to video bitmaps can be slow on older/slower hardware (like intel gpus).

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

 1   2 


Go to: