Stretch texture

Based on the following code that uses a Sprite and Texture to draw a textured square...

_sprite.Begin( D3D.SpriteFlags.AlphaBlend );
_sprite.Draw( _texture,
new Rectangle( 0, 0, (int)_width, (int)_height ),
new Vector3( 0.0f, 0.0f, 0.0f ),
new Vector3( (int)_left, (int)_top, 0.0f ),
Color.FromArgb( 255, 255, 255, 255 ) );
_sprite.End();

...I am confused as to what part of this code I can change to stretch my texture horizontally or vertically.

According to intellisense, the call parameters break down as follows: the texture (obviously), the area of the texture that you want to draw, the center of the texture, the position to draw at, and the color to use.

Which of these parameters could I adjust to make my texture stretch




Answer this question

Stretch texture

  • SMGK

    D3DX has matrix structures/functions that will help you with that. Example:


    D3DXMATRIX matrix;
    D3DXVECTOR2 scaleVec(2.0f, 1.0f);
    D3DXVECTOR2 translationVec(10.0f, 10.0f);
    // get the transform matrix for a scaling in the X coordinate and a translation of (10,10).. no rotation applied
    D3DXMatrixTransformation2D(&matrix, 0, 0, &scaleVec, 0, 0, &translationVec);
    sprite->SetTransform(&matrix);


  • Mark S. Milley, MCSD

    Hi,
    you can't stretch the texture in that call. You can stretch(scale) / transform the sprite calling the SetTransform function.


  • JamesBeyak

    Thanks for the reply; I will try this later today...

  • Uleepera

    My bad, for some reason, that I can't explain, I posted the code in c++. Sorry about that.


  • Seradex

    Okay, I've played around with it a bit... it looks like I'm supposed to pass in a matrix, but what am I supposed to do to the matrix so that the sprite knows it should stretch itself

    I'm guessing there's a handy set of functions you can apply to a matrix somewhere...



  • Eddy Escardo-Raffo - MSFT

    Okay, that's basically it; thanks!

    For C# purposes, I found that the calls look a little different, like this:

    Matrix matrix = new Matrix();
    Vector2 stretchVec = new Vector2(1.0f, 2.0f);
    matrix.Scale(1.0f, 2.0f, 1.0f);
    _sprite.Transform = matrix;



  • Stretch texture