Graphics Enumeration and Launching the Game Form
When it comes time to write a new game, I'd like to be able to tell my graphics library the various screen styles that the game wants to make available to the player and then have the library figure out which ones are supported by the player's computer. This will be how Nimble2D does things ... receive a list of requested screen styles, look at each available adapter for support for the requested style, and provide back a list of available screen styles.
Here's how the graphics enumeration testing app starts things off:
Nimble2D = New clsNimble2D()
'At least 1 video adapter is needed to continue ...
If Nimble2D.Adapters_Count < 1 Then
Application.Exit()
Exit Sub
End If
'--- Change this list to reflect requested screen styles ---
Nimble2D.AddRequestedScreenStyle(800, 600, False)
Nimble2D.AddRequestedScreenStyle(800, 600, True, clsNimble2D.enumColorDepth.CD_32bit)
Nimble2D.AddRequestedScreenStyle(800, 600, True, clsNimble2D.enumColorDepth.CD_16bit)
Nimble2D.AddRequestedScreenStyle(900, 400, False)
Nimble2D.AddRequestedScreenStyle(1024, 768, True, clsNimble2D.enumColorDepth.CD_32bit)
Nimble2D.AddRequestedScreenStyle(1024, 768, True, clsNimble2D.enumColorDepth.CD_16bit)
'---
Then the start-up form cycles through the available styles for the selected adapter:
'Load Screen Styles List Box
If modGame.Nimble2D.AvailableScreenStyles_Count(Me.cboAdapters.SelectedIndex) > 0 Then
For j As Integer = 0 To modGame.Nimble2D.AvailableScreenStyles_Count(Me.cboAdapters.SelectedIndex) - 1
Me.lstScreenStyle.Items.Add(modGame.Nimble2D.AvailableScreenStyleName(Me.cboAdapters.SelectedIndex, j))
Next
Me.lstScreenStyle.SelectedIndex = 0
End If
That gets us this far: 
Once the player selects the adapter and screen style and clicks "Launch", the game's code creates an instance of a game form and asks Nimble2D to launch it on the requested adapter in the requested screen style:
GameForm = New frmGame()
Nimble2D.LaunchGameScreen(GameForm, AdapterIndex, ScreenStyleIndex)
Which results in this: 
So ... how's it done? Well, SlimDX (which is what Nimble2D uses to access DirectX) makes a number of enumeration functions and properties available. The available adapters are grabbed when Nimble2D is first constructed, using this code:
Direct3D.Initialize()
Me.varAdapters_Count = Direct3D.AdapterCount()
For j As Integer = 0 To Me.varAdapters_Count - 1
Me.varAdapter(j) = Direct3D.GetAdapterIdentifier(j).Description
Next
The handling of requested screen styles is a bit more complicated. So, instead of giving code here, I'll walk through the steps.
-
The supplied parameters for screen style are: Width, Height, FullScreen, and ColorDepth
-
If FullScreen = False, then the ColorDepth is assumed to be whatever the primary adapter is currently set to, and the screen style will be considered available as long as the Width and Height are smaller than the current screen size
-
If FullScreen = True, then each adapter is run through the various formats for the given ColorDepth in preference order. As soon as a supported format in the given Width and Height is found, then it is marked as available for that adapter. The first-found supported format is noted to be used later if that screen style is selected for the launch.
When the game requests for the game form to be launched, Nimble2D resizes the supplied game form to the width and height of the selected screen style, shows the form, and creates the Direct3D Device:
GameForm.Size = New Size(varSelectedScreenStyle.Width, varSelectedScreenStyle.Height)
GameForm.Show()
Dim presentparams As New PresentParameters
presentparams.BackBufferWidth = varSelectedScreenStyle.Width
presentparams.BackBufferHeight = varSelectedScreenStyle.Height
If varSelectedScreenStyle.FullScreen Then
presentparams.BackBufferFormat = varSelectedScreenStyle.BackBufferFormat
presentparams.Windowed = False
Else
presentparams.Windowed = True
End If
presentparams.DeviceWindowHandle = GameForm.Handle
varD3D_Device = New Device(AdapterIndex, DeviceType.Hardware, GameForm.Handle, CreateFlags.HardwareVertexProcessing, presentparams)
The next thing to tackle is the main skeleton structure that will be used to get graphics on the screen ... Game Spaces (and their cameras), Layers, and Sprites.
-Matt
p.s. When requesting a screen style that is full screen, only 16- and 32-bit color depths are allowed. The various formats (5 to 6 in each color depth) are checked in order of "preference". If someone reading this has strong knowledge about graphics formats and in what order preference should be given, please post a comment or send me an e-mail ... I have some questions for you. ;-)