//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
void Device9::InitD3D( HWND hWnd,DevParam Parametros )
{
// Create the D3D object, which is needed to create the D3DDevice.
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
::MessageBox(hWnd,L"Error creando el objeto 3D/Error creating 3D object",L"Error Critico/Critical Error",MB_OK | MB_ICONERROR);
return;
}
// Set up the structure used to create the D3DDevice
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = Parametros.Windowed;
d3dpp.SwapEffect = Parametros.SwapEfect;
d3dpp.BackBufferHeight = X3D.resX;
d3dpp.BackBufferWidth = X3D.resY;
d3dpp.BackBufferCount = 1;
d3dpp.Flags = NULL;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.BackBufferFormat = Parametros.BackBuferFormat;
d3dpp.MultiSampleType = Parametros.MultisampleType;
d3dpp.MultiSampleQuality = Parametros.MultiSampleQuality;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
// Create the Direct3D device
if (Parametros.RenderType == Error)
{
::MessageBox(hWnd,TEXT("Imposible crear el dispocitivo/Can´t create device"),TEXT("Error Critico/Critical Error"),MB_OK | MB_ICONERROR);
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
g_pD3D = NULL;
Device = NULL;
return;
}
if (Parametros.RenderType == Hardware)
{
if( FAILED( g_pD3D->CreateDevice( Parametros.Adapter,Parametros.RasterizationType, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &Device ) ) )
{
::MessageBox(NULL,TEXT("Error creando el Dispocitivo por Hardware/Error creating the Hardware Device"),TEXT("Error Critico/Critical Error"),MB_OK | MB_ICONERROR);
}
}
if (Parametros.RenderType == Software)
{
if( FAILED( g_pD3D->CreateDevice( Parametros.Adapter,Parametros.RasterizationType, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &Device ) ) )
{
::MessageBox(NULL,TEXT("Error creando el Dispocitivo por Software/Error creating the Software Device"),TEXT("Error Critico/Critical Error"),MB_OK | MB_ICONERROR);
return;
}
}
if (Parametros.RenderType == Mixed)
{
if( FAILED( g_pD3D->CreateDevice( Parametros.Adapter,Parametros.RasterizationType, hWnd,
D3DCREATE_MIXED_VERTEXPROCESSING,
&d3dpp, &Device ) ) )
{
::MessageBox(NULL,TEXT("Error creando el Dispocitivo por Mescla/Error creating the Mixed Device"),TEXT("Error Critico/Critical Error"),MB_OK | MB_ICONERROR);
return;
}
}
return;
}