Jump to content
  • Advertisement
Sign in to follow this  
Tingle

D3D9 and Sprites

This topic is 3073 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reson, im not getting my sprite on my screen :/. I got no errors, the sprite just doesnt want to draw, all I got is a white background (buffer fill color).

This my code:

LPD3DXSPRITE m_pD3DSprite;
D3DXCreateSprite(m_pD3DDevice, &m_pD3DSprite);

D3DXCreateTextureFromFileEx(
g_pD3D->m_pD3DDevice,
L"F:\\Orb\\Bin\\win32\\sprite.tga",
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
NULL,
D3DFMT_A8R8G8B8,
D3DPOOL_MANAGED,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DCOLOR_XRGB(255, 0, 255),
NULL,
NULL,
&testSprite);


Then my drawing goes like:

m_pD3DSprite->Begin(D3DXSPRITE_ALPHABLEND);

D3DXVECTOR3 center(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 position(50.0f, 50.0f, 0.0f);
g_pD3D->m_pD3DSprite->Draw(g_pRP->testSprite, NULL, ¢er, &position, D3DCOLOR_ARGB(255, 255, 255, 255));

m_pD3DSprite->End();



I could show full code if you need it, but this is all regarding the sprite drawing. First I thought that the sprite might be away from the camera, but that cant be the problem because sprites get drawn on the screen. So I have no idea what its not showing up...

Share this post


Link to post
Share on other sites
Advertisement
Make sure it's loaded the texture correctly as that could cause problems. It could also be a culling issue. Disable back face culling and see if that fixes it.

Share this post


Link to post
Share on other sites
You're not checking the return value for any of those function calls, which means they could be failing. You can use the FAILED macro for that, and then use the error-handling library to get the actual error. You can also enable the debug runtimes for additional information.

Also, if you want to post source code here you can use the "code" or "source" tags. See the FAQ.

Share this post


Link to post
Share on other sites
@Dom_152 My backface culling is disabled:
m_pD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

@MJP I just used DXGetErrorDescription on all my Sprite relavent functions.
All said the same thing, the function was succesfull or something like that.

Edit:
Could one of my renderstates be the problem?



// Chris; Setup the device states
m_pD3DDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
m_pD3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

// Chris; Ambient Color and Lighting
m_pD3DDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
m_pD3DDevice->SetRenderState( D3DRS_AMBIENT, D3DCOLOR_XRGB( 100, 100, 100 ) );

ZeroMemory( &light, sizeof( light ) );
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse = D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f );
light.Direction = D3DXVECTOR3( -1.0f, -0.5f, -1.0f );

m_pD3DDevice->SetLight(0, &light);
m_pD3DDevice->LightEnable(0, TRUE);

//Chris; Anti Aliasing
m_pD3DDevice->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, TRUE );

//Chris; Texture sampling
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_MAXANISOTROPY, 8 );
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC );
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
m_pD3DDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );

// Chris; Useing AlphaTest for alpha, AlphaBlend wont work properly for some reson
m_pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
m_pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );
m_pD3DDevice->SetRenderState( D3DRS_ALPHAREF, (DWORD)1 );

Share this post


Link to post
Share on other sites
Ok I take that back, it is rendering, but its huge, and not in place, and its almost as if it was in 3D space and the coords apply to that and not to my monitor. I thought 2D sprites are suppose to be on screen coords. If I move my camera back I can see it. Its also effected by FOV and stuff like that o.O.

So basicly if I remove my camera, it works fine... but that cant be it >.<. Im trying to make an interface...

Could it be that I have to render the camera after the interface code?

[Edited by - Tingle on July 12, 2010 1:24:37 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Tingle
Ok I take that back, it is rendering, but its huge, and not in place, and its almost as if it was in 3D space and the coords apply to that and not to my monitor. I thought 2D sprites are suppose to be on screen coords. If I move my camera back I can see it. Its also effected by FOV and stuff like that o.O.

So basicly if I remove my camera, it works fine... but that cant be it >.<. Im trying to make an interface...

Could it be that I have to render the camera after the interface code?
Calling ID3DXSprite::Begin() will set up the device state for sprite rendering, so you shouldn't be changing any render states or transforms between the Begin() and End() call, unless you especially want to change the default rendering behaviour.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!