0

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> 
Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233
  • 1
    `If the function succeeds, the return value is S_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL, E_OUTOFMEMORY.` - Mind finding out which it is? – chris Mar 20 '13 at 02:09
  • Do these images help? I put a break in the first SUCCEEDED if statement and it skipped past and ended up with that in the output log – Jimmyt1988 Mar 20 '13 at 02:16
  • You're interested in the return value of `D3DXCreateSprite()`. Compare it against those two constants to see which it is. – chris Mar 20 '13 at 02:25
  • Sorry, how do I do that? I'm pretty new to both DX and c++ – Jimmyt1988 Mar 20 '13 at 02:34
  • Just save the return value in a variable and see if `result == D3DERR_INVALIDCALL` or `result == E_OUTOFMEMORY`. – chris Mar 20 '13 at 02:40
  • I'm installing SDK on my laptop so I can try that out... Sorry for late reply, totally fell asleep this morning (UK) and have work now ^_^ – Jimmyt1988 Mar 20 '13 at 10:08
  • It returns S_OK :(, so it's not that failing... I have no idea why my sprite ain't coming up then gawdammit – Jimmyt1988 Mar 20 '13 at 11:59

1 Answers1

0
gfx.Begin();
ComposeFrame();
gfx.End();
gfx.Present();

I was presenting before ending the scene!!!

YIPEEEE

Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233