コード例 #1
0
ファイル: Text3D.cs プロジェクト: hccampos/XtremeEngineXNA
        /// <summary>
        /// Generates the text mesh by extruding the vector font for each character of the current
        /// text.
        /// </summary>
        private void GenerateTextMesh()
        {
            //Create the text mesh using the font and the current text.
            Nuclex.Fonts.Text mesh = mFont.Extrude(mText);

            mWidth = mesh.Width;

            //Align the text.
            for (int i = 0; i < mesh.Vertices.Length; ++i)
            {
                Matrix alignTransform = Matrix.Identity;
                if (mTextAlign == TEXT_ALIGN.ALIGN_CENTER)
                {
                    alignTransform = Matrix.CreateTranslation(new Vector3(-this.mWidth / 2, 0, 0));
                }
                else if (mTextAlign == TEXT_ALIGN.ALIGH_RIGHT)
                {
                    alignTransform = Matrix.CreateTranslation(new Vector3(-this.Width, 0, 0));
                }

                mesh.Vertices[i].Position = Vector3.Transform(mesh.Vertices[i].Position, alignTransform);
            }

            int vertexCount = mesh.Vertices.Length;
            int indexCount  = mesh.Indices.Length;

            if (vertexCount == 0 || indexCount == 0)
            {
                this.VertexBuffer   = null;
                this.IndexBuffer    = null;
                this.PrimitiveCount = 0;
                return;
            }

            //Create the vertex buffer.
            VertexBuffer vb = new VertexBuffer(Root.GraphicsDevice,
                                               typeof(VertexPositionNormalTexture), vertexCount, BufferUsage.None);

            vb.SetData <VertexPositionNormalTexture>(mesh.Vertices);

            //Create the index buffer.
            IndexBuffer ib = new IndexBuffer(Root.GraphicsDevice, IndexElementSize.SixteenBits,
                                             indexCount, BufferUsage.None);

            ib.SetData <short>(mesh.Indices);

            this.VertexBuffer   = vb;
            this.IndexBuffer    = ib;
            this.PrimitiveType  = mesh.PrimitiveType;
            this.PrimitiveCount = VertexHelper.GetPrimitiveCount(indexCount, this.PrimitiveType);
        }
コード例 #2
0
ファイル: TextBatch.cs プロジェクト: pr0gramm3r1/AngryTanks
 /// <summary>Draws a line of text to the screen</summary>
 /// <param name="text">Pregenerated text mesh to draw to the screen</param>
 /// <param name="effect">Custom effect with which to draw the text</param>
 public void DrawText(Text text, Effect effect) {
   this.primitiveBatch.Draw(
     text.Vertices, text.Indices, text.PrimitiveType,
     new EffectDrawContext(effect)
   );
 }
コード例 #3
0
ファイル: TextBatch.cs プロジェクト: pr0gramm3r1/AngryTanks
 /// <summary>Draws a line of text to the screen</summary>
 /// <param name="text">Pregenerated text mesh to draw to the screen</param>
 /// <param name="color">Color and opacity with which to draw the text</param>
 /// <param name="transform">Transformation matrix to apply to the text</param>
 public void DrawText(Text text, Matrix transform, Color color) {
   this.primitiveBatch.Draw(
     text.Vertices, text.Indices, text.PrimitiveType,
     new TextDrawContext(
       this.solidColorEffect, transform * this.viewProjection, color
     )
   );
 }
コード例 #4
0
ファイル: Text3D.cs プロジェクト: NinjaSteph/SureShot
 private void CreateShape()
 {
     switch (styleToUse)
     {
         case UI3DRenderer.Text3DStyle.Outline:
             basicTextIn3D = basicTextVectorFont.Outline(basicTextToRender);
             break;
         case UI3DRenderer.Text3DStyle.Fill:
             basicTextIn3D = basicTextVectorFont.Fill(basicTextToRender);
             break;
         case UI3DRenderer.Text3DStyle.Extrude:
             basicTextIn3D = basicTextVectorFont.Extrude(basicTextToRender);
             break;
     }
 }