Beispiel #1
0
        public void UploadInGl()
        {
            var vertices = new Vertex[]
            {
                new Vertex(new Vector3(0, 0 + Size.Y, 0f), new Vector3(0, 0, 1), new Vector2(_uvStart.X, _uvStart.Y)),
                new Vertex(new Vector3(0, 0, 0f), new Vector3(0, 0, 1), new Vector2(_uvStart.X, _uvEnd.Y)),
                new Vertex(new Vector3(0 + Size.X, 0 + Size.Y, 0f), new Vector3(0, 0, 1), new Vector2(_uvEnd.X, _uvStart.Y)),

                new Vertex(new Vector3(0 + Size.X, 0 + Size.Y, 0f), new Vector3(0, 0, 1), new Vector2(_uvEnd.X, _uvStart.Y)),
                new Vertex(new Vector3(0, 0, 0f), new Vector3(0, 0, 1), new Vector2(_uvStart.X, _uvEnd.Y)),
                new Vertex(new Vector3(0 + Size.X, 0, 0f), new Vector3(0, 0, 1), new Vector2(_uvEnd.X, _uvEnd.Y)),
            };

            if (_vbo == null)
            {
                _vbo = new Vbo();
            }
            _vbo.Bind();
            _trianglesCount = vertices.Length;
            _vbo.SetData(vertices);
            _vbo.Unbind();

            if (_vao == null)
            {
                _vao = new Vao <Vertex>();
            }
            _vao.BindVbo(_vbo, Shader, new[] {
                new VertexAttribute("_pos", 3, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, 0),
                new VertexAttribute("_uv", 2, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, Vector3.SizeInBytes * 2),
            });
        }
Beispiel #2
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 Vector3(0, 0, 1), new Vector2(u, 0)),
                        new Vertex(new Vector3(prevX + leftPadding, prevY, 0f), new Vector3(0, 0, 1), new Vector2(u, Font.CharTextureHeight)),
                        new Vertex(new Vector3(prevX + leftPadding + Font.CharWidth, prevY + Font.CharHeight, 0f), new Vector3(0, 0, 1), new Vector2(u + Font.CharTextureLength, 0)),

                        new Vertex(new Vector3(prevX + leftPadding + Font.CharWidth, prevY + Font.CharHeight, 0f), new Vector3(0, 0, 1), new Vector2(u + Font.CharTextureLength, 0)),
                        new Vertex(new Vector3(prevX + leftPadding, prevY, 0f), new Vector3(0, 0, 1), new Vector2(u, Font.CharTextureHeight)),
                        new Vertex(new Vector3(prevX + leftPadding + Font.CharWidth, prevY, 0f), new Vector3(0, 0, 1), 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 + Vector3.SizeInBytes + Vector4.SizeInBytes, 0),
                new VertexAttribute("_uv", 2, VertexAttribPointerType.Float, Vector2.SizeInBytes + Vector3.SizeInBytes + Vector3.SizeInBytes + Vector4.SizeInBytes, Vector3.SizeInBytes * 2),
            });
        }
Beispiel #3
0
 public void UpdateData()
 {
     if (!Loaded)
     {
         LoadInGl();
     }
     if (!Invalidated)
     {
         return;
     }
     VerticesCount = Objects.Count;
     if (_vbo != null)
     {
         var objs = Objects.ToArray();
         _vbo.Bind();
         _vbo.SetData(objs);
         _vbo.Unbind();
     }
 }
Beispiel #4
0
        public void LoadInGl()
        {
            if (Loaded)
            {
                return;
            }
            VerticesCount = Objects.Count;
            if (Objects.Count == 0)
            {
                return;
            }
            var objs = Objects.ToArray();

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

            Loaded      = true;
            Invalidated = false;
        }
Beispiel #5
0
        public void LoadInGl()
        {
            if (Loaded)
            {
                return;
            }
            VerticesCount = Vertices.Count;
            if (Vertices.Count == 0)
            {
                return;
            }
            var vertices = Vertices.ToArray();

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

            ClearVertices();
            Loaded = true;
        }