public void SetIndices(int[] indices, int elementCount)
        {
            if (indices == null)
            {
                throw new ArgumentNullException(nameof(indices));
            }

            elements = elementCount;
            indexBuffer.Bind();
            indexBuffer.CopyData(indices);
            indexBuffer.Unbind();
        }
        public void CanDrawSquare()
        {
            VertexBuffer vbuf = new VertexBuffer(Test_VertexBuffer.CUBE_VERTICES.Length);
            vbuf.CopyData(Test_VertexBuffer.CUBE_VERTICES);

            IndexBuffer ibuf = new IndexBuffer(Test_IndexBuffer.CUBE_INDICES.Length);
            ibuf.CopyData(Test_IndexBuffer.CUBE_INDICES);

            VertexFormat vfmt = new VertexFormat(Test_VertexFormat.CUBE_ATTRIBUTES);

            GraphicsSystem.BeginFrame();
            GraphicsSystem.Clear(Color.Black);
            GraphicsSystem.Draw(vbuf, vfmt, ibuf);
            GraphicsSystem.EndFrame();
            GraphicsSystem.Swap();

            Bitmap image = _wnd.GrabScreen();
            Assert.IsTrue(0 == image.GetPixel(30,30).R, "Square is larger than expected");
            Assert.IsTrue(0 < image.GetPixel(48,48).R, "Square was not rendered");
        }
        public StaticDisplayList(T[] vertices, int[] indices, uint vertexSize, OpenGL.PrimitiveType primitiveType = OpenGL.PrimitiveType.Triangles, ShaderPipeline pipeline = null, VertexAttributeDescription[] attributes = null) : base(vertexSize, pipeline, attributes)
        {
            if (vertices == null)
            {
                throw new ArgumentNullException(nameof(vertices));
            }
            if (indices == null)
            {
                throw new ArgumentNullException(nameof(indices));
            }

            vertexArrayBuffer = new VertexArrayBuffer <T>(vertexSize, OpenGL.BufferUsage.StaticDraw, primitiveType);
            indexBuffer       = new IndexBuffer <T>(OpenGL.BufferUsage.StaticDraw);
            vertexArrayObject = new VertexArrayObject <T>(vertexArrayBuffer, this.pipeline, vertexAttributes);
            vertexArrayBuffer.Bind();
            indexBuffer.Bind();
            vertexArrayBuffer.CopyData(vertices);
            indexBuffer.CopyData(indices);
            indexBuffer.Unbind();
            vertexArrayBuffer.Unbind();
            elementCount = indices.Length;
        }
Esempio n. 4
0
        protected void Setup()
        {
            var vs = DefaultShader.FromType(typeof(VertexPositionColorTexture), PlainCore.Graphics.Core.ShaderType.Vertex);
            var fs = DefaultShader.FromType(typeof(VertexPositionColorTexture), PlainCore.Graphics.Core.ShaderType.Fragment);

            pipeline    = new ShaderPipeline(vs, fs);
            buffer      = new VertexArrayBuffer <VertexPositionColorTexture>(32, OpenGL.BufferUsage.StaticDraw);
            indexBuffer = new IndexBuffer <VertexPositionColorTexture>(OpenGL.BufferUsage.StaticDraw);
            vao         = new VertexArrayObject <VertexPositionColorTexture>(buffer, pipeline,
                                                                             DefaultVertexDefinition.FromType(typeof(VertexPositionColorTexture)));
            texture            = new DeviceTexture(DefaultShader.DEFFAULT_TEXTURE_UNIFORM_NAME, 100, 100, true);
            defaultFramebuffer = Framebuffer.GetDefault();
            var imageData = Image.Load("Example.png").SavePixelData();

            texture.Bind();
            texture.CopyData(imageData);
            buffer.Bind();
            buffer.CopyData(_ArrayPosition);
            buffer.Unbind();
            indexBuffer.Bind();
            indexBuffer.CopyData(indexArray);
            indexBuffer.Unbind();
            worldMatrix = new Matrix4fUniform(DefaultShader.MVP_UNIFORM_NAME);
        }