public static MeshTextFromFont(
Device device, // デバイス
Font font, // テキストのフォント
string text, // 作成する文字列
float deviation, // テキストの輪郭の滑らかさ
float extrusion // テキストの奥行き
);
Mesh.TextFromFont(Device,Font,String,Single,Single) | MSDN
| deviationの値 | 1.0 | 0.001 |
|---|---|---|
| 表示イメージ | ![]() |
![]() |
| extrusionの値 | 0.1 | 0.2 |
|---|---|---|
| 表示イメージ | ![]() |
![]() |
テキストの位置などはDevice.Transform.Worldで、色はマテリアルで指定します。
public void DrawSubset(
int attributeID
);
BaseMesh.DrawSubset(Int32) | MSDN
3Dテキストの描画はストックオブジェクトの描画と同一です。
public Font(
Device device, // デバイス
Font font // テキストのフォント
);
Font.Font(Device,Font) | MSDN
public int DrawText(
Sprite sprite, // テキストを格納するスプライト
string text, // 描画する文字列
Point pos, // テキストの位置 (スクリーン座標)
Color color // テキストの色
);
Font.DrawText メソッド (Sprite, String, Point, Color) (Microsoft.WindowsMobile.DirectX.Direct3D) | MSDN
public int DrawText(
Sprite sprite, // テキストを格納するスプライト
string text, // 描画する文字列
Rectangle rect, // テキストを格納する長方形 (スクリーン座標)
DrawTextFormat format, // テキストのフォーマット
Color color // テキストの色
);
Font.DrawText メソッド (Sprite, String, Rectangle, DrawTextFormat, Color) (Microsoft.WindowsMobile.DirectX.Direct3D) | MSDN
Direct3D自体のスプライトを使用する場合には、spriteにはnullを指定します。関数が成功した場合には、テキストの高さが返されます。失敗した場合には、0が返されます。
2Dテキストはスクリーン座標で描画位置を指定する必要があります。よって3Dの座標系上に表示しているオブジェクトの位置に2Dのテキストを重ねるには、3Dの座標系からスクリーン座標を求める必要があります。これにはVector3構造体のProject()メソッドを使用します。(ちなみにXNAでは、このメソッドはViewport構造体のProject()メソッドに相当します)
public static Vector3 Project(
Vector3 v, // 3D座標系の位置
object viewport, // ビューポート変換行列
Matrix projection, // 射影変換行列
Matrix view, // ビュー変換行列
Matrix world // ワールド変換行列
);
Vector3.Project(Vector3,Object,Matrix,Matrix,Matrix) | MSDN
たとえば次のように使用します。
// スクリーン座標での位置を求める Vector3 textPosition = Vector3.Project( targetPosition, // 3Dオブジェクトの座標 device.Viewport, device.Transform.Projection, device.Transform.View, Matrix.Identity ); // 2Dテキストを描画する font.DrawText( null, "Text", ( int )textPosition.X, ( int )textPosition.Y, Color.White );