Jump to content
  • Advertisement
Sign in to follow this  
Rewasvat

Problem with SlimDX DX9 Sprite

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

I recently formatted my XP SP2, installing Windows 7 x64 in it's place. Since I was reinstalling everything, also got the new August SlimDX (I was using the one before it, from March). But now I'm having a problem when drawing a sprite (and I'm using DirectX 9 and C#), which didn't happened before. In some cases in my project I don't use the full source of the texture I'm drawing (for example when drawing a animated texture in which all frames are in the same texture file). And now after this OS/SlimDX version change, changing the source to something other than the full size isn't working somehow... Oh and this is just to draw simple, static 2D stuff, like an UI. For example, I have a texture, and want to draw a (rectangle) part of it in a rectangle in screen. So I appropriately calculate the source and destination rects to use (more than double-checked this to be sure), but then in-game, instead of applying that part of the texture (the source rect) to that part of the screen (the destination), it applies the full texture source in the coordinates of the destination, completely ignoring the source rect and the destination's width/heigth... However the other stuff in my project which are using the full texture source are draw appropriately, with the full texture being show appropriately inside the destination rect. This is drawing function, used in all cases. "SelectedSprite" is the sprite being used, which only changes for another one to draw text which is ok, and both sprites are used with the AlphaBlend flag. The Sprite's Begin and End methods being called before and after it like it should. "Textures" is a {name, Texture} dict, and "TextureSizes" is a {name, size of the texture} dice. Because of a few reasons, in the cases where I use the full texture source I pass in Rectangle.Empty as source, so that the Draw method gets by itself the appropriate full texture source rectangle.
        public static void Draw(string texName, Rectangle srcRect, Rectangle destRect, PointF rotationalCenter, float rotateAngle, Color color)
        {
            if (Textures.ContainsKey(texName))
            {
                if (srcRect == Rectangle.Empty)
                {
                    srcRect = new Rectangle(Point.Empty, TexturesSizes[texName]);
                }
                Vector3 pos = new Vector3((float)destRect.X, (float)destRect.Y, 0);
                Vector3 center = new Vector3(rotationalCenter.X, rotationalCenter.Y, 0);
                float scaleX = (float)destRect.Width / srcRect.Width;
                float scaleY = (float)destRect.Height / srcRect.Height;
                SelectedSprite.Transform = Matrix.RotationZ(rotateAngle) * Matrix.Scaling(scaleX, scaleY, 0) * Matrix.Translation(pos);
                SelectedSprite.Draw(Textures[texName], srcRect, center, Vector3.Zero, new Color4(color));
                SelectedSprite.Transform = Matrix.Identity;
            }
            else
            {
                LoadTexture(texName);
            }
        }

Share this post


Link to post
Share on other sites
Advertisement
Thanks Mike.

Still gotta decide if I rollback to the March SlimDX or if I build it myself tho...
I wanted to keep with the newer version, but since I'm not coding for DX11 and don't have DX11 hardware (only DX10), there's not much difference from the March build to August (for me at least, in my current needs).

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!