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
Fullscreen/Windowed Mode with C#
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:
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:
As for switching between windowed and fullscreen, you could try the following (althought I can't guarantee it will work):
[edited by - langguy on August 10, 2003 9:28:53 PM]
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]
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
ATS
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement