DXUT - EmptyProject
Empty Project
This tutorial is an introduction to getting a bare-bones DirectX9.0c
application configured and running. Note: While we could get started
on our own class framework to take care of the lower-level Windows initialization
for us, there really isn’t much point if the goal is to just learn
the beginning tasks of using DirectX.
EmptyProject == Hello World
For our basic “Hello World” type of tutorial using the DXUT framework, we’re going to create an
empty shell of an application which will:
- Launch the app and handle our registration with the Windows OS
- Query our video hardware to create a default Direct3D device
- Display a solid blue background to the monitor
DXUT
The DXUT (or my own nickname, the DirectX Utility Toolkit) set of classes / methods is a result
of feedback from the DirectX common framework that was included with the
DirectXSDK in 7.0 and 8.0/8.1. As with the previous common frameworks,
the DXUT is meant to be a quick way to spin up access to DirectX. However, instead
of using a class framework approach, where the developer must inherit from
a class such as CD3DApplication, the DXUT system revolves around using
a callback mechanism. The strength of this approach is that you can just about
drop DXUT right into an existing engine without too much work, whereas the
CD3DApplication approach might be incompatible with your current game’s engine.
The two other significant points about DXUT is that:
- Unicode The project must be compiled to support the Unicode character set, opening up
your project to multi-language environments. - Uses the D3DX helper library as a DLL For this reason, it’s important the
properly version of DirectX9.0c is also installed on the client’s machine that you
wish to deploy to.
Winmain - Launching the application
Every Windows application from games to business applications need to register
themselves properly with the Windows operating system, in order to fit properly
into the Windows event model of operations. The first step of this process
is to always define a WinMain entry point into your application.
INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
// Set the callback functions
DXUTSetCallbackDeviceCreated( OnCreateDevice );
DXUTSetCallbackDeviceReset( OnResetDevice );
DXUTSetCallbackDeviceLost( OnLostDevice );
DXUTSetCallbackDeviceDestroyed( OnDestroyDevice );
DXUTSetCallbackMsgProc( MsgProc );
DXUTSetCallbackFrameRender( OnFrameRender );
DXUTSetCallbackFrameMove( OnFrameMove );
// TODO: Perform any application-level initialization here
// Initialize DXUT and create the desired Win32 window and Direct3D device for the application
DXUTInit( true, true, true ); // Parse the command line, handle the default hotkeys, and show msgboxes
DXUTSetCursorSettings( true, true ); // Show the cursor and clip it when in full screen
DXUTCreateWindow( L"EmptyProject" ); // Make sure the string is converted to UNICODE using the L
DXUTCreateDevice( D3DADAPTER_DEFAULT, true, 800, 600, IsDeviceAcceptable, ModifyDeviceSettings );
// Start the render loop
DXUTMainLoop();
// TODO: Perform any application-level cleanup here
return DXUTGetExitCode();
}
This is the “core” of a DXUT app; configuring the callback mechanism. Through the use
of a concept in C++ known as function pointers, you can just about drop
any function declaration into this method (provided they follow the base template
of course).
For example, take a quick look at our OnCreateDevice function declaration in the code…
//--------------------------------------------------------------------------------------
// Create any D3DPOOL_MANAGED resources here
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
return S_OK;
}
So whenever the DXUT processing core hits the DXUTCallbackDeviceCreated function, it
is now pointing to the one declared in your application. Easy peasy.
Most of the DXUT framework appears similar to the virtual function methods provided
in the DirectX common frameworks of DirectX7 and DirectX8.0/8.1, so about the
only other interesting thing in this “EmptyProject” is the rendering callback,
OnFrameRender.
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
HRESULT hr;
// Clear the render target and the zbuffer
V( pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 45, 50, 170), 1.0f, 0) );
// Render the scene
if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
V( pd3dDevice->EndScene() );
}
}
There isn’t really much more than that. The sample code chooses a default display mode for our use, but
you can leave this out if you want to force the user to select their video settings.
Further “tweaks”
In the current version of the sample code, if we’re specifying that we want a windowed device, then we
set the display parameters to match the width and height of the device. If we want a fullscreen device,
then we simply use the default parameters that we chose in the DXUTCreateDevice core.
DXUTCreateDevice( D3DADAPTER_DEFAULT, false, 800, 600, IsDeviceAcceptable, ModifyDeviceSettings );
That’s it for this lesson. We covered some of the basics behind the DXUT objects
which is a different approach from the class framework system used in the DirectX7
and DirectX8.0/8.1 SDKs, and we were able to get our first “Hello World” application up and running!
Download
Download the project files here: dxut-emptyproject
Feedback? Comments?
Either comment to this posting, or use our contact
form to get in touch with us.









This is default description text on Padangan Themes, of course you can change this text via you profile administration.