LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-12-2009, 02:46 PM   #1
Ace Blackwell
Member
 
Registered: Mar 2004
Location: Kentucky, USA
Distribution: SlamD 12.1 / Slack 12.0 ~ 14.2_64
Posts: 345

Rep: Reputation: 54
Double Buffering


Hey all,

I'm playing around with Allegro and I'm testing the double buffering. I have written a few simple Simon Says type games in Quick C years ago. I didn't use double buffering though I did use various graphics during the game.

I'm a novice by far , but just from what I'm seeing, can anyone explain the benefits to double buffering? I mean it seems your still going to have to draw or aquire a file, whether memory or screen. So what is the benefit to the extra step of blitting the memory to screen?

The only thing I can think of would be to draw numerous sprites to a memory bitmap and then transfer only the onces you want to the screen as you need them or using them repeatedly without redrawing.

Anyways, just trying to learn

Thanks in advance for your time.

Ace
 
Old 02-12-2009, 02:55 PM   #2
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by Ace Blackwell View Post
I'm a novice by far , but just from what I'm seeing, can anyone explain the benefits to double buffering? I mean it seems your still going to have to draw or aquire a file, whether memory or screen. So what is the benefit to the extra step of blitting the memory to screen?
If you'll draw on screen directly, without second buffer, everything that moves will flicker terribly. Image will get displayed (on monitor) when you haven't drawn anything (just cleared screen), rendered only half of the picture, etc. and each time different portion of scene will be displayed. The only way to avoid this is to use double-buffering.

Another thing is that second buffer doesn't necessarily blit onto screen. There might be actually two buffers being swapped every frame, which will be faster than blitting. One of them will serve as screen (i.e. "primary surface"), while another will serve as backbuffer. Not sure if allegro works this way, though, but such option was widely used in DirectDraw, so if Allegro is hardware-accelerated, it should have similar functionality.

Quote:
Originally Posted by Ace Blackwell View Post
The only thing I can think of would be to draw numerous sprites to a memory bitmap and then transfer only the onces you want to the screen as you need them or using them repeatedly without redrawing.
This won't be possible if screen has serious amount of movement (entire screen scrolls, etc.)
Anyway, everything that changes (animated/moving) should appear on screen at once, otherwise it might flicker and some spirtes might even disappear (if you accidentally "synchronize" redrawing with display refresh rate). That's why double-buffering is needed.

Last edited by ErV; 02-12-2009 at 05:46 PM.
 
Old 02-13-2009, 08:06 AM   #3
Ace Blackwell
Member
 
Registered: Mar 2004
Location: Kentucky, USA
Distribution: SlamD 12.1 / Slack 12.0 ~ 14.2_64
Posts: 345

Original Poster
Rep: Reputation: 54
Thanks, This is a bit over my head at this point, but it makes sense and should help me to catch on a little quicker.

Along the Double Buffering lines. I seen where I can download templates for sprites (humanoid) and alter them in a paint shop editor. My question is how do you use them in program. Do you pull the template into a memory screen and them pull off what you need as you need them or is there another way to get them in a program?

Thanks
Ace

Last edited by Ace Blackwell; 02-13-2009 at 08:13 AM. Reason: Another Question
 
Old 02-13-2009, 09:19 AM   #4
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by Ace Blackwell View Post
Thanks, This is a bit over my head at this point, but it makes sense and should help me to catch on a little quicker.

Along the Double Buffering lines. I seen where I can download templates for sprites (humanoid) and alter them in a paint shop editor. My question is how do you use them in program. Do you pull the template into a memory screen and them pull off what you need as you need them or is there another way to get them in a program?

Thanks
Ace
Look, I don't work with Allegro (but flickering and reasons to use double-buffering are common across all apis/libraries - it even applies to complicated gui widgets), I prefer SDl+OpenGL(even for 2D) and I have experience with DirectDraw, so I can't give detail on how to do it in allegro.

In general, to draw sprite on screen, you need to load it onto surface(in 2D) or texture(in 3D), blit surface onto backbuffer (or draw textured polygon onto backbuffer), then swap(or "flip") buffers or blit backbuffer onto screen. I'd recommend to check allegro documentation.

In SDL you would use SDL_image library (supports most common formats) to load pictures onto surfaces, surface blitting functions(SDL_BlitSurface) for blits (or OpenGL functions to draw polygons) and SDL_Flip to swap buffers(or SDL_GL_SwapBuffers if used with OpenGL).

Last edited by ErV; 02-13-2009 at 09:23 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
vertical syncronization (double buffering) not working moeFEAR Linux - Desktop 2 12-27-2007 04:48 PM
Kaffeine always Buffering AvatarofVirgo Linux - General 1 10-13-2005 04:46 AM
turn off buffering suchi_s Programming 2 10-30-2004 07:14 AM
Regarding buffering with streams karthikvina Programming 0 09-04-2003 02:48 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration