Advertisement Jump to content
Sign in to follow this  

DX9 Sprite Scaling/Display Question

This topic is 4922 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, I have searched the forums and did not find a question similar to my own, so please forgive me if this question has already been asked and I missed the thread. I am trying to write a simple game in managed Direct X 9 using C#. Specifically, I am attempting to place a background image in my windowed form. The size of my form is 800 x 600 as is the size of the image that I am attempting to make my background. My problem is that when the application runs, a sizeable black border appears around the top and left sides of the image resulting in the image appearing off center within window. I think this problem may have something to do with the image size not being a power of two. My understanding of the Direct X API is still limited so I am unsure if this sizing issue is what is causing the problem to occur. My solution was to attempt to scale the image size to the exact width and height of the windowed form (as shown in my code below). Unfortunately, this solution did not work. Any suggestions, and, or, pointers in the right direction, would be greatly appreciated. Thanks, Chris /* Initialize Function */ ... // Create background texture backgroundTexture = TextureLoader.FromFile(device, @"..\..\back.png"); using (Surface s = backgroundTexture.GetSurfaceLevel(0)) { SurfaceDescription desc = s.Description; backgroundTextureSize = new Rectangle(0, 0, desc.Width, desc.Height); } backgroundSprite = new Sprite(device); /*OnPaint Override*/ ... // Draw background backgroundSprite.Begin(SpriteFlags.None); Matrix bSpriteMatrix; bSpriteMatrix = Matrix.Transformation( new Vector3((float)400, (float)300, (float)0), Quaternion.Identity, new Vector3( (float)this.Width/backgroundTextureSize.Width, // Scale (float)this.Height/backgroundTextureSize.Height, // Scale (float)1 ), Vector3.Empty, Quaternion.Identity, Vector3.Empty); backgroundSprite.Transform = bSpriteMatrix; backgroundSprite.Draw( backgroundTexture, backgroundTextureSize, new Vector3(0,0,0), new Vector3(0,0,1), Color.White ); backgroundSprite.End();

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!