Example #1
0
        public void Render()
        {
            if (this.Active)
            {
                Matrix4Uniform textProjection = Engine.UniformManager.GetUniform <Matrix4Uniform>("textProjection");
                textProjection.Matrix = this.Camera.GetProjectionMatrix();
                textProjection.Set(this.GetShader());

                Vector3Uniform textColor = Engine.UniformManager.GetUniform <Vector3Uniform>("textColor");
                textColor.Value = new Vector3(this.Color.R, this.Color.G, this.Color.B);
                textColor.Set(this.GetShader());

                GL.ActiveTexture(TextureUnit.Texture0);
                this.vertexArray.Bind();
                this.vertexBuffer.Bind();
                GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * 6 * 4, (IntPtr)null, BufferUsageHint.DynamicDraw);

                for (int i = 0; i < this.Text.Length; i++)
                {
                    Font.Character character = this.Font.Characters[this.Text[i]];

                    GL.BindTexture(TextureTarget.Texture2D, character.TextureId);

                    TextVertex[] subVertices = textVertices.SubArray(i * 6, 6);

                    this.vertexBuffer.Bind();
                    this.vertexBuffer.BufferSubData((IntPtr)0, TextVertex.Size * subVertices.Length, subVertices);
                    GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
                    GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
                }
            }
        }
Example #2
0
        public double GetPixelWidth()
        {
            List <double> linesSize   = new List <double>();
            double        currentSize = 0;

            for (int i = 0; i < this.Text.Length; i++)
            {
                Font.Character character = this.Font.Characters[this.Text[i]];
                if (this.Text[i] == '\n')
                {
                    linesSize.Add(currentSize);
                    currentSize = 0;
                    continue;
                }
                currentSize += (double)(character.Advance) * this.Scale;
                if (i + 1 == this.Text.Length)
                {
                    linesSize.Add(currentSize);
                }
            }
            linesSize.Sort((double a, double b) => {
                if (a > b)
                {
                    return(1);
                }
                return(-1);
            });
            return(linesSize.First());
        }
Example #3
0
        public void UpdateVertexBuffer()
        {
            this.textVertices = new TextVertex[this.Text.Length * 6];
            int   vIndex = 0;
            float x      = this.Position.X;

            for (int i = 0; i < this.Text.Length; i++)
            {
                Font.Character character = this.Font.Characters[this.Text[i]];

                float xPos = x + character.Bearing.X * (float)this.Scale;
                float yPos = this.Position.Y - (character.Size.Height - character.Bearing.Y) * (float)this.Scale;

                float w = character.Size.Width * (float)this.Scale;
                float h = character.Size.Height * (float)this.Scale;

                this.textVertices[vIndex++] = new TextVertex(new Vector2(xPos, yPos + h), new Vector2(0, 0));
                this.textVertices[vIndex++] = new TextVertex(new Vector2(xPos, yPos), new Vector2(0, 1));
                this.textVertices[vIndex++] = new TextVertex(new Vector2(xPos + w, yPos), new Vector2(1, 1));

                this.textVertices[vIndex++] = new TextVertex(new Vector2(xPos, yPos + h), new Vector2(0, 0));
                this.textVertices[vIndex++] = new TextVertex(new Vector2(xPos + w, yPos), new Vector2(1, 1));
                this.textVertices[vIndex++] = new TextVertex(new Vector2(xPos + w, yPos + h), new Vector2(1, 0));

                x += character.Advance * (float)this.Scale;
            }
        }
Example #4
0
 public int GetPixelHeight()
 {
     Font.Character character = this.Font.Characters[this.Text[0]];
     return(character.Size.Height);
 }