Bloom326984

Hi there,

I am having some problems with my screen flickering when I redraw my scene. Below is my code ...

private void tabPage16_Paint(object sender, PaintEventArgs e)

{

//clear the direct3d device

this.mDevice.Clear(ClearFlags.Target, Color.DimGray, 1.0f, 0);

//send the scene info

this.mDevice.BeginScene();

this.mDevice.VertexFormat = CustomVertex.PositionColored.Format;

this.mDevice.DrawUserPrimitives(PrimitiveType.TriangleList, this.mVerts.Length / 3, this.mVerts);

this.mDevice.EndScene();

//paint the scene info

this.mDevice.Present();

}

private void tabPage16_MouseMove(object sender, MouseEventArgs e)

{

int xDelta, yDelta;

xDelta = Cursor.Position.X - (this.Width / 2);

yDelta = Cursor.Position.Y - (this.Height / 2);

if ((xDelta == 0) && (yDelta == 0))

return;

//

// camera orient code

//

Cursor.Position = new Point(this.Width / 2, this.Height / 2);

this.tabPage16.Refresh();

}

}

So, I am using Direct3D in a C# app. I am using .Net 2.0. I got the latest (Oct 2006) DirectX 9 SDK. My problem comes from the moseMove event issuing the refresh command. Any time I move the mouse, I get serious flickering in my Direct3D device. I am familiar with the concept of doublebuffering, but I am relatively new to C# and Direct3D. I have my form set to be doublebuffered. If I understand correctly, the Direct3D calls of clear, beingScene, endScene, and present will ensure that my Direct3D device is doublebuffered also. My assumption is that the mouseMove event is flooding the form with paint events. I therefore used a tick timer to ensure that the paint event would only be processed at most 60 times a second, this didn't fix anything. I even commented out the calls to beginScene, drawUserPrimatives, and endScene; this didn't fix anything either. I am dumbfounded as to what my problem is. Any help would be appreciated.

Thanks in advance



Re: Game Technologies: DirectX 101 Direct3D Flickering Issue

Wessam Bahnassi

It seems like your control is performing a background clear when calling Refresh(). Change the control's behavior to make it stop painting the background and see if it removes the flickering...




Re: Game Technologies: DirectX 101 Direct3D Flickering Issue

Bloom

First of all, thanks for the help. I tried to implement what you suggested, and it doesn't seem to fix my problem. I added the following code ...

public Editor()

{

InitializeComponent();

this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque | ControlStyles.OptimizedDoubleBuffer, true);

}

protected override void OnPaintBackground(PaintEventArgs e)

{

//base.OnPaintBackground(e);

}

As far as I understand, adding the ControlStyle:Opaque should have stopped the background painting. That didn't seem to fix anything though, so I also overrode the OnPaintBackground event. This also didn't seem to help with anything. Like I said, I am relatively new to C#, .Net, and Direct3D; so maybe I am just not understanding what you are suggesting.

Thanks again





Re: Game Technologies: DirectX 101 Direct3D Flickering Issue

Bloom

Any other ideas how to solve this issue Thanks again



Re: Game Technologies: DirectX 101 Direct3D Flickering Issue

aka Andr3w Grammenos

Hey,

I don't know if this would help but you could increase the refresh ratio in order to eliminate the flickering, also use PIX in order to see the currect fps and statistics of your application! If you don't know how to use PIX now it's the time to learn how to do so! A good tutorial is at msdn and is a very good starting point :http://msdn.microsoft.com/library/default.asp url=/library/en-us/directx9_c/directx/directxsdk/Tools/Performance/PIX_Tutorial.asp. If this proved helpful say so if you require any more help drop a post ;)

Kindly,

~a.ka. Andr3w





Re: Game Technologies: DirectX 101 Direct3D Flickering Issue

Wessam Bahnassi

The functionality he's implementing is a "render-on-demand". That is, only when the mouse moves, which means there's no FPS in the first place. I'd double check that the control is not drawing anything behind my back because that's the only reason I can think of that would produce such a flicker. To find out if this is true or not, you can replace the call to Refresh() in your mouse move handler by a direct call to tabPage16_Paint(), which will skip all default paint behavior that Refresh() would do.





Re: Game Technologies: DirectX 101 Direct3D Flickering Issue

Etienne2005

I'm not sure it's your problem but it might be the OnEraseBkgnd handler

The Message WM_ERASEBACKGROUND is send and the default Handle erase the background each pass

Over ride this handler and remove the call to the base function so no erase background happen...





Re: Game Technologies: DirectX 101 Direct3D Flickering Issue

Bloom

Thanks everyone, doing what Wessam Bahnassi suggested worked. I am not sure why it worked exactly, but hey it worked :) As far as I understand, the background painting should already be ignored by my previous overriding of the PaintBackground method and the usage of an Opaque style. But anyways, thanks again for all your help to everyone



Re: Game Technologies: DirectX 101 Direct3D Flickering Issue

Milos Cvjeticanin

Thank you Wessam, you helped me as well!