#include "d3d_init.h"
CD3D::CD3D()
{
d3d_interface = NULL;
d3d_device = NULL;
}
bool CD3D::CD3D_init( HWND hwnd )
{
int vp = 0;
D3DDEVTYPE deviceType;
d3d_interface = Direct3DCreate9( D3D_SDK_VERSION );
D3DCAPS9 si3D_caps;
d3d_interface->GetDeviceCaps( D3DADAPTER_DEFAULT, //Denotes primate display adapter.
deviceType, // Specifies the device type, usually D3DDEVTYPE HAL.
&si3D_caps ); // Return filled D3DCAPS9 structure that contains the capabilities of the primary display adapter.
// If the bit is "on" then that implies the hardware device supports it.
if ( si3D_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
{
// Yes, the bit is "on", so it is supported.
vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
else
{
// No, the bit is not "on", so it is not supported.
vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
if ( d3d_interface == NULL )
return false;
D3DPRESENT_PARAMETERS si3D_params = {0};
si3D_params.BackBufferFormat = D3DFMT_A8R8G8B8; // pixel format
si3D_params.SwapEffect = D3DSWAPEFFECT_DISCARD;
si3D_params.Windowed = true; // false = fullscreen ; true = windowed;
HRESULT result = d3d_interface->CreateDevice( D3DADAPTER_DEFAULT, // Primary Device
D3DDEVTYPE_HAL, // device type, hal = hardware vertex proc, ref = software vertex proc
hwnd, // window associated with the device
vp, // vertex proc type (HAL/REF)
&si3D_params, // present parameters
&d3d_device ); // returned created device.
if ( result == D3D_OK )
{
return true; // Could initialize D3D successfully
}
else if ( result != D3D_OK )
{
return false; // Coul dnot initialize D3D
}
}
Not all paths returned...
Hi,
I''m running into an error:
c:\documents and settings\dan joseph\my documents\visual studio projects\space invaders 3d\d3d_init.cpp(64): warning C4715: ''CD3D::CD3D_init'' : not all control paths return a value
I''m using Visual Studio .NET 2003, C++..
I cannot for the life of my find what I''ve done wrong. Can someone point it out?
Or just remove
if ( result != D3D_OK )
after the else at the bottom. It looks like its confusing the compiler.
Your problem is that your function is set to return a value, and it would theoretically be possible for it to run to the end without returning a value. Change your little block at the end to this:
if ( result == D3D_OK ) return true; // Could initialize D3D successfully else return false; // Coul dnot initialize D3D
Ahh, I did not realize I could run through that with the scenario of not finding a match in the if''s... Thank you all for your input. I wll be more careful on stepping thru my code. Now if I can get a grasp on the D3D initialization, this will be a successful night...
-Dan Joseph
-Dan Joseph
quote:Original post by djoseph74
Ahh, I did not realize I could run through that with the scenario of not finding a match in the if''s...
Technically it will never happen. But your compiler is not so smart that it can figure that out.
I recommend you change your bool CD3D::Init into
HRESULT CD3D::Init;
and the return value can be S_OK or E_FAIL.
you can use if ( FAILED ( Init(hWnd) ) ) or
if ( SUCCEEDED ( Init(hWnd) ) )
to detect that your application runs OK.
HRESULT CD3D::Init;
and the return value can be S_OK or E_FAIL.
you can use if ( FAILED ( Init(hWnd) ) ) or
if ( SUCCEEDED ( Init(hWnd) ) )
to detect that your application runs OK.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement