コード例 #1
0
        public void RenderText(string text, float x, float y, Vector3 color)
        {
            float tmpX = x;
            float tmpY = y;

            _textPs.UseProgram();
            _textPs.SetVariable("projection", ProjMatrix);
            _textPs.SetVariable("textColor", color);

            foreach (var c in text)
            {
                Character ch = _characters[c];

                float xpos = tmpX + ch.Bearing.X;
                float ypos = tmpY + ch.Bearing.Y - ch.Size.Y;

                float w = ch.Size.X;
                float h = ch.Size.Y;

                float[] vertices = new float[]
                {
                    xpos, ypos + h, 0.0f, 0.0f,
                    xpos, ypos, 0.0f, 1.0f,
                    xpos + w, ypos, 1.0f, 1.0f,
                    xpos + w, ypos + h, 1.0f, 0.0f
                };

                tmpX += ch.Advance + 1; // Bitshift by 6 to get value in pixels (2^6 = 64
                //Console.WriteLine(ch.Advance >> 6);

                Texture.SetTexture(ch.TextureID);
                vbo.ChangeData(vertices);
                vao.Draw();
                Texture.Clear();
            }
        }