Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of <see cref="VertexArray"/>.
        /// </summary>
        /// <param name="vb">The <see cref="VertexBuffer"/> and <see cref="IndexBuffer"/> required to create the <see cref="VertextArray"/>.</param>
        /// <param name="ib">The <see cref="IndexBuffer"/> that describes the layout of the <see cref="VertextBuffer"/> for the <see cref="VertexArray"/>.</param>
        public VertexArray(VertexArrayBuffer <T> vb, IndexBuffer ib)
        {
            if (vb is null)
            {
                throw new ArgumentNullException(nameof(vb), "The param must not be null");
            }

            if (ib is null)
            {
                throw new ArgumentNullException(nameof(ib), "The param must not be null");
            }

            ID = GL.GenVertexArray();

            Bind();

            GL.BindBuffer(BufferTarget.ArrayBuffer, vb.ID);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, ib.ID);

            //Setup aPosition attribute
            GL.EnableVertexArrayAttrib(ID, 0);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 9 * sizeof(float), 0);


            //Setup aTexCoord attribute
            GL.EnableVertexArrayAttrib(ID, 1);
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 9 * sizeof(float), 3 * sizeof(float));


            //Setup u_TintClr attribute
            GL.EnableVertexArrayAttrib(ID, 2);
            GL.VertexAttribPointer(2, 4, VertexAttribPointerType.Float, false, 9 * sizeof(float), 5 * sizeof(float));
        }
Exemplo n.º 2
0
        public Renderer(int renderSurfaceWidth, int renderSurfaceHeight)
        {
            Shader = new ShaderProgram("shader.vert", "shader.frag");

            _renderSurfaceWidth  = renderSurfaceWidth;
            _renderSurfaceHeight = renderSurfaceHeight;

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
            GL.ClearColor(0.2f, 0.3f, 0.3f, 1.0f);//TODO: Allow changing of this

            Shader.UseProgram();

            InitBufferData();

            _vertexBuffer = new VertexArrayBuffer <QuadBufferData>(_vertexBufferData);
            _indexBuffer  = new IndexBuffer(new uint[] { 0, 1, 3, 1, 2, 3, 4, 5 });

            _vertexArray = new VertexArray <QuadBufferData>(_vertexBuffer, _indexBuffer);
        }