Jump to content
  • Advertisement
Sign in to follow this  
Odoacer

D3DX Sprites appear bigger

This topic is 5065 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

Sorry if this question is dumb, but whenever I try to render a sprite using D3DX, it appears bigger onscreen (roughly one and a half the size it should be). Is there a reason for this? Or am I perhaps initializing something incorrectly in my code?
	if(FAILED(D3DXCreateTextureFromFile(g_pd3dDevice, "images/snakeHeaddown.png", &g_pTexture)))
		return false;
	if(FAILED(D3DXCreateSprite(g_pd3dDevice, &g_pSprite)))
		return false;
/**/
	g_pSprite->Begin(NULL);
	D3DXVECTOR3 foo(16, 16, 1);

	if(D3DXERR_INVALIDDATA == (g_pSprite->Draw(g_pTexture, NULL, NULL, &foo, 0xFFFFFFFF )))
		msgboxnumber(100);

Share this post


Link to post
Share on other sites
Advertisement
I don't believe I've set up any cameras yet. I'm just drawing to the screen and leaving it at that.

Share this post


Link to post
Share on other sites
Stupid question, but is it due to the fact you have your application in a lower resolution than your OS?

Share this post


Link to post
Share on other sites
you need to disable texture filtering using D3DXCreateTextureFromFileEx

D3DXCreateTextureFromFileEx(device, texture.c_str(), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, NULL, NULL, &m_texture);

D3DX_FILTER_NONE
No scaling or filtering will take place. Pixels outside the bounds of the source image are assumed to be transparent black.

Share this post


Link to post
Share on other sites
Quote:
Original post by eFoDay
you need to disable texture filtering using D3DXCreateTextureFromFileEx

D3DXCreateTextureFromFileEx(device, texture.c_str(), D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_FILTER_NONE, 0, NULL, NULL, &m_texture);

D3DX_FILTER_NONE
No scaling or filtering will take place. Pixels outside the bounds of the source image are assumed to be transparent black.


That worked... the image is not being resized, but now there is a black border (transparent, eh?) on the left and bottom sides of the picture, so it is still pretty much the same size as it was before.

I'm one step closer, but not quite there yet. Why is D3D trying to render pixels outside the bounds of the source image? I'm not specifying any sizes.

Quote:
Stupid question, but is it due to the fact you have your application in a lower resolution than your OS?
No, I'm running in windowed mode, not fullscreen.

Share this post


Link to post
Share on other sites
Is your images size not powers of 2? A lot of cards still need textures with sizes being powers of 2.

The D3DXCreateTextureFromFile will acquire a bigger texture and put your image inside with borders.

You can use D3DXCreateTextureFromFileEx and specify D3DX_DEFAULT_NONPOW2 for width and height. This will only work on a card that supports textures of non power of 2 sizes.

Share this post


Link to post
Share on other sites
I was making a HUD system using the sprite tutorial from nexe and was just about to post the same problem when I saw this post. I am also getting a border around the sprite - though my sprite dimensions are powers of 2.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!