4
LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice
5
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device
7
HRESULT InitD3D( HWND hWnd )
9
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
12
D3DPRESENT_PARAMETERS d3dpp;
13
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
14
d3dpp.Windowed = TRUE;
15
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
16
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
18
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
19
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
20
&d3dpp, &g_pd3dDevice ) ) )
30
if( g_pd3dDevice != NULL )
31
g_pd3dDevice->Release();
39
if( NULL == g_pd3dDevice )
42
// Clear the backbuffer to a blue color
43
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );
46
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
48
// Rendering of scene objects can happen here
51
g_pd3dDevice->EndScene();
54
// Present the backbuffer contents to the display
55
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
58
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
69
ValidateRect( hWnd, NULL );
73
return DefWindowProc( hWnd, msg, wParam, lParam );
76
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
78
// Register the window class
81
sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
82
GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
85
RegisterClassEx( &wc );
87
// Create the application's window
88
HWND hWnd = CreateWindow( L"D3D Tutorial", L"D3D Tutorial 01: CreateDevice",
89
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
90
NULL, NULL, wc.hInstance, NULL );
92
// Initialize Direct3D
93
if( SUCCEEDED( InitD3D( hWnd ) ) )
96
ShowWindow( hWnd, SW_SHOWDEFAULT );
99
// Enter the message loop
101
while( GetMessage( &msg, NULL, 0, 0 ) )
103
TranslateMessage( &msg );
104
DispatchMessage( &msg );
108
UnregisterClass( L"D3D Tutorial", wc.hInstance );