예제 #1
0
        public void Write(string strText, Color color, float x, float y, float sx, float sy)
        {
            m_pProgram.Use();
            m_pProgram.Uniform(m_iUniformColor, color);



            for (int i = 0; i < strText.Length; i++)
            {
                char c = strText[i];

                try
                {
                    if (c == 32)
                    {
                        x += (m_iFontSize / 6) * sx;
                        continue;
                    }

                    uint glyphIndex = m_pFace.GetCharIndex(c);
                    m_pFace.LoadGlyph(glyphIndex, LoadFlags.Render, LoadTarget.Normal);
                    m_pFace.Glyph.RenderGlyph(RenderMode.VerticalLcd);

                    m_pTexture = new Texture("", m_pFace.Glyph.Bitmap.BufferData, TextureDataType.UnsignedByte,
                                             TextureFormat.Red, new Size(m_pFace.Glyph.Bitmap.Width, m_pFace.Glyph.Bitmap.Rows),
                                             TextureInternalFormat.R8);

                    m_pTexture.SetWrapping(TextureWrapping.ClampEdge, TextureWrapping.ClampEdge, TextureWrapping.ClampEdge);
                    m_pTexture.SetFilters(TextureFilter.Linear, TextureFilter.Linear);
                    m_pTexture.Rectangle.Y = m_pFace.Glyph.BitmapTop;
                    m_pTexture.Rectangle.X = m_pFace.Glyph.BitmapLeft;

                    m_pProgram.Uniform(m_iUniformTex, m_pTexture.glObject);
                }
                catch (Exception)
                {
                    continue;
                }
                float x2 = x + m_pTexture.Rectangle.Left * sx;
                float y2 = -y - m_pTexture.Rectangle.Top * sy;
                float w  = m_pTexture.Rectangle.Width * sx;
                float h  = m_pTexture.Rectangle.Height * sy;

                VertexDataBuffer data = new VertexDataBuffer();
                data.Vector4(new Vector4(x2, -y2, 0, 0));
                data.Vector4(new Vector4(x2 + w, -y2, 1, 0));
                data.Vector4(new Vector4(x2, -y2 - h, 0, 1));
                data.Vector4(new Vector4(x2 + w, -y2 - h, 1, 1));


                m_pVbo.Data(data, BufferUsage.DynamicDraw);
                m_pVao.BindElements(m_pVbo);

                m_pGame.GameContext.DrawArrays(m_pVao, Primitive.TrianglesStrip, 0, 4);

                x += (m_pFace.Glyph.Advance.X >> 6) * sx;
                y += (m_pFace.Glyph.Advance.Y >> 6) * sy;
            }
        }