I have supplied my DirectX project: http://www.planetchili.net/forum/download/file.php?id=830
It has to be something simple but I just don't know the API well enough to find out where the problem is...
I think the following will help:
class D3DGraphics
{
public:
D3DGraphics( HWND hWnd );
~D3DGraphics();
void Begin();
void End();
void Present();
LPDIRECT3D9 d3dObject;
LPDIRECT3DDEVICE9 d3dDevice;
D3DPRESENT_PARAMETERS presParams;
HRESULT hr;
};
I declare a D3DGraphics class that starts up my object and device:
D3DGraphics::D3DGraphics( HWND hWnd )
:
d3dObject( NULL ),
d3dDevice( NULL )
{
ZeroMemory( &presParams, sizeof( presParams ) );
presParams.Windowed=TRUE;
presParams.SwapEffect=D3DSWAPEFFECT_DISCARD;
presParams.BackBufferFormat=D3DFMT_UNKNOWN;
presParams.PresentationInterval=D3DPRESENT_INTERVAL_ONE;
d3dObject = Direct3DCreate9( D3D_SDK_VERSION );
hr = d3dObject->CreateDevice(
D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&presParams,
&d3dDevice
);
};
My WindowsAPI is creating an instance of a Game class I have made which has constructor declared:
HWND hWnd = CreateWindow("MyWindowClass", "Pubes", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
Game theGame = Game( hWnd );
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
theGame.Go();
}
}
And finally here is my game class that is mucking up on the constructor as it can't create the sprite mentioned in the first block of code, here it is in full:
Game::Game( HWND hWnd )
:
gfx( hWnd )
{
sprite = NULL;
if ( SUCCEEDED( D3DXCreateSprite( gfx.d3dDevice, &sprite ) ) )
{
// returns s_OK
}
pos.x=10.0f;
pos.y=20.0f;
pos.z=0.0f;
gTexture = NULL;
if ( SUCCEEDED( D3DXCreateTextureFromFile( gfx.d3dDevice, "Images/character001.png", &gTexture ) ) )
{
// returns s_OK
}
gfx.d3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE); };
Game::~Game()
{
sprite->Release();
gTexture->Release();
};
void Game::Go()
{
gfx.Begin();
ComposeFrame();
gfx.Present();
gfx.End();
};
gfx is an instance of D3DGraphics declared in my Game class header.
gosh, you guys got any idea as to why my sprite isn't being rendered at all?
//Extra notes: I'm getting this in my output, this may have something to do with it??
My hWnd variable containing a handle to my window:
HWND hWnd = CreateWindow("MyWindowClass", "Pubes", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
Game theGame = Game( hWnd );
says:
- hWnd 0x000e0682 {unused=??? } HWND__ *
unused <Unable to read memory>