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