Flickering DX

When I use DirectX, my screen is flickering.
Is it common?

I know my videoBoard support the DX I’m using.

Hello !

When I use DirectX, my screen is flickering.
Is it common?

What do you mean with “flickering” ? Do you mean the same
thing that happens when playing games with VSYNC turned off ?

CU

When I use DirectX, my screen is flickering.

How? Directly or via SDL? If the latter, are you using SDL 1.2
(stable) or 1.3 (development)? (These have rather different video
subsystems.)

Is it common?

Yes, it’s perfectly normal if you’re?trying (and failing) to
perform “smart updates” (ie redraw only what’s changed) over a double
buffered hardware surface.

The reason is that a double buffered hardware surface normally uses
two actual VRAM surfaces that are flipped by SDL_FlipSurface(). No
copying is done, so the new “drawing page” you get after a flip is
two frames old, rather than identical to the last drawing page.

Simple solution: Always redraw the whole screen. Basically, assume
that the drawing page is filled with random garbage after a flip.

If you want to do it the hard (but in some cases, very fast) way, you
can have a look at my Fixed Rate Pig example (pig-1.0), which (among
other things) demonstrates one way of performing smart updates, even
on true page flipped displays:
http://olofson.net/mixed.html

For starters, just verify that “Pig” actually works in with a double
buffered hardware surface. (Retrace sync’ed frame rate probably; no
flickering, no tearing.)

I know my videoBoard support the DX I’m using.

I don’t think you would be able to set up a display at all if it
wasn’t.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Monday 05 November 2007, Miguel Pragier wrote:

Torsten Giebl <wizard syntheticsw.com> writes:

Hello !

When I use DirectX, my screen is flickering.
Is it common?

What do you mean with “flickering” ? Do you mean the same
thing that happens when playing games with VSYNC turned off ?

CU

Hi, Mr. Giebl.

The screen keeps blinking.
And blinking hard!

David Olofson <david olofson.net> writes:

When I use DirectX, my screen is flickering.

How? Directly or via SDL? If the latter, are you using SDL 1.2
(stable) or 1.3 (development)? (These have rather different video
subsystems.)

Thru SDL 1.2.

I don’t think you would be able to set up a display at all if it
wasn’t.

Yes, now I know :wink:

Every modern videoboard supports DoubleBuffering?
Or is this technique obsolete?

Thank you, mr. Olofson.> On Monday 05 November 2007, Miguel Pragier wrote:

[…]

The screen keeps blinking.
And blinking hard!

This sounds like the typical result of setting up a double buffered
display, drawing something and then going into a loop, flipping.

Basically, you need to draw stuff twice, or it’ll only be visible
every other frame, creating massive flickering.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Monday 05 November 2007, Miguel Pragier wrote:

David Olofson <david olofson.net> writes:

When I use DirectX, my screen is flickering.

How? Directly or via SDL? If the latter, are you using SDL 1.2
(stable) or 1.3 (development)? (These have rather different video
subsystems.)

Thru SDL 1.2.

I don’t think you would be able to set up a display at all if it
wasn’t.

Yes, now I know :wink:

Every modern videoboard supports DoubleBuffering?

Yes - and triple buffering, and other configurations as well. It’s
mostly limited by drivers and/or APIs.

Or is this technique obsolete?

It’s the only practical way of animating graphics without tearing or
flickering, so I don’t think it’s going away any time soon. :slight_smile:

However, there are many different ways of implementing double
buffering! There are basically two scenarios that you have to be
aware of when using SDL:

  1. The “real”, efficient method, which is what most serious
    drivers use when possible, is to have two separate buffers
    that are directly available to the video card’s RAMDAC.
    This way, a “flip” is only a matter of changing a pointer -
    no copying of graphics data needed.
    Flips may be synchronized with the display refresh to
    avoid pumping out frames that no one will see, and to avoid
    tearing. No guarantee though, as some platforms and drivers
    don’t support it, and many drivers come with it disabled
    in the driver settings by default.

  2. Another rather common method, used in most cases on Linux
    (OpenGL and X11 alike), SDL in windowed mode on most
    platforms etc, is to have only one actual display buffer,
    and perform flipping by physically copying the "drawing page"
    into the display buffer when “flipping”.

The second approach is slower and makes retrace sync very hard to do
properly (which causes tearing) - but it has the advantage that the
application is always rendering into the very same buffer, which
makes smart updates simpler to get right.

You can force SDL to use the second method by requesting a software
display surface, but then you definitely lose the retrace sync, and
have to rely on manual “throttling” to avoid a constant 100% CPU
load. Well, you should actually have that throttling logic either
way, as you don’t know if you’ll get retrace sync even if you get a
hardware display surface.

Now, if you redraw the whole screen every frame (like a full screen
scrolling game would do anyway), the difference between the modes is
irrelevant an far as flickering is concerned, as you never depend on
old data in the buffers. Obviously though, you don’t want to do this
in applications with mostly still screens, as it’s just be a waste of
CPU or GPU cycles and/or substantially raises the minimum system
requirements.

//David Olofson - Programmer, Composer, Open Source Advocate

.------- http://olofson.net - Games, SDL examples -------.
| http://zeespace.net - 2.5D rendering engine |
| http://audiality.org - Music/audio engine |
| http://eel.olofson.net - Real time scripting |
’-- http://www.reologica.se - Rheology instrumentation --'On Monday 05 November 2007, Miguel Pragier wrote:

On Monday 05 November 2007, Miguel Pragier wrote: