Jump to content
  • Advertisement
Sign in to follow this  
alop125125

Very Basic Question that will make all of us facepalm

This topic is 635 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

I am just getting back into d3d9 and i cannot get my program to work please help

void D3D9CLASS::initD3D(HWND hwnd)
{
 
d3d = Direct3DCreate9(D3D_SDK_VERSION);
 
D3DPRESENT_PARAMETERS d3dpp;
 
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hwnd;
 
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
 
}
d3d is in the class public
Edited by alop125125

Share this post


Link to post
Share on other sites
Advertisement
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);

 

 

hal and software vertex processing doesn't sound right...   might give you something like E_INVALIDCALL instead of D3D_OK as a return result.  make sure those params are not mutually exclusive.

 

here's the startup code from Caveman 3.0 (a dx9 app)...

 

do adapter stuff determines the screen resolution to use.

 

code blocks are being a pain to edit as usual, so the code is shown in blue text.

 

void do_adapter_stuff(int *w2,int *h2)
{
int num_adaptor_modes,i,w,h;
D3DDISPLAYMODE d[50];
HRESULT result;
FILE *f;
char s[100],s2[100];
if (filefound("startup_rez.dat"))
    {
    f=infile("startup_rez.dat");
    w=readfileint(f);
    h=readfileint(f);
    fclose(f);
    *w2=w;
    *h2=h;
    if (Zdebug)
        {
        i2s(w,s);
        strcat_s(s,100," x ");
        i2s(h,s2);
        strcat_s(s,100,s2);
        strcat_s(s,100," resolution specified in startup_rez.dat.");
        Zmsg(s,Zprogram_name);
        }
    return;
    }
if (Zdebug)
    {
    Zmsg("Getting adapter mode count",Zprogram_name);
    }
num_adaptor_modes=(int)d3d_obj_ptr->GetAdapterModeCount(D3DADAPTER_DEFAULT,D3DFMT_X8R8G8B8);
w=0; 
h=0;
if (Zdebug)
    {
    Zmsg("Enumerating adapter modes",Zprogram_name);
    }
for (i=0; i<num_adaptor_modes; i++)
    {
    result=d3d_obj_ptr->EnumAdapterModes(D3DADAPTER_DEFAULT,D3DFMT_X8R8G8B8,(UINT)i,&d);
    if (result!= D3D_OK) d.Width=0;
//  TODO: d3d_obj_ptr->CheckDeviceType d3d_obj_ptr->CheckDeviceFormat d3d_obj_ptr->CheckDepthStencilMatch
//  check for HAL support
result=d3d_obj_ptr->CheckDeviceType(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,D3DFMT_X8R8G8B8,D3DFMT_A8R8G8B8,FALSE);
if (result != D3D_OK)
    {
    d.Width=0;
    }
//  check for 24 bit depth stencil buffer support
result=d3d_obj_ptr->CheckDeviceFormat(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,D3DFMT_X8R8G8B8,D3DUSAGE_DEPTHSTENCIL,D3DRTYPE_SURFACE,D3DFMT_D24X8);
if (result != D3D_OK)
    {
    d.Width=0;
    }
//  check for depth stencil buffer compatability with front and back buffers
result=d3d_obj_ptr->CheckDepthStencilMatch(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,D3DFMT_X8R8G8B8,D3DFMT_A8R8G8B8,D3DFMT_D24X8);
if (result != D3D_OK)
    {
    d.Width=0;
    }
    if ((int)d.Width>w)
        {
        w=(int)d.Width;
        h=(int)d.Height;
        }
    else if ((int)d.Width==w)
        {
        if ((int)d.Height>h) h=(int)d.Height;
        }
    }
if (Zdebug)
    {
    i2s(w,s);
    strcat_s(s,100," x ");
    i2s(h,s2);
    strcat_s(s,100,s2);
    strcat_s(s,100," resolution auto-selected.");
    Zmsg(s,Zprogram_name);
    }
*w2=w;
*h2=h;
}
 

 

 

 

Zsetparams sets the present parameters...

 

 

void Zsetparams(int w,int h)

{
ZeroMemory(&Zparams,sizeof(D3DPRESENT_PARAMETERS));
Zparams.AutoDepthStencilFormat = D3DFMT_D24X8;
Zparams.BackBufferCount=1;
Zparams.BackBufferFormat = D3DFMT_A8R8G8B8;              // set the back buffer format to 32-bit      // turn these on for fullscreen
Zparams.BackBufferWidth = (unsigned)w;                          //width;    // set the width of the buffer
Zparams.BackBufferHeight = (unsigned)h;                          //height;    // set the height of the buffer
Zparams.EnableAutoDepthStencil = TRUE;                   // automatically run the z-buffer for us
Zparams.Flags=0;
Zparams.FullScreen_RefreshRateInHz=D3DPRESENT_INTERVAL_DEFAULT;
Zparams.hDeviceWindow=Zprogram_window_handle;
Zparams.MultiSampleQuality=0;
Zparams.MultiSampleType=D3DMULTISAMPLE_NONE;
Zparams.PresentationInterval=D3DPRESENT_INTERVAL_DEFAULT;
Zparams.SwapEffect = D3DSWAPEFFECT_COPY;                 //D3DSWAPEFFECT_DISCARD;
Zparams.Windowed = FALSE;                                // TRUE for windowed, FALSE for fullscreen
}
 
 
 
and Zinit3D  creates the device...
 
 
 
// init 3d stuff.  returns 1 on success, 0 on failure.
int Zinit3D(float nearplane,int farplane)
{
HRESULT result; 
D3DXMATRIX m;
D3DMATERIAL9 material;
int width,height;
 
if (Zdebug)
    {
    Zmsg("Creating D3D object",Zprogram_name);
    }
 
d3d_obj_ptr=Direct3DCreate9(D3D_SDK_VERSION);
if (d3d_obj_ptr==NULL) 
    { 
    Zmsg("Error creating D3D object",Zprogram_name); 
    return(0); 
    }
 
do_adapter_stuff(&width,&height);
 
 
Zsetparams(width,height);
 
if (Zdebug)
    {
    Zmsg("Creating device",Zprogram_name);
    }
 
result=d3d_obj_ptr->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,Zprogram_window_handle,
                                 D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,                          // D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                 &Zparams,&Zd3d_device_ptr);
if (result != D3D_OK) { Zmsg("Error creating D3D device.",Zprogram_name); d3d_obj_ptr->Release(); return(0); }
 
// gone 3d, turn off windows mouse cursor.
ShowCursor(FALSE);
 
 
etc
 
etc
 
etc
 
 

 

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

I am just getting back into d3d9

 

In addition to checking the return codes (which is the best answer), I have to ask:  Why are you targeting D3D9?

 

DirectX was integrated into the OS core components.  D3D9 is Windows XP.  Is your game targeting Windows XP?

 

If your game targets Windows 7, prefer to use D3D11 unless there is a compelling reason not to. That is where you will get best performance.

 

Same thing for Windows 8 using Direct3D 11.1, Windows 8.1 using 11.2, and Windows 10 using 12. 

 

 

Generally you should use the version that most closely matches your minimum operating system, then detect the card's feature set for the functionality it supports.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!