示例#1
0
        public void Run()
        {
            PlainCoreSettings.GlfwSearchPath = Path.GetFullPath("../../../../../Native/");
            var window = new RenderWindow();

            var rs       = new TextureResourceSet(window);
            var t        = Texture.FromFile("Example.png");
            var renderer = new SpriteRenderer();
            var dl       = DynamicDisplayList <VertexPositionColorTexture> .Create(renderer);

            var sprites     = new List <SpriteRenderItem>();
            var description = FontGenerator.GenerateFont("OpenSans-Regular.ttf", 40);
            var font        = new Font(description);

            sprites.Add(SpriteDrawer.Draw(t, Color4.White, 0f, 0f));
            sprites.Add(SpriteDrawer.Draw(t, Color4.White, 100f, 100f));
            sprites.Add(SpriteDrawer.Draw(t, Color4.White, 200f, 200f));
            sprites.Add(SpriteDrawer.Draw(t, Color4.White, 400f, 400f));
            var glyphs = font.DrawString("ASDF", 500f, 400f);

            sprites.AddRange(glyphs);
            var indices = SpriteRenderer.GetIndices(sprites.Count);

            renderer.SetRenderItems(sprites.ToArray());

            while (window.IsOpen)
            {
                window.Clear(Color4.Black);

                window.PollEvents();

                renderer.RenderToData((vertices, count, tex) =>
                {
                    dl.SetVertices(vertices);
                    dl.SetIndices(indices, count);
                    rs.Texture = tex;
                    dl.Draw(rs, count);
                });

                window.Display();
            }

            dl.Dispose();
            font.Dispose();
            renderer.Dispose();
            window.Dispose();
        }
        private void Setup()
        {
            random = new Random();
            font   = Font.GenerateFromFont("OpenSans-Regular.ttf", 50);
            var textSprites = font.DrawString("HelloWorld", 0, 0);

            renderer = new SpriteRenderer();
            renderer.SetRenderItems(textSprites);
            resourceSet = new TextureResourceSet(window);
            displayList = DynamicDisplayList <VertexPositionColorTexture> .Create(renderer);

            renderer.RenderToData((vertices, count, tex) =>
            {
                displayList.SetIndices(SpriteRenderer.GetIndices(count));
                displayList.SetVertices(vertices);
                resourceSet.Texture = tex;
            });
        }
        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);
        }