コード例 #1
0
 public void AddBuffer(ref BufferObject bufferObject, BufferLayout bufferLayout = null)
 {
     Bind();
     bufferObject.Bind();
     _buffers.Add(bufferObject);
     if (bufferLayout != null)
     {
         int offset = 0;
         for (int i = 0; i < bufferLayout.Elements.Count; i++)
         {
             LayoutElement la = bufferLayout.Elements[i];
             GL.VertexAttribPointer(i, la.Count, la.Type, la.Normalized, bufferLayout.Stride, offset);
             GL.EnableVertexAttribArray(i);
             offset += LayoutElement.GetSizeOfType(la.Type) * la.Count;
         }
     }
 }
コード例 #2
0
        public void Dispose()
        {
            if (!_isDisposed)
            {
                GL.BindVertexArray(0);
                GL.DeleteVertexArray(_handle);

                for (int i = 0; i < _buffers.Count; i++)
                {
                    BufferObject bo = _buffers[i];
                    bo.Dispose();
                }

                GC.SuppressFinalize(this);
                _isDisposed = true;
            }
        }
コード例 #3
0
        protected override void OnLoad(EventArgs e)
        {
            float[] vertices =
            {
                0.5f,   0.5f, 0.0f, 1.0f, 1.0f,
                0.5f,  -0.5f, 0.0f, 1.0f, 0.0f,
                -0.5f, -0.5f, 0.0f, 0.0f, 0.0f,
                -0.5f,  0.5f, 0.0f, 0.0f, 1.0f
            };
            uint[] indices =
            {
                0, 1, 3,
                1, 2, 3
            };
            _vbo    = new BufferObject();
            _ebo    = new BufferObject();
            _layout = new BufferLayout();
            _vao    = new VertexArrayObject();

            _vbo.SetData(BufferTarget.ArrayBuffer, vertices);
            _ebo.SetData(BufferTarget.ElementArrayBuffer, indices);

            _layout.AddLayoutItem(VertexAttribPointerType.Float, 3);
            _layout.AddLayoutItem(VertexAttribPointerType.Float, 2);

            _vao.AddBuffer(ref _ebo);
            _vao.AddBuffer(ref _vbo, _layout);


            _shader  = new Shader("shader.vert", "shader.frag");
            _texture = new Texture("test");

            _transform = new Transform();
            _camera    = new Camera(Width, Height);
            _transform.SetShader(ref _shader);
            _camera.ApplyToShader(ref _shader);

            GL.ClearColor(1f, 1f, 1f, 1f);

            base.OnLoad(e);
        }