C# Form flashing in DX9

Started by
4 comments, last by Trashcann 19 years, 10 months ago
Hey, I initialized DX9 in fullscreen, setting the cooperative level to a form, with FullscreenExclusive. When I render, I can see the form... border and all... flashing on the screen. Does anybody know how to stop that? My initialization code is as follows

public bool InitFullscreen(int Width, int Height, int BPP, Control Parent)
		{
			try
			{
				if (Parent != null)
				{
					// The user specified a form handle to render to
					SurfaceDescription description = new SurfaceDescription();		// Used to describe a surface
					
					mParent = Parent;

					mDisplay = new Device();

					// Link DirectDraw to the form handle given and tell it we are going to run in fullscreen
					mDisplay.SetCooperativeLevel(Parent, CooperativeLevelFlags.FullscreenExclusive);
					// Set the resolution and color depth
					mDisplay.SetDisplayMode(Width, Height, BPP, 0, false);

					// Define the attributes for the primary surface
					description.SurfaceCaps.PrimarySurface = true;
					description.SurfaceCaps.Flip = true;
					description.SurfaceCaps.Complex = true;
					// We are using Double Buffering, so start with one backbuffer.
					// NOTE: To change to Tripple Buffering, set this value to 2
					description.BackBufferCount = 1;

					// Create the primary surface
					mPrimary = new Surface(description, mDisplay);

					description.Clear();

					// A Caps is a set of attributes used by most DirectX objects
					SurfaceCaps caps = new SurfaceCaps();
					// Yes, we are using a backbuffer
					caps.BackBuffer = true;
					// Associate the primary buffer to backbuffer with specified caps
					mBackbuffer = mPrimary.GetAttachedSurface(caps);
					
					// Create the clipper
					mClipper = new Clipper(mDisplay);
					// Set the region to the parent
					mClipper.Window = Parent;
					// Set the clipper for the primary surface
					mPrimary.Clipper = mClipper;

					description.Clear();
				}
				// Initalized without error
				return true;
			}
			catch 
			{
				// There was an error initializing DirectDraw
				return false;
			}
		}   
ermokwww.truevision3d.com
Advertisement
Tell Windows Forms not to do its own rendering, that dirty bastard Call this code somewhere within your form''s initialization (constructor for instance):

SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
Now the background of the form doesnt show up, but I can still see the border, and I can see part of the IDE behind it :o
ermokwww.truevision3d.com
I don''t know if this is the best way, but for now I just set the FormBorderStyle to none and the BackColor to black.
ermokwww.truevision3d.com
The BackColor won''t matter, but yeah setting FormBorderStyle to None will fix it.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
The best way to fix all problems seems to be just mBackBuffer.ColorFill(Color.Black)
ermokwww.truevision3d.com

This topic is closed to new replies.

Advertisement