Sign in to follow this  
BoxyCraft

[SlimDX] Sprite projection matrix for drawing font [SOLVED]

Recommended Posts

BoxyCraft    127
Hi I am rendering to a backbuffer that is different in size to the screen, and I use a projection matrix to keep the perspective. When I try drawing fonts with a sprite though, it just doesn't work, and they appear all bunched up. I apply a world matrix to the sprite before rendering the font, and i tried multiplying the projection matrix into there but it didnt work. Can someone please help me out? [Edited by - BoxyCraft on May 20, 2010 11:22:00 PM]

Share this post


Link to post
Share on other sites
BoxyCraft    127
This is basically the draw function, in Visual Basic. This works fine if the rendertarget and screen are the same size.


Public Sub Draw(ByRef p As Vector2D, ByVal scale As Single)

'Begin
_sprite.Begin(SpriteFlags.AlphaBlend)

'get top-left position
Dim pos As Vector2D
pos.X = p.X - (_width * 0.5F * scale)
pos.Y = p.Y - (_height * 0.5F * scale)

'Transform
_sprite.Transform = Matrix.Identity * Matrix.Scaling(scale, scale, 1) * Matrix.Translation(pos.X, pos.Y, 0)

'Draw text
rect.X = _spacing
rect.Y = _spacing
rect.Width = _width - _spacing - _spacing
_smallfont.MeasureString(_sprite, _text, DrawTextFormat.Left, rect)
_smallfont.DrawString(_sprite, _text, rect, DrawTextFormat.Left, _textcolor.ToArgb)

'End
_sprite.Flush()
_sprite.End()

End Sub


Share this post


Link to post
Share on other sites
BoxyCraft    127
Solved. I was changing the state before the Sprite.Flush! [depressed]

I even cut that part out before posting my code, because I didn't think it was important!

Anyway, solved, and no problem!
[imwithstupid]

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