Archived

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

Initialization of D3D9

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

If you intended to correct an error in the post then please contact us.

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

m_Direct3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_D3DCaps) 

// Get Number of Videomaodes for wished format 

int ModeNum = m_Direct3D->GetAdapterModeCount(D3DADAPTER_DEFAULT, 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

  m_Direct3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &VideoModes[0]); 
  Mode = 0; 
}         
else   
{ 
  for(Mode = 0; Mode < ModeNum; Mode++) 
  { 
    // fill Array of modes 

    m_Direct3D->EnumAdapterModes(D3DADAPTER_DEFAULT,  
                                 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))  
     || FAILED(m_Direct3D->CheckDeviceFormat( D3DADAPTER_DEFAULT,  D3DDEVTYPE_HAL, 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->Adapter = D3DADAPTER_DEFAULT; 
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.SwapEffect = D3DSWAPEFFECT_DISCARD; 
d3dpp.hDeviceWindow = m_AppWnd; // wurde vorher erstellt 

d3dpp.Windowed = config->Windowed; 
d3dpp.EnableAutoDepthStencil = TRUE; 
d3dpp.AutoDepthStencilFormat = config->ZStencilFormat; 
d3dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; 
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 this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
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 info

m_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 this post


Link to post
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 this post


Link to post
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...

Share this post


Link to post
Share on other sites