Exemple #1
0
        private void LoadModelData(Model model)
        {
            GL.BindVertexArray(_vao);
            vertexBuffer.Bind();
            var name   = model.Path;
            var meshes = model.Meshes;

            _bufferDataPointers.Add(name, new List <MeshDataPointer>());

            foreach (var mesh in meshes)
            {
                var baseIndex = _vertices.Count;
                _vertices.AddRange(mesh.Vertices);
                _indices.AddRange(mesh.Indices);

                _bufferDataPointers[name].Add(new MeshDataPointer(baseIndex, mesh.Indices.Count, mesh.Material));
            }

            vertexBuffer.UpdateData(0, _vertices.Count * Vertex.Stride, _vertices.ToArray());
            //GL.BufferSubData(BufferTarget.ArrayBuffer, _lightDataPtr, _vertices.Count * Vertex.Stride, _vertices.ToArray());

            GL.BufferData(BufferTarget.ElementArrayBuffer, _indices.Count * sizeof(uint), _indices.ToArray(),
                          BufferUsageHint.StaticDraw);

            _logger.Info($"Loaded {model.Path} into VBO");
        }
        public void RenderText(Shader shader, string text, float x, float y, float scale, Vector3 color)
        {
            shader.Use();
            shader.SetVec3("textColor", color);
            shader.SetMat4("projection", projection);
            GL.BindVertexArray(VAO);
            GL.ActiveTexture(TextureUnit.Texture0);

            foreach (char c in text)
            {
                if (!characters.ContainsKey(c))
                {
                    LoadCharacter(c);
                }

                var character = characters[c];
                var xPos      = x + character.Bearing.X * scale;
                var yPos      = y - (character.Size.Y - character.Bearing.Y) * scale;

                var w = character.Size.X * scale;
                var h = character.Size.Y * scale;


                var vertices = new[]
                {
                    xPos, yPos + h, 0.0f, 0.0f,
                    xPos, yPos, 0.0f, 1.0f,
                    xPos + w, yPos, 1.0f, 1.0f,
                    xPos, yPos + h, 0.0f, 0.0f,
                    xPos + w, yPos, 1.0f, 1.0f,
                    xPos + w, yPos + h, 1.0f, 0.0f
                };

                GL.BindTexture(TextureTarget.Texture2D, character.TextureId);
                vertexArrayBuffer.UpdateData(0, 6 * 4 * sizeof(float), vertices);
                vertexArrayBuffer.Bind();
                GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
                vertexArrayBuffer.Unbind();

                x += (character.Advance >> 6) * scale;
            }

            GL.BindVertexArray(0);
            GL.BindTexture(TextureTarget.Texture2D, 0);
        }
Exemple #3
0
        public void RenderShape(Shader shader, UIShape shape)
        {
            if (!_dataPointers.ContainsKey(shape))
            {
                _renderableShapes.Add(shape);
                LoadUIObjectMeshData();
            }

            GL.Disable(EnableCap.DepthTest);
            GL.BindVertexArray(VAO);
            shader.Use();
            shader.SetMat4("projection", projection);
            uiVertexBuffer.Bind();
            shader.SetVec3("color", new Vector3(shape.Color.R, shape.Color.G, shape.Color.B));
            if (_dataPointers.ContainsKey(shape))
            {
                var pointer = _dataPointers[shape];
                GL.DrawArrays(PrimitiveType.Triangles, pointer.Start, pointer.Count);
            }
            uiVertexBuffer.Unbind();
            GL.BindVertexArray(0);
            GL.Enable(EnableCap.DepthTest);
        }