Mesh.TextFromFont

Reidar Lange

Member
Joined
Oct 29, 2004
Messages
16
Does anyone know how to control the size of the resulting mesh when you use Mesh.TextFromFont().

Code:
System.Drawing.Font font = new System.Drawing.Font("Arial",1.0f,GraphicsUnit.Millimeter);
GlyphMetricsFloat [] glyph = new GlyphMetricsFloat[1];

Mesh m = Mesh.TextFromFont(device,font,"8",1f,0.1f,ref glyph);
Setting the font size does not change anything.

One solution would be to aply scaling to the world transform before rendering, but that has a tendency to do strange things with 3d lighting.
 
Found a solution!

The following code creates a 0-digit mesh and scales all vertixes down by 50%
Code:
Mesh m = Mesh.TextFromFont(device,font,"0",1f,0.1f,ref glyph);
int [] ranks = new int[1];
ranks[0] = m.NumberVertices;
System.Array arr = m.VertexBuffer.Lock(0,typeof(CustomVertex.PositionNormal),LockFlags.None,ranks);
for(int i=0;i<arr.Length;i++)
{
	Direct3D.CustomVertex.PositionNormal pn = (CustomVertex.PositionNormal)arr.GetValue(i);
	pn.X *= 0.5f;
	pn.Y *= 0.5f;
	pn.Z *= 0.5f;
	arr.SetValue(pn,i);			
}
m.VertexBuffer.Unlock();
 
Back
Top