Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

drewslater

Fullscreen/Windowed Mode with C#

This topic is 5526 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to be able to use either windowed or fullscreen mode as well as be able to switch between them at the users discretion. Here is the code I have right now which only works for windowed mode:
private bool InitDirect3D()
		{
			PresentParameters pParams = new PresentParameters();

			if (userPrefs.bFullscreen)		// Fullscreen Settings

			{
				pParams.Windowed = false;
				pParams.SwapEffect = SwapEffect.Flip;
				pParams.BackBufferWidth = Convert.ToInt32(userPrefs.resolution.width);
				pParams.BackBufferHeight = Convert.ToInt32(userPrefs.resolution.height);
				pParams.BackBufferFormat = Format.A8B8G8R8;
			}
			else							// Windowed Settings

			{
				pParams.Windowed = true;
				pParams.SwapEffect = SwapEffect.Discard;
			}

			// Settings which are the same regardless of fullscreen setting

			pParams.DeviceWindow = renderPanel;
		
			try
			{
				device = new Device(0,DeviceType.Hardware, renderPanel, CreateFlags.HardwareVertexProcessing, pParams);
			
			}
			catch
			{
				MessageBox.Show("Error Initializing Direct3D - Make sure this machine meets the hardware requirements","Error");
			}

			return true;
		}
The only thing that needs explaination is probably the variable renderPanel. This is a reference to a panel which fills the entire form. Can anyone tell me what calls are required for changing between fullscreen/windowed mode. I know (i think) that Device.Reset must be called but what else? Thanks ATS

Share this post


Link to post
Share on other sites
Advertisement
I dunno about switching video modes in the middle of program execution, but I do know something you may want to fix in your code:

Many monitors (including my own) don't support A8B8G8R8 32-bit color. The following code can remedy this:

try
{
pParams.Format = Format.A8B8G8R8
}
catch
{
try
{
pParams.Format = Format.A8R8G8B8
}
catch(Exception e)
{
//do error handling

}
}



As for switching between windowed and fullscreen, you could try the following (althought I can't guarantee it will work):

device.Dispose();
device = null;
...
device = new Device(...);



[edited by - langguy on August 10, 2003 9:28:53 PM]

Share this post


Link to post
Share on other sites
Thanks for the tips. I changed the format to X8R8G8B8. The thing is that the code I have will work for windowed mode but if userPrefs.bFullscreen is true then I get an exception after the call to create the device. Is there anything I need to do besides set the pParams.DeviceWindow to the panel I want to draw to and also pass that same panel to the device constructor? Do I need to manually resize the form which I am rendering to? If so how do I do this in code? (as opposed to the IDE) Thanks.

ATS

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!