How to set sprite source coordinates?

Posted by ChaosDev on Game Development See other posts from Game Development or by ChaosDev
Published on 2012-04-30T09:02:21Z Indexed on 2012/05/30 17:01 UTC
Read the original article Hit count: 238

Filed under:
|

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},
    }; 

© Game Development or respective owner

Related posts about directx11

Related posts about spritesheet