1
\$\begingroup\$

I'm using DirectX 9 via SlimDX (C#). My screen flickers a lot during rendering. I dug a little deeper and see that the surface is being cleared early. Here's an example: http://pastebin.com/HXyAUwLp.

I'm using Windows XP on a low-end card. I've seen it act correctly on this computer, but I obviously have something wrong with my drawing routines or something and have reached the end of my resources.

The draw method starts at line 135 in that paste. To make the action more apparent, make sure the code in one or more of the preprocessor directives executes.

This shows that the buffer is being cleared before Present. I think things are supposed to work such that one scene to be visible until after Present, after which, the next scene is present. The user should never see the Cleared surface.

Let me know if you need more information.

\$\endgroup\$
7
  • \$\begingroup\$ i'm no dx expert, but i'm guessing it must be becouse you dont use double buffering. \$\endgroup\$
    – Toni
    Apr 27, 2012 at 14:46
  • \$\begingroup\$ Le pardon, but why are there 500-700ms Sleep calls in the code that have on/off switches? \$\endgroup\$
    – bobobobo
    Apr 27, 2012 at 15:01
  • \$\begingroup\$ @Toni Line 109 specified one back buffer. (Changing to 2 doesn't help.) \$\endgroup\$ Apr 27, 2012 at 15:04
  • \$\begingroup\$ @bobobobo I explained it in my question. It makes the problem more apparent. When sleeping before or after present, you see that during the sleep, the surface is black (which is, to the best of my knowledge, incorrect behaviour). \$\endgroup\$ Apr 27, 2012 at 15:05
  • \$\begingroup\$ I think it might have to do with the .net form's buffer settings. I believe you have to set it to double buffering also. \$\endgroup\$
    – Toni
    Apr 27, 2012 at 15:13

2 Answers 2

4
\$\begingroup\$

The answer doesn't have to do with DoubleBuffered, but rather with the default behaviour of System.Windows.Forms.Forms, which paint their own background when they need to paint. The answer is to add an override in the form:

protected override void OnPaintBackground(PaintEventArgs e)
{ }

Which fixes the problem.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ i stand corrected \$\endgroup\$
    – Toni
    Apr 27, 2012 at 16:02
1
\$\begingroup\$

Something to do with the .net controls not having doublebuffering enabled by default and the default redraw functionality.. There should be some ways to go around that.

Using slimdx's RenderForm instead of .net's Form works as you yourself noticed in above commentary.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks for the help. Did you run the example? \$\endgroup\$ Apr 27, 2012 at 15:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .