DirectX 9 Sprite Wont Display? See Code...

Started by
3 comments, last by JeZ-l-Lee 10 years, 6 months ago

Hi,

I am trying to display a DirectX 9 Sprite but I cant seem to get it to display on the screen?

All I get is a black screen and no sprite is drawn?

Code is below, any help would be appreciated - thanks!

JeZ+Lee


//-------------------------------------------------------------------------------------------------------------------------------
void loadTexture( void )
{
    D3DXCreateTextureFromFileEx(DXDevice, L"TC5-Logo.png",  D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
		                D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &SpriteTexture);
}

//-------------------------------------------------------------------------------------------------------------------------------
void render( void )
{
    DXDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

    D3DSURFACE_DESC textureInfo;
    SpriteTexture->GetLevelDesc(0, &textureInfo);
    RECT spriteRect;
    spriteRect.top = 0;
    spriteRect.left = 0;
    spriteRect.bottom = textureInfo.Height;
    spriteRect.right = textureInfo.Width;

    Sprite->Begin(D3DXSPRITE_ALPHABLEND);

	
    D3DXVECTOR3 spritePosition;
    spritePosition.x = 0.0f;
    spritePosition.y = 0.0f;
    spritePosition.z = 0.0f;

    Sprite->Draw(SpriteTexture, &spriteRect, NULL, &spritePosition, NULL);

    Sprite->End();

    DXDevice->Present( NULL, NULL, NULL, NULL );
}

//-------------------------------------------------------------------------------------------------------------------------------

JeZxLee
Fallen Angel Software
www.FallenAngelSoftware.com

Advertisement

You're calling Sprite->Draw with a NULL color. I've not messed around with DirectX 9 much, but the quick searches I've done leads me to believe you should be passing "white" with maximum alpha. I'm not sure if NULL assumes white, or if it would be 'invisible'.

From MSDN:

The color and alpha channels are modulated by this value. A value of 0xFFFFFFFF maintains the original source color and alpha data. Use the D3DCOLOR_RGBA macro to help generate this color.

- Eck

EckTech Games - Games and Unity Assets I'm working on
Still Flying - My GameDev journal
The Shilwulf Dynasty - Campaign notes for my Rogue Trader RPG

You're calling Sprite->Draw with a NULL color. I've not messed around with DirectX 9 much, but the quick searches I've done leads me to believe you should be passing "white" with maximum alpha. I'm not sure if NULL assumes white, or if it would be 'invisible'.

From MSDN:

The color and alpha channels are modulated by this value. A value of 0xFFFFFFFF maintains the original source color and alpha data. Use the D3DCOLOR_RGBA macro to help generate this color.

- Eck

Hi,

Thanks for you reply, I added the color, but still no display of sprite on the screen.

Any other ideas?

Current code is below...

JeZ+Lee


//-------------------------------------------------------------------------------------------------------------------------------
void loadTexture( void )
{
    D3DXCreateTextureFromFileEx(DXDevice, L"TC5-Logo.png",  D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0,
		                D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &SpriteTexture);
}

//-------------------------------------------------------------------------------------------------------------------------------
void render( void )
{
    DXDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

    D3DSURFACE_DESC textureInfo;
    SpriteTexture->GetLevelDesc(0, &textureInfo);
    RECT spriteRect;
    spriteRect.top = 0;
    spriteRect.left = 0;
    spriteRect.bottom = textureInfo.Height;
    spriteRect.right = textureInfo.Width;

    Sprite->Begin(D3DXSPRITE_ALPHABLEND);

    D3DXVECTOR3 spritePosition;
    spritePosition.x = 0.0f;
    spritePosition.y = 0.0f;
    spritePosition.z = 0.0f;

    Sprite->Draw( SpriteTexture, &spriteRect, NULL, &spritePosition, D3DCOLOR_RGBA(255,255,255,255) );

    Sprite->End();

    DXDevice->Present( NULL, NULL, NULL, NULL );
}

//-------------------------------------------------------------------------------------------------------------------------------

JeZxLee
Fallen Angel Software
www.FallenAngelSoftware.com

ID3DXSprite::Begin()/ID3DXSprite::Draw()/ID3DXSprite::End must be called inside a IDirect3DDevice9::Begin()/IDirect3DDevice9::End() Block.

ID3DXSprite::Begin()/ID3DXSprite::Draw()/ID3DXSprite::End must be called inside a IDirect3DDevice9::Begin()/IDirect3DDevice9::End() Block.

Hi,

Thanks! I got it working now...

JeZ+Lee


void render( void )
{
    DXDevice->BeginScene();

    DXDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

    Sprite->Begin(D3DXSPRITE_ALPHABLEND);

    D3DSURFACE_DESC textureInfo;
    SpriteTexture->GetLevelDesc(0, &textureInfo);
    RECT spriteRect;
    spriteRect.top = 0;
    spriteRect.left = 0;
    spriteRect.bottom = textureInfo.Height;
    spriteRect.right = textureInfo.Width;

    D3DXVECTOR3 spritePosition;
    spritePosition.x = 0.0f;
    spritePosition.y = 0.0f;
    spritePosition.z = 0.0f;

    Sprite->Draw( SpriteTexture, &spriteRect, NULL, &spritePosition, D3DCOLOR_RGBA(255,255,255,255) );

    Sprite->End();

    DXDevice->EndScene();
    DXDevice->Present( NULL, NULL, NULL, NULL );
}

JeZxLee
Fallen Angel Software
www.FallenAngelSoftware.com

This topic is closed to new replies.

Advertisement