1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
public void DrawChar(FontChar fcChar, float x, float y, Color color)
{
float u, v;
//Add Quad
u = (float)fcChar.TX / (float)_textureWidth;
v = (float)fcChar.TY / (float)_textureHeight;
Quad[BufferIndex] = new CustomVertex.TransformedColoredTextured(x, y, 0f, 1f, color.ToArgb(), u, v);
u = (float)(fcChar.TX + fcChar.TWitdh) / (float)_textureWidth;
v = (float)fcChar.TY / (float)_textureHeight;
Quad[BufferIndex + 1] = new CustomVertex.TransformedColoredTextured(x + fcChar.TWitdh, y, 0f, 1f, color.ToArgb(), u, v);
u = (float)fcChar.TX / (float)_textureWidth;
v = (float)(fcChar.TY + fcChar.THeight) / (float)_textureHeight;
Quad[BufferIndex + 2] = new CustomVertex.TransformedColoredTextured(x, y + fcChar.THeight, 0f, 1f, color.ToArgb(), u, v);
Quad[BufferIndex + 3] = Quad[BufferIndex + 1];
u = (float)(fcChar.TX + fcChar.TWitdh) / (float)_textureWidth;
v = (float)(fcChar.TY + fcChar.THeight) / (float)_textureHeight;
Quad[BufferIndex + 4] = new CustomVertex.TransformedColoredTextured(x + fcChar.TWitdh, y + fcChar.THeight, 0f, 1f, color.ToArgb(), u, v);
Quad[BufferIndex + 5] = Quad[BufferIndex + 2];
BufferIndex += 6;
}
public Point DrawString(string Text, int x, int y, Color color, int StartX)
{
Point carret = new Point(x, y);
//Prepare Shader
effect.SetValue("objectDiffuse", _texture);
effect.Begin(0);
effect.BeginPass(0);
//Pour chaque Char
for (int i = 0; i < Text.Length; i++)
{
if (Text[i] != '\n')
{
//Char Info
FontChar fcChar = _chars[Text[i]];
//DrawChar
DrawChar(fcChar, fcChar.XOffset + carret.X, fcChar.YOffset + carret.Y, color);
carret.X += fcChar.Advance;
}
}
//Update VB
vb.SetData(Quad, 0, LockFlags.None);
//Dessin
_device.SetStreamSource(0, vb, 0);
_device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
_device.DrawPrimitives(PrimitiveType.TriangleList, 0, Text.Length*2);
//End
effect.EndPass();
effect.End();
BufferIndex = 0;
return carret;
} |
Partager