Jump to content
  • Advertisement
Sign in to follow this  

Problems with Sprite.Draw

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

Hello everybody!


I have encountered a new obstacle when porting from XNA to DirectX 9. I have replaced SpriteBatch with Sprite and I'm using the Draw method (http://sharpdx.org/documentation/api/m-sharpdx-direct3d9-sprite-draw-1).


The problem is that I need to align a source rectangle from a texture to a destination rectangle in the current render target. If the source and destination rectangle have different dimensions, the texture should get stretched.


But I was not able to make the Transform property behave correctly. If scaling is involved, I can't get the right translation. Does anybody know how to use the Sprite class to precisely position and stretch a source texture to a destination rectangle? Something that behaves like StrechDraw I think.


Thank you!

Share this post

Link to post
Share on other sites

I have found a solution of some-sort, bypassing the Sprite class entirely, something like:

float px = 2.0f / Enjin.Width;
float py = 2.0f / Enjin.Height;
AdjustFSQuad(fsQuad, 100 * px, 100 * py, 200 * px, 200 * py, 0.5f / Enjin.Width, 0.5f / Enjin.Height);

I am drawing a fullscreen quad, but I am substracting the left, top, right and bottom values multiplied by the pixel size. These are the parameters 2 though 5. 6 and 7 are the half pixel offset because I am sampling the texture in the shader under DirectX 9. I'm not 100% sure that this is needed here.


Now I need to update this method to allow me to render only a source rectangle from the texture...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!