Archived

This topic is now archived and is closed to further replies.

Seriema

D3DX Sprite: distorted size? why??

Recommended Posts

Seriema    634
I finally got a simple animated character walking around. BUT... It''s distorted The whole image is 256x256, actually it''s two 128x256 slapped together. I have a RECT of each side, to make the animation. The problem is that the image that is shown on screen is 106*193 (it should be 128x256??). Why does it do that?! Here''s the constructor, so you can see the values of my variables:
    
CSimpleSprite::CSimpleSprite()
{
	m_pSprite = 0;
	m_pTexture = 0;
	m_bInitialized = false;
	m_RotCenter.x = 2.0f;
	m_RotCenter.y = 1.0f;
	m_Translation.x = 0.0f;
	m_Translation.y = 0.0f;
	m_Scaling.x = 1.0f;
	m_Scaling.y = 1.0f;
	m_ModulateColor = D3DCOLOR_ARGB(255, 255,255, 255);  //MED alpha-värde, kan använda D3DCOLOR_XRGB() för att default köra alpha=255

	m_Rotation = 0.0f;
	m_TransparentColor = D3DCOLOR_ARGB(0, 0, 255, 0);

	wFrame = 0;
	wFrameMax = 0;
}
  


Here''s my init code. The D3DXCreateTextureFromFileExA is the most important part I think?
        
HRESULT CSimpleSprite::Initialize(char *path, RECT sprite_rect, short frames_right, short frames_down)
{
	HRESULT hr = 0;
	D3DSURFACE_DESC desc;
	RECT rect;
	rect.bottom = sprite_rect.bottom;//{0,0, 0,0};

	rect.left = sprite_rect.left;
	rect.right = sprite_rect.right;
	rect.top = sprite_rect.top;

	hr = D3DXCreateTextureFromFileExA(g_pDevice, 	// LPDIRECT3DDEVICE8 pDevice	

									path,	// LPCSTR pSrcFile	

									256,	// UINT Width	

									256,//D3DX_DEFAULT,	// UINT Height	

									D3DX_DEFAULT,	// UINT MipLevels	

									0,//D3DUSAGE_RENDERTARGET,	// DWORD Usage	

									D3DFMT_UNKNOWN,	// D3DFORMAT Format	

									D3DPOOL_MANAGED,	// D3DPOOL Pool	  -- D3DPOOL_DEFAULT

									D3DX_DEFAULT,	// DWORD Filter	

									D3DX_DEFAULT,	// DWORD MipFilter	

									m_TransparentColor,	// D3DCOLOR ColorKey  - transparent färg!	

									NULL,			// D3DXIMAGE_INFO* pSrcInfo	

									NULL,			// PALETTEENTRY* pPalette	

									&m_pTexture);	// LPDIRECT3DTEXTURE8* ppTexture


	D3DXCreateSprite(g_pDevice, &m_pSprite);

	m_pTexture->GetLevelDesc(0, &desc);
  
	if(sprite_rect.bottom == 0)
	{
		sprite_rect.bottom = desc.Height;
		sprite_rect.right = desc.Width;
		vecSpriteRec.push_back( sprite_rect/*{0,0, (LONG)desc.Width, (LONG)desc.Height}*/ );
	}
	else
	{
		if(desc.Height % sprite_rect.bottom != 0)
			return E_INVALIDARG;

		for(int y=0; y < frames_down; y++)
		{
			for(int x=0; x < frames_right; x++)
			{
				vecSpriteRec.push_back(rect);

				rect.left = rect.right ;
				rect.right += sprite_rect.right ;
			}

			rect.top = rect.bottom ;
			rect.bottom += sprite_rect.bottom ;
		}
	}

	wFrameMax = (short)vecSpriteRec.size();   // skulle kunna vara en POINT, om bilden e en matris. Tänk mer på d här...


	m_bInitialized = TRUE;

	return S_OK;
}
  


Here''s my Render function.
      
HRESULT CSimpleSprite::Render()
{
	if(!m_bInitialized)
		return E_FAIL;

	HRESULT hr = 0;

	m_pSprite->Begin();

	hr = m_pSprite->Draw(m_pTexture,
						&vecSpriteRec[wFrame],
						&m_Scaling,
						&m_RotCenter,
						m_Rotation,
						&m_Translation,
						m_ModulateColor);

	m_pSprite->End();
	
	return S_OK;
}
      
}+TITANIUM+{

Share this post


Link to post
Share on other sites
Coudrak    122
I don''t know if it can help but try with these parameters :

hr = m_pSprite->Draw(m_pTexture, NULL, NULL, NULL, 0, // Size by default
&m_Translation, m_ModulateColor);

Share this post


Link to post
Share on other sites
Seriema    634
Thanx, but I''ve already tried that before. Nothing helps!

I was thinking, could this be the problem:
I''ve runned the program in windowed mode, took a print screen and checked the size of the image in Photoshop. The windowed mode of my program is 800x600 and I run my monitor on 1280x1024.
But, a pixel is a pixel right?..

}+TITANIUM+{

Share this post


Link to post
Share on other sites
Anarchi    122
If the source bitmap (the file) is not compatible with the requirements of your 3D card, then D3DX will resize the texture to fit.

Most cards require their textures to be of the power of 2 (2,4,8,16,32,64,128,256 etc..), so if you load a texture with a size of say 500x500, D3DX will resize the texture to fill the whole 512x512 texture in the video card. This is also the case with files being larger than the 3D card can handle, for instance the Voodoo3 can only handle 256x256 and lower textures, anything bigger, it will be shrinked down to 25x256 (or cut off I think).

Sometimes another requirement is that the texture must be square, i.e. 256x256, 64x64, and not 256x64.

Your safest bet is to make all your bitmaps square and of power of 2.

All my textures in my game are either 64x64, 256x256, or 512x512, and ive had no problems at all.

I have a small utility that displays the basic caps of your 3D Card, ill send it to u, whats your email address?

U can also grab the code from my D3DXSprite wrapper which can be downloaded at:

Downloads, D3DXSprite tutorial, New platform game: .-= The ZeroOne Realm =-.

Share this post


Link to post
Share on other sites
Mark Duffill    156
If you are running in a window and that Window is smaller than the direct x surface (back buffer) you created. On Present it will do a stretch blit so it will fit. ( ie shrink it ).

This is if the target rect is null in the Present function. (see the sdk help on Present )

Share this post


Link to post
Share on other sites
grasshopa55    128
Also, another item is the Filter value when you load up the texture. Using D3DX_DEFAULT apply other filters to stretch and filter your image. If you use D3DX_FILTER_NONE, no filters are applied. Try that.

-----------------------------
kevin@mayday-anime.com
http://games.mayday-anime.com

Share this post


Link to post
Share on other sites
Seriema    634
Thanx for all your posts!

Mark Duffill: My back buffer and window are created with the same constants, so it''s the same size. Doesn''t help =(

grasshopa55: Tried that, didn''t work =((


I''m curious, this whole thing could be just lack of understanding DX! My windw is created in 800x600, and my desktop runs at 1280x1024. Could this be why it looks "shrunk"? Because the little window runs at it''s own resolution?..

}+TITANIUM+{

Share this post


Link to post
Share on other sites
Mark Duffill    156
quote:

Mark Duffill: My back buffer and window are created with the same constants, so it''s the same size. Doesn''t help =(



Hmm, odd,
Perhaps if your window has borders don''t forget to add this into your window sizes, ie 640+borderwidths, 480+border heights. I think you''ll have to use GetSystemMetrics(..) function to find out what these are at runtime.

This is annoying and it caught me out to!

ps: you could do a printscreen and look at the image in a paint program and measure the real pixel dimensions of your visible dx surface. (ie make sure its 640x480, if so problem is else where!)

Have you tried hard coding the width height values of your sprite in the draw code? This might help you find out if its Directx oddness, or somewhere in you code is modifying something it shouldn''t

[The views stated herein do not necessarily represent the view of the company Eurocom ]

Eurocom Entertainment Software
www.Eurocom.co.uk

The Jackal

Share this post


Link to post
Share on other sites
PhanThomas    122
quote:
Original post by Mark Duffill
Perhaps if your window has borders don''t forget to add this into your window sizes, ie 640+borderwidths, 480+border heights. I think you''ll have to use GetSystemMetrics(..) function to find out what these are at runtime.



There''s a function called AdjustWindowRect() to make the client area of the window the requested size. You just pass it the window styles and it will resize the window appropriate.

Share this post


Link to post
Share on other sites
Jim Adams    440
When loading the texture, don''t specify a width and height, use D3DX_DEFAULT instead. Also, try manually specifying the source rect coordinates during the draw and see if that helps.

Jim Adams

Share this post


Link to post
Share on other sites