Archived

This topic is now archived and is closed to further replies.

d000hg

Screwing up my desktop.

Recommended Posts

Yeah, same as desktop resolution.

Here is my d3d init code

  BOOL D3DClass::InitD3D()
{
// create a Direct3D device

Output("Creating a D3D COM object...");
D3D = Direct3DCreate8( D3D_SDK_VERSION );
if(D3D == NULL)
{
Output("failed\n");
return FALSE;
}
Output("Succeeded\n");
NumAdapters=D3D->GetAdapterCount();
Devices=new LPDIRECT3DDEVICE8[NumAdapters];
ZeroMemory(Devices,NumAdapters*sizeof(LPDIRECT3DDEVICE8));
Adapters=new D3DADAPTER_IDENTIFIER8[NumAdapters];
Caps=new D3DCAPS8[NumAdapters];
NumModes=new UINT [NumAdapters];
DisplayModes=new D3DDISPLAYMODE *[NumAdapters];
for(unsigned i=0;i<NumAdapters;++i)
{
D3D->GetAdapterIdentifier(i,D3DENUM_NO_WHQL_LEVEL,&Adapters[i]);
D3D->GetDeviceCaps(i,D3DDEVTYPE_HAL,&Caps[i]);
NumModes[i]=D3D->GetAdapterModeCount(i);
DisplayModes[i]=new D3DDISPLAYMODE[NumModes[i]];
for(unsigned j=0;j<NumModes[i];++j)
D3D->EnumAdapterModes(i,j,&DisplayModes[i][j]);
}
return TRUE;
}


And this is the method to get rid of everything:

  void D3DClass::ShutD3D()
{
// first, release any devices we''ve created.

if(Devices != NULL)
{
for(UINT i=0;i<NumAdapters;++i)
if(Devices[i]!=NULL)
Devices[i]->Release();
delete [] Devices;
Devices = NULL; // just to be safe

}
Output("Released the d3d device(s)\n");
// next, release the direct3d interface.

if(D3D != NULL)
{
D3D->Release();
D3D = NULL; // just to be safe

}
Output("Released the d3d interface\n");

for(UINT i=0;i<NumAdapters;++i)
{
delete [] DisplayModes[i];
}
delete [] DisplayModes;
DisplayModes=NULL;
delete [] NumModes;
NumModes=NULL;
delete [] Adapters;
NumAdapters=0;
Adapters=NULL;

}


This gets called from my d3dclass'' destructor, the d3d class is deleted last thing before returning from WinMain.



Read about my game, project #1



John 3:16

Share this post


Link to post
Share on other sites