Exemplo n.º 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;
            });
        }