Google Ads

Questions for the Author?

Navigation

 ·   Wiki Home
 ·   Wiki Help
 ·   Categories
 ·   Title List
 ·   Uncategorized Pages
 ·   Random Page
 ·   File Upload
 ·   Uploaded Files
 ·   Recent Changes
 ·   RSS
 ·   Atom
 ·   What Links Here

Active Members:

Search:

 

Create or Find Page:

 

View DirectX 9 Sample Framework Notes

DirectX 9 Sample Framework for C

Getting Oriented

After installing the August 2007 DirectX SDK, the pertinent files are stored here:

C:\Program Files\Microsoft DirectX SDK (August 2006)\

In the Samples\Managed directory, you'll find several directories:

  • Common - contains the Sample Framework and support files, which are referred to by the other samples in the SDK. It also has some basic GUI stuff in it too.
  • Direct3D - sample projects, including EmptyProject, which is the "shell" without anything in it.
  • DirectINput - joystick, mouse, keyboard, force feedback devices
  • DirectSound - sound playback, including 3D sound
  • Misc - DirectX diagnostic (?) routines

To use the Framework, the contents of the Common directory are added to your project. Alternative, you could copy the EmptyProject project out of the Direct3D sample folder.

EmptyProject Main()

Tracing the Main() function in EmptyProject.cs

  • Create a Framework objected called sampleFramework. The Framework class is defined in Microsoft.Samples.DirectX.UtilityToolkit, in file Common\dxmut.cs
  • Create an instance of itself called sample and pass sampleFramework at construction time.
  • Tell the framework to pass several callback functions that handle device events: disposing, lost, creation, resetting back to the sample.
  • Tell the framework where the window callback function is (in sample).
  • Tell the framework where the callback interface is. It's here, in our emptyProject.

NEXT: The sample calls function InitializeApplication()

  • creates the HUD buttons (common to all samples), hooks them to specific handlers
  • creates sample-specific buttons

NEXT: The sample calls the Framework to do some work:

  • sampleFramework.Initialize() to parse command line, hotkeys, message boxes
  • sampleFramework.CreateWindow("EmptyProject") to create the window

NEXT: When the window was created, sampleFramework.Window returns the window object, so we can start hooking things into it:

  • sampleFramework.Window keyDown Handler gets set

NOW: We can finally create the DirectX device

  • sampleFramework.CreateDevice() does the work.

WRAPPING UP: Call the Framework's MainLoop() method:

  • sampleFramework.MainLoop()

And that's pretty much it. The MainLoop() sets up the

Then, set up various handlers:

  •             // Initialize the sample framework and create the desired window and Direct3D 
                // device for the application. Calling each of these functions is optional, but they
                // allow you to set several options which control the behavior of the sampleFramework.
                sampleFramework.Initialize( true, true, true ); // Parse the command line, handle the default hotkeys, and show msgboxes
                sampleFramework.CreateWindow("EmptyProject");
                // Hook the keyboard event
                sampleFramework.Window.KeyDown += new System.Windows.Forms.KeyEventHandler(sample.OnKeyEvent);
                sampleFramework.CreateDevice( 0, true, Framework.DefaultSizeWidth, Framework.DefaultSizeHeight, 
                    sample);
    
                // Pass control to the sample framework for handling the message pump and 
                // dispatching render calls. The sample framework will call your FrameMove 
                // and FrameRender callback when there is idle time between handling window messages.
                sampleFramework.MainLoop();