1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object.
if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Get the current desktop display mode, so we can set up a back
// buffer of the same format
D3DDISPLAYMODE d3ddm;
if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice. Since we are now
// using more complex geometry, we will create a device with a zbuffer.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.BackBufferHeight = 1024;
d3dpp.BackBufferWidth = 1280;
d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE;
// Create the D3DDevice
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
// Turn on the zbuffer
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
// camera
eye.x = 0; eye.y = 10; eye.z = 0;
lookat.x = 0; lookat.y = 10; lookat.z = 1;
up.x = 0; up.y = 1; up.z = 0;
// projection
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 200.0f );
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
// fonts
LOGFONT LogFont = {24,0,0,0,FW_NORMAL,false,false,false,
DEFAULT_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,DEFAULT_PITCH,"Arial"};
// init de la font
FontPosition.top = 0;
FontPosition.left = 0;
FontPosition.right = 640;
FontPosition.bottom = 50;
D3DXCreateFontIndirect(g_pd3dDevice ,&LogFont, &g_Font);
// fog
SetupVertexFog(D3DCOLOR_COLORVALUE(0.2,0.1,0.1,1), D3DFOG_LINEAR, TRUE, 1);
return S_OK;
} |
Partager