RECT with decimals?

Started by
2 comments, last by Kest 15 years, 4 months ago
I was trying to animate a sprite but realized that a RECT takes only LONG values not decimal ones, I need decimal values for the sprite frames to display properly but since the sprite->Draw function needs a RECT I don't know what to do. Does anyone knows a way to fix/around this? Here's the code just in case.

void render()
{
    d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    d3dDevice->BeginScene(); 

    d3dSprite->Begin(NULL);  

	D3DXVECTOR2 pos = D3DXVECTOR2(128,128);
	D3DXVECTOR2 scale(2.0f,2.0f);
	D3DXMATRIX mat;

	D3DXMatrixTransformation2D(&mat, NULL, 0.0, &scale, NULL, 0, &pos);
	rct.left = 39*chrono.frame;
	rct.right = rct.left+39;
	rct.top = 39 *chrono.row;
	rct.bottom = rct.top+39;

	d3dSprite->SetTransform(&mat);

    d3dSprite->Draw(sprite, &rct, NULL, NULL, 0xFFFFFFFF);

    d3dSprite->End(); 

    d3dDevice->EndScene(); 

    d3dDevice->Present(NULL, NULL, NULL, NULL);

    return;
}

Thanks
Advertisement
I think you'd have to stop using the ID3DXSprite and draw your sprite yourself using a vertex buffer containing two triangles. Then you'd be free to specify whatever texture coordinates as (0-1) range floats you wanted.

I'm not sure if it is the same issue as you have (or even if it has been fixed in ID3DXSprite since the article was written) but there's an article here on GameDev that discusses some of the texturing issues using the sprite interface.
I am not sure why you would need decimals in the rect?

The rect tells the sprite what texel portion to draw from the texture.
Quote:Original post by Crazyfool
I am not sure why you would need decimals in the rect?

The rect tells the sprite what texel portion to draw from the texture.

In typical situations, that's true. But it is possible to set texture coordinates in-between pixels, and it's useful in some situations. For example, you could animate a scrolling waterfall more smoothly if the drawing source coordinates can smoothly transition between pixels.

I'm not sure about the OP's case, though.

This topic is closed to new replies.

Advertisement