D3DX Sprites appear bigger

Started by
14 comments, last by Odoacer 19 years, 8 months ago
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);

Advertisement
Where is your camera positioned?
"Learn as though you would never be able to master it,
hold it as though you would be in fear of losing it" - Confucius
I don't believe I've set up any cameras yet. I'm just drawing to the screen and leaving it at that.
Stupid question, but is it due to the fact you have your application in a lower resolution than your OS?
Stupid question, as in, obvious? Either way, I think its a good question and probably your answer.
"Learn as though you would never be able to master it,
hold it as though you would be in fear of losing it" - Confucius
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.
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.
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Are the dimentions of the image powers of 2?
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.

This topic is closed to new replies.

Advertisement