Jump to content

  • Log In with Google      Sign In   
  • Create Account

DirectX 9 Sprite Wont Display? See Code...


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 JeZ-l-Lee   Members   -  Reputation: 130

Like
0Likes
Like

Posted 31 October 2013 - 07:43 AM

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 );
}

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


Sponsor:

#2 Eck   Members   -  Reputation: 2786

Like
0Likes
Like

Posted 31 October 2013 - 08:24 AM

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



#3 JeZ-l-Lee   Members   -  Reputation: 130

Like
0Likes
Like

Posted 31 October 2013 - 08:34 AM

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 );
}

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



#4 Aerodactyl55   Members   -  Reputation: 149

Like
0Likes
Like

Posted 31 October 2013 - 08:53 AM

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


Edited by Aerodactyl55, 31 October 2013 - 09:04 AM.


#5 JeZ-l-Lee   Members   -  Reputation: 130

Like
0Likes
Like

Posted 31 October 2013 - 09:25 AM

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 );
}






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS