Sprite Issues

Started by
7 comments, last by justin12343 14 years, 1 month ago
I'm loading an animation strip that is 9344 x 64 with each frame being 64 x 64. It looks distorted when I draw a single frame (2 frames kinda squished together), but when I load and draw a 64 x 64 image using the same code, it looks perfectly fine. Does DirectX 9 support images of those dimensions or am I doing something wrong?

	//D3DXIMAGE_INFO d3dxImageInfo;
	
	D3DXCreateTextureFromFile(g_pd3dDevice9, fname,&sprite_texture[num_sprites]);
	
	//sprite_texture_width[num_sprites]= d3dxImageInfo.Width;
	//sprite_texture_height[num_sprites]= d3dxImageInfo.Height;
	
	g_pd3dDevice9->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	g_pd3dDevice9->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	
	sprite_width[num_sprites]=width;
	sprite_height[num_sprites]=height;
	
	sprite_frames[num_sprites]=frames;

	sprite_originx[num_sprites]=originx;
	sprite_originy[num_sprites]=originy;

	D3DXCreateSprite( g_pd3dDevice9, &sprite_index[num_sprites]);

	return num_sprites;
	num_sprites+=1;



[source lang ="cpp"]
	RECT srcRect;
    srcRect.top    = 0;
    srcRect.left   = 0;
	srcRect.bottom = 64;
    srcRect.right  = 64;
	
	//D3DXVECTOR3 vCenter( sprite_originx[index], sprite_originy[index], 0.0f );
	D3DXVECTOR3 vCenter( 0.0f, 0.0f, 0.0f );
	D3DXVECTOR3 vPosition( 0.0f, 0.0f, 0.0f );

	sprite_index[index]->Begin( D3DXSPRITE_ALPHABLEND );
	sprite_index[index]->Draw( sprite_texture[index],
                          &srcRect,
                          &vCenter,
                          &vPosition,
                          D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );

	sprite_index[index]->End();



[Edited by - justin12343 on March 11, 2010 7:31:57 PM]
Advertisement
D3DXCreateTextureFromFile will scale the image to power-of-2 dimensions. In your case, it's probably also scaling it down to 4096x64, since 4096x4096 is the max texture dimensions for most DX10-level GPU's (some newer GPU's can do 8192x8192). You'll definitely need to use a smaller texture, and if you don't want it scaled to power-of-2 dimensions you'll need to use D3DXCreateTextureFromFileEx.
Will it work if I change it from a strip to a tileset with rows?
thats the usual aproach
I edited it so that it could load the tileset, but it draws on only a piece of the first frame.

Heres the edited parts:

	D3DXIMAGE_INFO d3dxImageInfo;		D3DXCreateTextureFromFileEx(g_pd3dDevice9, 							  fname,							  D3DPOOL_DEFAULT,							  D3DPOOL_DEFAULT,							  1,							  D3DPOOL_DEFAULT,							  D3DFMT_UNKNOWN,							  D3DPOOL_DEFAULT,							  D3DX_DEFAULT,							  D3DX_DEFAULT,							  D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),							  &d3dxImageInfo,							  NULL,							  &sprite_texture[num_sprites]);


	RECT srcRect;    //srcRect.top    = (frame / sprite_cells[index]) * sprite_height[index];    //srcRect.left   = (frame % sprite_cells[index]) * sprite_height[index];	//srcRect.bottom = srcRect.top+sprite_height[index];    //srcRect.right  = srcRect.left+sprite_width[index];	    srcRect.top    = 0;    srcRect.left   = 0;	srcRect.bottom = 64;    srcRect.right  = 64;	D3DXVECTOR3 vCenter( sprite_originx[index], sprite_originy[index], 0.0f );	//D3DXVECTOR3 vCenter( 0.0f, 0.0f, 0.0f );	D3DXVECTOR3 vPosition( x, y, 0.0f );	sprite_index[index]->Begin( D3DXSPRITE_ALPHABLEND );	sprite_index[index]->Draw( sprite_texture[index],                          &srcRect,                          &vCenter,                          &vPosition,                          D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );	sprite_index[index]->End();
Did you read the documentation for D3DXCreateTextureFromFileEx?
I did
Then you know that you just told D3D to resize the image to the next power of two, right?
obviously not, where did I make a mistake?

EDIT:

I found my mistake. I didn't set the width and height.

[Edited by - justin12343 on March 12, 2010 11:16:16 PM]

This topic is closed to new replies.

Advertisement