示例#1
0
        private void UpdateString()
        {
            var chars = new List <Vertex>(3 * _str.Length);

            var split = _str.Split(new[] { '\n' }, StringSplitOptions.None);
            var prevY = 0f;

            for (int i = 0; i < split.Length; i++)
            {
                var prevX       = 0f;
                var leftPadding = TextAlignment == Alignment.LEFT ? 0 : (TextAlignment == Alignment.RIGHT ? -Font.GetStringWidth(split[i]) : -Font.GetStringWidth(split[i]) / 2);
                prevY -= Font.CharHeight;
                foreach (var c in split[i])
                {
                    var u = Font.GetUFor(c);
                    chars.AddRange(new Vertex[]
                    {
                        new Vertex(new Vector3(prevX + leftPadding, prevY + Font.CharHeight, 0f), new Vector2(u, 0)),
                        new Vertex(new Vector3(prevX + leftPadding, prevY, 0f), new Vector2(u, Font.CharTextureHeight)),
                        new Vertex(new Vector3(prevX + leftPadding + Font.CharWidth, prevY + Font.CharHeight, 0f), new Vector2(u + Font.CharTextureLength, 0)),

                        new Vertex(new Vector3(prevX + leftPadding + Font.CharWidth, prevY + Font.CharHeight, 0f), new Vector2(u + Font.CharTextureLength, 0)),
                        new Vertex(new Vector3(prevX + leftPadding, prevY, 0f), new Vector2(u, Font.CharTextureHeight)),
                        new Vertex(new Vector3(prevX + leftPadding + Font.CharWidth, prevY, 0f), new Vector2(u + Font.CharTextureLength, Font.CharTextureHeight)),
                    });

                    prevX += Font.CharWidth;
                }
            }

            if (_vbo == null)
            {
                _vbo = new Vbo();
            }
            _vbo.Bind();
            var charsArray = chars.ToArray();

            _trianglesCount = charsArray.Length;
            _vbo.SetData(charsArray);
            _vbo.Unbind();

            if (_vao == null)
            {
                _vao = new Vao <Vertex>();
            }
            _vao.BindVbo(_vbo, Shader, new[] {
                new VertexAttribute("_pos", 3, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes, 0),
                new VertexAttribute("_uv", 2, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes, Vector3.SizeInBytes),
            });
        }
示例#2
0
文件: Mesh.cs 项目: Entrivax/42run
        public void LoadInGl(Shader shader)
        {
            var vertices = Vertices.ToArray();

            _vbo = new Vbo();
            _vbo.Bind();
            _vbo.SetData(vertices);
            _vbo.Unbind();

            VerticesCount = vertices.Length;

            _vao = new Vao <Vertex>();
            _vao.BindVbo(_vbo, shader, new[] {
                new VertexAttribute("_pos", 3, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes, 0),
                new VertexAttribute("_uv", 2, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes, Vector3.SizeInBytes),
            });
            ClearVertices();
        }