How to set sprite source coordinates?
- by ChaosDev
I am creating own sprite drawer with DX11 on C++. Works fine but I dont know how to apply source rectangle to texture coordinates of rendering surface(for animation sprite sheets)
//source = (0,0,32,64); //RECT
D3DXVECTOR2 t0 = D3DXVECTOR2( 1.0f, 0.0f);
D3DXVECTOR2 t1 = D3DXVECTOR2( 1.0f, 1.0f);
D3DXVECTOR2 t2 = D3DXVECTOR2( 0.0f, 1.0f);
D3DXVECTOR2 t3 = D3DXVECTOR2( 0.0f, 1.0f);
D3DXVECTOR2 t4 = D3DXVECTOR2( 0.0f, 0.0f);
D3DXVECTOR2 t5 = D3DXVECTOR2( 1.0f, 0.0f);
VertexPositionColorTexture vertices[] =
{
{ D3DXVECTOR3( dest.left+dest.right, dest.top, z),D3DXVECTOR4(1,1,1,1), t0},
{ D3DXVECTOR3( dest.left+dest.right, dest.top+dest.bottom, z),D3DXVECTOR4(1,1,1,1), t1},
{ D3DXVECTOR3( dest.left, dest.top+dest.bottom, z),D3DXVECTOR4(1,1,1,1), t2},
{ D3DXVECTOR3( dest.left, dest.top+dest.bottom, z),D3DXVECTOR4(1,1,1,1), t3},
{ D3DXVECTOR3( dest.left , dest.top, z),D3DXVECTOR4(1,1,1,1), t4},
{ D3DXVECTOR3( dest.left+dest.right, dest.top, z),D3DXVECTOR4(1,1,1,1), t5},
};