One thing I’ve been telling people for quite some time is to blit the
contents of the front buffer onto the back buffer immediately after
flipping (or vice versa, immediately before flipping.) However, this
seems to suggest you can’t do this in SDL:
- SDL_Flip(). This is usually slower than the normal single-buffering
- scheme, but prevents “tearing” artifacts caused by modifying video
- memory while the monitor is refreshing. It should only be used by
- applications that redraw the entire screen on every update.
I think I used to do this using DirectX, or possibly some other
graphics API, and somehow got it into my head that you could do it in
SDL as well.
The solution then would be to either recreate the screen from scratch
each frame, or, sync the contents of both buffers. Keeping then
synchronized may be less costly depending on your particular
application, but here are a few simple steps that can get you
synchronizing in no time.
First, if you haven’t already done so, disassociate all drawing
routines from “progress” routines. This means that code that affects
the game’s state should be separated from the code that affects the
screen’s state.
Second, alter your main game routine so that it progress your game
state first, and performs actual drawing second.
Third, after performing the flip, simply reinvoke the same code you
used to draw the last frame, only this time, you will be operating on
what will become your future drawing surface.
I hope I wasn’t too ambiguous with step three. No matter, I think it’s
not too hard to understand even if I neglected to actually spell out
step three anyhow.
Hope this helps.On Sep 16, 2004, at 11:24 PM, Drake Wilson wrote:
Quoth Benjamin Sonnemann <B.Sonnemann at t-online.de>, on 2004-09-17
01:12:28 +0200:
Sorry if this is a stupid Question, but how can i write to each
buffer?
I mean, i thought i only must write to the surface i flip?
But when you’re double-buffering you have two buffers that correspond
to the same “surface”. You’re generally always drawing to the back
buffer, whereas the front buffer is what’s being displayed; then the
flip operation causes the back buffer to become the new front buffer
et vice versa. Example (someone correct this if I’ve made glaring
mistakes, please):
Back buffer Front buffer
----------- ------------
Start (empty) (empty)
Draw square square (empty)
Flip! (empty) square
Draw circle circle square
Flip! square circle
No square in front buffer!
If you wanted the square to appear in the front buffer in this case,
you would also have to draw it on the second buffer:
Back buffer Front buffer
----------- ------------
Start (empty) (empty)
Draw square square (empty)
Flip! (empty) square
Draw square square square
Draw circle circle square
square
Flip! square circle
square
Incremental drawing on double-buffered video surfaces tends to be a
pain, for this reason; my impression is that mostly when drawing to
double-buffered surfaces, people simply clear the buffer at each
frame, then redraw everything, since it’s significantly easier…
—> Drake Wilson
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl