Sign in to follow this  

Sprite Issues

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

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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();



Share this post


Link to post
Share on other sites

This topic is 2837 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this