Rotated text drawing
rytisss opened this issue · comments
Is it possible to draw text in specific angle with a functional of SharpDX, or should i draw it on separate image, rotate it and add (or something like this)?
Why are you asking about this here? This forum is mainly for discussing bugs and problems inside of SharpDX. But I'll answer your question anyway. Yes, you can.
For example, in DirectX 9 use SharpDX.Direct3D9.Sprite and its properties. With matrix transformation you can translate, scale, ROTATE, shear and so on with your text.
You can find the sources by googling them.
You can set the Transform property on a RenderTarget prior to rendering some text.
You may need the SharpDX.Mathematics library to access the Matrix3x2 helper class.
_renderTarget2D.BeginDraw();
// multiply the current transform matrix with a rotation matrix...
_renderTarget2D.Transform = Matrix3x2.Multiply(Matrix3x2.Rotation(angle), _renderTarget2D.Transform);
// Now draw the actual text...
using (var textFormat = new TextFormat(
_factoryDWrite,
fontFamily,
FontWeight.Normal,
FontStyle.Normal,
FontStretch.Normal,
fontSize))
{
using (var textLayout = new TextLayout(_factoryDWrite, text, textFormat, maxWidth, maxHeight))
{
_renderTarget2D.DrawTextLayout(new RawVector2(x, y), textLayout, _textBrush);
}
}
_renderTarget2D.EndDraw();