Sign in to follow this  

DX9 Sprite Scaling/Display Question

This topic is 4514 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 gamedev.net 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
I've ran into the same problem, using the Sprite class:

TheImage.Begin(SpriteFlags.None);
TheImage.Draw2D(TheTexture, Rectangle.Empty, new Rectangle(Left, Top, Width, Height), new Point((int)(Left / ((float)Width / (float)TextureX)), (int)(Top / ((float)Height / (float)TextureY))), Color.Transparent);
TheImage.End();

This code position exactly the picture at position Left,Top, using a Width and Height. Don't forget that if your window size is 800*600, the available area for DirectX is a bit smaller: something like 760*594... (it depends on the interface used)

Share this post


Link to post
Share on other sites

This topic is 4514 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this