Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » acquire/release_bitmap: Is this valid?

This thread is locked; no one can reply to it. rss feed Print
acquire/release_bitmap: Is this valid?
spork222
Member #7,263
May 2006

...
while(1)
{
  acquire_screen();
  ... //Do drawing stuff here
  release_screen();
}
...

I was thinking that there has to be more efficient ways of drawing than backbuffers or double buffering- is this little code snippet valid? According to the documentation, acquire_screen can mess things up if you don't use it correctly.

Matthew Leverton
Supreme Loser
January 1999
avatar

Sure you can draw a bunch of stuff directly to the screen if you don't mind artifacts, shearing, and just a horrible all around experience.

When you use those functions the only thing between them must be drawing operations to the bitmap you've locked.

spork222
Member #7,263
May 2006

Wow, that was fast.

That's what I meant. What I wanted to do was instead of drawing stuff to a backbuffer and then blitting it to the screen, to lock the screen and draw to it directly, then clear it at the beginning of the cycle. Is that any more efficient than a backbuffer?

Richard Phipps
Member #1,632
November 2001
avatar

Unless you are drawing very little then no. :) Any form of scrolling will look bad without some form of double buffer or page flipping.

Kris Asick
Member #1,424
July 2001

By removing the buffering step, you are effectively removing the guarantee that the screen itself will only update when you tell it to. Otherwise, the screen could update at any moment, rendering only as much (or as little) as is currently on the screen bitmap surface.

Double Buffer or Page Flipping is almost a necessity...

...however, there's another update method called "Dirty Rectangles" where you only update areas that have changed. I personally don't recommend it, but if framerate is a huge issue and you're not doing full-screen scrolling, it will deliver, but it will also be the poorest quality refreshing you could hope to achieve, and more complicated to implement.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Taiko Keiji
Member #8,307
February 2007
avatar

If what your looking for is a quick way to draw to the screen then you should use a double buffer.

BITMAP*dbuffer;
*initialize things and do all your coding here*
*then when you draw just draw to the buffer*

dbuffer=create_bitmap(SCREEN_W,SCREEN_H);
*dont forget to create the buffer*
draw_sprite(dbuffer,sprite*,int x, inty);
blit(dbuffer...
textprintf(dbuffer...

*once all that is done you can call the screen draw function*

acquire_screen();
blit(dbuffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
release_screen();

It really simplifies your screen drawing code, as you can see it's only three lines. I find this to be the easiest and most efficient form for rendering.

Life could be better, machines could program themselves.

Taiko Keiji-
http://lostotaku.net

Kauhiz
Member #4,798
July 2004

Quote:

most efficient form for rendering.

That would be triple buffering...

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Go to: