Пример #1
0
 /// <summary>
 /// Returns the vertex' <see cref="VertexAttributes" />
 /// </summary>
 /// <returns>
 /// Array of <see cref="VertexAttribute" />
 /// </returns>
 public         VertexAttribute[] VertexAttributes()
 {
     if (UVColorVertexData.vertexAttributes == null)
     {
         UVColorVertexData.setVertexAttributes();
     }
     return(UVColorVertexData.vertexAttributes);
 }
Пример #2
0
        /// <summary>
        /// Draws a string.
        /// </summary>
        /// <param name="position">The position to draw at.</param>
        /// <param name="text">The string to draw.</param>
        private void drawStringReal(Vector3 position, string text)
        {
            int l = text.Length;
            UVColorVertexData[] vertices = new UVColorVertexData[l * 4];

            int v_i = 0;

            Vector2 charSize = this.Font.SymbolSize * this.Height;

            charSize.X *= this.SizeCoefficient.X;
            charSize.Y *= this.SizeCoefficient.Y;
            Vector2 uvSymbolSize = this.Font.UVSymbolSize;
            Vector2 uvOffset = this.Font.UVSymbolOffset;
            bool monospaced = this.Font.Monospaced;

            float wRatio = charSize.X  * 16;
            
            Vector3 yOffset = charSize.Y * this.UnitY;

            for (int i = 0; i < l; i++)
            {
                byte c = (byte)text[i];
                float u = (c % 16) * uvSymbolSize.X + uvOffset.X;
                float v = (c / 16) * uvSymbolSize.Y + uvOffset.Y;

                float w;
                float wu;
                if (monospaced)
                {
                    w = charSize.X;
                    wu = uvSymbolSize.X;
                }
                else
                {
                    float f = this.Font.LetterWidth(c);
                    w = wRatio * f;
                    wu = f;
                }

                Vector3 position2 = position + w * this.UnitX;

                // left top
                vertices[v_i++] = new UVColorVertexData(position,
                    new Vector2(u, v), this.Color);

                // right top
                vertices[v_i++] = new UVColorVertexData(position2,
                    new Vector2(u + wu, v), this.Color);

                // right bottom
                vertices[v_i++] = new UVColorVertexData(position2 + yOffset,
                    new Vector2(u + wu, v + uvSymbolSize.Y), this.Color);

                // left bottom
                vertices[v_i++] = new UVColorVertexData(position + yOffset,
                    new Vector2(u, v + uvSymbolSize.Y), this.Color);

                position = position2;
            }

            var indexOffset = this.Surface.AddVertices(vertices);

            var indices = new ushort[l * 6];
            int id = 0;
            for (int i = 0; i < l; i++)
            {
                int b = indexOffset + i * 4;
                indices[id++] = (ushort)(b);
                indices[id++] = (ushort)(b + 1);
                indices[id++] = (ushort)(b + 2);
                indices[id++] = (ushort)(b);
                indices[id++] = (ushort)(b + 2);
                indices[id++] = (ushort)(b + 3);
            }

            this.Surface.AddIndices(indices);
        }
Пример #3
0
        /// <summary>
        /// Draws a string.
        /// </summary>
        /// <param name="position">The position to draw at.</param>
        /// <param name="text">The string to draw.</param>
        private void drawStringReal(Vector3 position, string text)
        {
            int l = text.Length;

            UVColorVertexData[] vertices = new UVColorVertexData[l * 4];

            int v_i = 0;

            Vector2 charSize = this.Font.SymbolSize * this.Height;

            charSize.X *= this.SizeCoefficient.X;
            charSize.Y *= this.SizeCoefficient.Y;
            Vector2 uvSymbolSize = this.Font.UVSymbolSize;
            Vector2 uvOffset     = this.Font.UVSymbolOffset;
            bool    monospaced   = this.Font.Monospaced;

            float wRatio = charSize.X * 16;

            Vector3 yOffset = charSize.Y * this.UnitY;

            for (int i = 0; i < l; i++)
            {
                byte  c = (byte)text[i];
                float u = (c % 16) * uvSymbolSize.X + uvOffset.X;
                float v = (c / 16) * uvSymbolSize.Y + uvOffset.Y;

                float w;
                float wu;
                if (monospaced)
                {
                    w  = charSize.X;
                    wu = uvSymbolSize.X;
                }
                else
                {
                    float f = this.Font.LetterWidth(c);
                    w  = wRatio * f;
                    wu = f;
                }

                Vector3 position2 = position + w * this.UnitX;

                // left top
                vertices[v_i++] = new UVColorVertexData(position,
                                                        new Vector2(u, v), this.Color);

                // right top
                vertices[v_i++] = new UVColorVertexData(position2,
                                                        new Vector2(u + wu, v), this.Color);

                // right bottom
                vertices[v_i++] = new UVColorVertexData(position2 + yOffset,
                                                        new Vector2(u + wu, v + uvSymbolSize.Y), this.Color);

                // left bottom
                vertices[v_i++] = new UVColorVertexData(position + yOffset,
                                                        new Vector2(u, v + uvSymbolSize.Y), this.Color);

                position = position2;
            }

            var indexOffset = this.Surface.AddVertices(vertices);

            var indices = new ushort[l * 6];
            int id      = 0;

            for (int i = 0; i < l; i++)
            {
                int b = indexOffset + i * 4;
                indices[id++] = (ushort)(b);
                indices[id++] = (ushort)(b + 1);
                indices[id++] = (ushort)(b + 2);
                indices[id++] = (ushort)(b);
                indices[id++] = (ushort)(b + 2);
                indices[id++] = (ushort)(b + 3);
            }

            this.Surface.AddIndices(indices);
        }