Archived

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

Initialization of D3D9

This topic is 5200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi! Ive got Problems with my Ini-Code for D3D9: heres the Code, i dont know how to use Code-Tags or screenhots ... config is a struc that has the information for the Device
// Create Direct3D-Interface

m_Direct3D = Direct3DCreate9(D3D_SDK_VERSION);
// Get Device Cpas

// Get Number of Videomaodes for wished format

// if nothing exist, it ends

if(ModeNum == 0)
{
m_Direct3D->Release();
return ME_ERROR;
}

// CreateArray for viedomodes

D3DDISPLAYMODE* VideoModes = new D3DDISPLAYMODE[ModeNum];

// Counter for Modes

int Mode = 0;

if(Windowed)
{
// In window you use the current Format

Mode = 0;
}
else
{
for(Mode = 0; Mode < ModeNum; Mode++)
{
// fill Array of modes

format, // R5G6B5

&VideoModes[Mode]);

// found wished mode? Width and heigt are parameters

if(VideoModes[Mode].Width == Width && VideoModes[Mode].Height == Height)
break;
}
}

// Test, whether the format for The z-Buffer can be used

if(FAILED(m_Direct3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, VideoModes[Mode].Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, VideoModes[Mode].Format))
D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8)))
{
// if not, then error

delete [] VideoModes;
m_Direct3D->Release();
return ME_ERROR;
}

ZeroMemory(config, sizeof(meScreenConfig));
config->BackBufferFormat = VideoModes[Mode].Format;
config->ZStencilFormat = D3DFMT_D24S8;
config->DevType = D3DDEVTYPE_HAL;
config->DisplayMode = VideoModes[Mode];
config->DisplayMode.Width = Width;
config->DisplayMode.Height    = Height;
config->Windowed = Windowed;

// check wheter using the ure device or Software Raster

if(!(m_D3DCaps.DevCaps & D3DDEVCAPS_HWRASTERIZATION) || !(m_D3DCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT))
{
config->Flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
else if(m_D3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE)
{
config->Flags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
else
{
config->Flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}

config->MultiSampleType = D3DMULTISAMPLE_NONE;
config->MultiSampleQuality = 0;

delete [] VideoModes;
m_Direct3D->Release();
m_Direct3D = NULL;

// Then PresentParams are fille dupt with the info

m_Direct3D = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;

d3dpp.BackBufferWidth = config->DisplayMode.Width;
d3dpp.BackBufferHeight = config->DisplayMode.Height;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = config->DisplayMode.Format;
d3dpp.MultiSampleType = config->MultiSampleType;
d3dpp.MultiSampleQuality = config->MultiSampleQuality;
d3dpp.hDeviceWindow = m_AppWnd; // wurde vorher erstellt

d3dpp.Windowed = config->Windowed;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = config->ZStencilFormat;
d3dpp.FullScreen_RefreshRateInHz = 0;
d3dpp.PresentationInterval    = D3DPRESENT_INTERVAL_DEFAULT;

if(FAILED(m_Direct3D->CreateDevice(config->Adapter, config->DevType, m_AppWnd, config->Flags, & d3dpp, &m_D3DDevice)))
{
m_Direct3D->Release();
meErrorLog("Fehler beim ERstellen der Geräteschnittstelle (PDIRECT3D::CreateDevice())");
return ME_ERROR;   // It failes at Geforce 2

}

Do you know what to do? [edited by - The Only on November 28, 2003 2:18:13 PM]

Share on other sites
Perhaps you could be a bit more specific about what the problem is exactly?

You can use [ source ] and [ /source ] around code to make it nicer -- read the forum FAQ.

Share on other sites
YOu seem to be doing m_Direct3D = Direct3DCreate9(D3D_SDK_VERSION); twice, probably not a good idea, cant see any other problems

Share on other sites
d3dpp.FullScreen_RefreshRateInHz = 0; might be a problem here, not sure what the 0 value means, might want to use the value from D3DDISPLAYMODE::RefreshRate

Share on other sites
Yeah i know, but it works, coause i release it, it cnat be the problem

maybe its because of WinME?

Share on other sites
Hm, id ont know what to tell more about the problem...

It doesnt work on Geforce2. If you start, you can see the window, for about on second, and then it cloeses. But it could be also one reason if you use WinMe, I dont know.

Share on other sites
This piece of code is going to delete D3D regardless:

config->MultiSampleType = D3DMULTISAMPLE_NONE;config->MultiSampleQuality = 0;delete [] VideoModes;m_Direct3D->Release();m_Direct3D = NULL;// Then PresentParams are fille dupt with the infom_Direct3D = Direct3DCreate9(D3D_SDK_VERSION);D3DPRESENT_PARAMETERS d3dpp;

Edit: Formatting got screwed

---------------------------------------

Let's struggle for our dream of Game!

http://andrewporritt.4t.com

[edited by - f8k8 on November 28, 2003 7:23:37 PM]

Share on other sites
Also, this was causing it to drop out on mine:

	// if nothing exist, it ends 	if(ModeNum == 0)  	{ 	  m_Direct3D->Release(); 	  return ME_ERROR; 	}

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com

Share on other sites
Hm...
Thge Init-Code is divided into two functions, so I create on D3D-Object in the function that filles up the config struct, and one
that creates the Direct3DDevice.
The Prog crashes at CreateDevice...
Is it possible, that Gf2 doesnt support D3DDEVTTYPE_HAL ? But I dont think so...

Share on other sites
Use the debug Direct3D runtime and check the debug output. That should give you a more accurate error description.

Share on other sites
Ive only got my own PC, and it works on my machine...

Possibly you could check it out on your PCs?

Share on other sites
Its divided into two workspaces for VC6
One Dll and one Testprog. Just compile the Dll and put the lib into your libs folder and the dll into the output folder of the testprog.

Please, I need help, i need to knwo, what the problem is...