private void Draw()
        {
            if (!renderTargetDrawn)
            {
                renderTexture.Use();
                renderTexture.Clear(Color4.Gray);
                vab.Bind();
                vao.Bind();
                pipeline.Bind();
                worldMatrix.Matrix = renderTexture.WorldMatrix;
                worldMatrix.Set(pipeline);
                vab.DrawDirect(3);
                var imageData = renderTexture.Framebuffer.Read(800, 600);
                var image     = Image.LoadPixelData <Rgba32>(imageData, 800, 600);
                image.Save("Screenshot.png");
                renderTargetDrawn = true;
                var sprite = SpriteDrawer.Draw(renderTexture, 0f, 0f);
                spriteRenderer.SetRenderItems(new SpriteRenderItem[] { sprite });
                spriteRenderer.RenderToData((data, count, tex) =>
                {
                    spriteDisplayList.SetVertices(data);
                    spriteDisplayList.SetIndices(SpriteRenderer.GetIndices(1));
                    resourceSet.Texture = tex;
                });
            }

            defaultFramebuffer.Bind();
            normal.Set();

            rotation += 0.001f;
            spriteDisplayList.Draw(resourceSet);
        }
示例#2
0
 protected void Draw()
 {
     worldMatrix.Matrix = Matrix4x4.CreateOrthographic(2.0f, 2.0f, -1.0f, +1.0f);
     pipeline.Bind();
     worldMatrix.Set(pipeline);
     buffer.Bind();
     indexBuffer.Bind();
     vao.Bind();
     texture.Set(pipeline);
     indexBuffer.DrawIndexed(buffer, 6);
 }
        private void Setup()
        {
            pipeline      = new ShaderPipeline(DefaultShader.FromType(typeof(VertexPositionColor), ShaderType.Vertex), DefaultShader.FromType(typeof(VertexPositionColor), ShaderType.Fragment));
            vab           = new VertexArrayBuffer <VertexPositionColor>(VertexPositionColor.Size, OpenGL.BufferUsage.StaticDraw);
            vao           = new VertexArrayObject <VertexPositionColor>(vab, pipeline, DefaultVertexDefinition.FromType(typeof(VertexPositionColor)));
            renderTexture = new RenderTexture(400, 400);

            vab.Bind();
            vao.Bind();
            pipeline.Bind();
            vab.CopyData(vertices);
            worldMatrix = new Matrix4fUniform(DefaultShader.MVP_UNIFORM_NAME);
            pipeline.Unbind();
            vao.Unbind();
            vab.Unbind();

            spriteRenderer     = new SpriteRenderer();
            defaultFramebuffer = Framebuffer.GetDefault();
            spriteDisplayList  = new DynamicDisplayList <VertexPositionColorTexture>(VertexPositionColorTexture.Size);
            resourceSet        = new TextureResourceSet(window);
        }