Sign in to follow this  
Mrs Kensington

Managed DirectX Sprite and Font scaling

Recommended Posts

I'm using the February 2005 DirectX SDK and trying to use the Direct3D Sprite object to draw sprites and text. The actual drawing is fine i can happily draw a sprite on top of text and text on top of that and a sprite on top of that... The problem comes when I try to draw a sprite scaled... as in the destination rectangle is not the same height and width and the source rectangle. The texture is scaled exactly how i wanted however any text is also scaled by the same amount, for example if I draw a 512x512 texture with a width and height of 256 the text is half the size that it should be. this is my sprite and font rendering code...
public override void RenderSprite(Texture texture, Rectangle sourceRectangle, int x, int y, int width, int height)
{
	Rectangle destinationRectangle = new Rectangle(x, y, width, height);
	Point position = new Point(x, y);

	sprite.Draw2D(texture, sourceRectangle, destinationRectangle, position, Color.White);
}


public override void DrawText(string text, int x, int y, Color color)
{
	Rectangle rect = Rectangle.Empty;
			
	rect.X = x;
	rect.Y = y;
			
	font.DrawText(sprite, text, rect, DrawTextFormat.NoClip, color);
}


I've tried modifying the sprites Transform property but that doesn't seem to do anything. Anyone have any ideas?? Thanks for your help!

Share this post


Link to post
Share on other sites
There are a bunch of options here, but it sounds like you are dealing with a sort of bug where the scale of Draw2D applies to following draw calls.

1. Try using a different sprite object for your text and for your sprites.
2. Use the Draw method instead of Draw2D and the Transform property to do the scaling, setting it back to the the identity before drawing your text.
3. DrawText does not require a sprite, if your text is always in screen space just pass null as the first argument.

hope this helps.

Share this post


Link to post
Share on other sites
Thanx for the reply!

The problem with 1 and 3 is that as I'm using the sprites to create a GUI and theres a chance that I'll want to cover up some of the text with a sprite. While you can do it with option 1 it involves a call to Flush before you draw the sprite that covers the text. This absolutely kills performance...

I've given option 2 a try and it seems to be working... I'm translating before I scale and so far it's done everything I need... This way I guess I could even alow things to be rotated though not sure how useful that would be... I'll give it some more testing but it looks like it should work this way...

It looks like it's a bug in Managed DirectX... I wonder if I should report it on the newsgroup and see if it can be fixed...

Again thanks for your help, It seems to have fixed it!

Mrs K

Share this post


Link to post
Share on other sites

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