Exemplo n.º 1
0
        public override void Draw(RenderComposer composer)
        {
            Color textCol = new Color(32, 32, 32);

            int    size = 20;
            string text = "The quick brown fox jumped over the lazy dog.";

            composer.SetUseViewMatrix(false);

            composer.RenderSprite(new Vector3(0, 0, 0), Engine.Renderer.CurrentTarget.Size, new Color(240, 240, 240));

            composer.PushModelMatrix(Matrix4x4.CreateScale(1, 1, 1) * Matrix4x4.CreateTranslation(100, 100, 0));

            FontAsset.GlyphRasterizer = GlyphRasterizer.Emotion;
            composer.RenderLine(new Vector3(0, 0, 0), new Vector3(500, 0, 0), Color.Red);
            composer.RenderString(new Vector3(0, 0, 0), textCol, "Emotion Renderer:\n" + text, _font.GetAtlas(size));

            FontAsset.GlyphRasterizer = GlyphRasterizer.EmotionSDFVer3;
            composer.RenderLine(new Vector3(0, 140, 0), new Vector3(500, 140, 0), Color.Red);
            composer.RenderString(new Vector3(0, 140, 0), textCol, "EmotionSDFVer3:\n" + text, _font.GetAtlas(size));

            FontAsset.GlyphRasterizer = GlyphRasterizer.EmotionSDFVer4;
            composer.RenderLine(new Vector3(0, 300, 0), new Vector3(500, 300, 0), Color.Red);
            composer.RenderString(new Vector3(0, 300, 0), textCol, "EmotionSDFVer4:\n" + text, _font.GetAtlas(size));

            FontAsset.GlyphRasterizer = GlyphRasterizer.StbTrueType;
            composer.RenderLine(new Vector3(0, 450, 0), new Vector3(500, 450, 0), Color.Red);
            composer.RenderString(new Vector3(0, 450, 0), textCol, "StbTrueType:\n" + text, _font.GetAtlas(size));

            composer.PopModelMatrix();

            composer.SetUseViewMatrix(true);
        }
Exemplo n.º 2
0
        public void RenderDepthTest()
        {
            var       asset     = Engine.AssetLoader.Get <TextureAsset>("Images/logoAlpha.png");
            var       fontAsset = Engine.AssetLoader.Get <FontAsset>("Fonts/1980XX.ttf");
            const int maxY      = 5 * 49;

            Runner.ExecuteAsLoop(_ =>
            {
                RenderComposer composer = Engine.Renderer.StartFrame();

                // Set a background so invalid alpha can be seen
                composer.RenderSprite(new Vector3(0, 0, -1), Engine.Renderer.CurrentTarget.Size, Color.CornflowerBlue);

                for (var i = 0; i < 50; i++)
                {
                    composer.RenderSprite(new Vector3(5 * i, 5 * i, i), new Vector2(100, 100), Color.White, asset.Texture);
                }

                for (var i = 0; i < 50; i++)
                {
                    composer.RenderSprite(new Vector3(5 * i, maxY - 5 * i, i), new Vector2(100, 100), Color.White, asset.Texture);
                }

                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X, 0, 0), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 50, 0, 1), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 100, 0, 0), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 150, 0, 1), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 200, 0, 0), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 250, 0, 1), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 300, 0, 0), new Vector2(100, 100), Color.White, asset.Texture);

                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X, 100, 1), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 50, 100, 0), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 100, 100, 1), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 150, 100, 0), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 200, 100, 1), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 250, 100, 0), new Vector2(100, 100), Color.White, asset.Texture);
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X - 300, 100, 1), new Vector2(100, 100), Color.White, asset.Texture);

                composer.RenderString(new Vector3(Engine.Renderer.CurrentTarget.Size.X / 2 - 100, 0, 1), Color.Red, "This is test text", fontAsset.GetAtlas(20));
                composer.RenderString(new Vector3(Engine.Renderer.CurrentTarget.Size.X / 2 - 100, 10, 2), Color.Green, "This is test text", fontAsset.GetAtlas(20));
                composer.RenderString(new Vector3(Engine.Renderer.CurrentTarget.Size.X / 2 - 100, 20, 1), Color.Blue, "This is test text", fontAsset.GetAtlas(20));
                composer.RenderSprite(new Vector3(Engine.Renderer.CurrentTarget.Size.X / 2 - 100, 0, 0), new Vector2(200, 100), Color.Black);

                Engine.Renderer.EndFrame();
                Runner.VerifyScreenshot(ResultDb.ComposerRender);
            }).WaitOne();
        }
Exemplo n.º 3
0
        public override void Render(RenderComposer composer)
        {
            if (InclineAngle != 0f)
            {
                composer.PushModelMatrix(
                    Matrix4x4.CreateRotationZ(InclineAngle, new Vector3(Center, 0))
                    );
            }
            composer.RenderSprite(
                Position,
                Size,
                !IsAffectedByGravityPush ? Color.White : Color.Pink,
                TextureAsset.Texture,
                null,
                IsFacingRight
                );
            if (InclineAngle != 0f)
            {
                composer.PopModelMatrix();
            }

            if (IsInteracting)
            {
                string text = Dialogues[0].DialogueLines[0];
                composer.RenderString(Position + new Vector3(-30, -30, 0), Color.Black, text, Engine.AssetLoader.Get <FontAsset>("Fonts/Calibri 400.ttf").GetAtlas(16));
            }


            //Rectangle futurePosition = new Rectangle(CollisionBox.X, CollisionBox.Y - (GravityTimer.Progress * StartingVelocityY), CollisionBox.Width, CollisionBox.Height);
            //composer.RenderOutline(futurePosition, Color.Green, 1);
            //composer.RenderOutline(CollisionBox.ToRectangle(), Color.Red, 2);
        }
Exemplo n.º 4
0
        protected override void RenderContent(RenderComposer composer)
        {
            ImGui.InputInt("Font Size", ref _size);

            if (ImGui.Button("Select Font"))
            {
                var explorer = new FileExplorer <FontAsset>(f => { _font = f; });
                Parent.AddWindow(explorer);
            }

            if (_font == null)
            {
                return;
            }

            ImGui.Text($"Font: {_font.Font.FullName}");
            ImGui.Text($"Asset Name: {_font.Name}");
            if (ImGui.Checkbox("Emotion Renderer", ref _emotionRenderer))
            {
                FontAsset.GlyphRasterizer = _emotionRenderer ? GlyphRasterizer.Emotion : GlyphRasterizer.StbTrueType;
            }
            ImGui.InputTextMultiline("Test Text", ref _testText, 200, new Vector2(200, 100));

            composer.RenderString(new Vector3(0, 100, 0), Color.Black, _testText, _font.GetAtlas(_size));
        }
Exemplo n.º 5
0
        protected override void RenderContent(RenderComposer composer)
        {
            Vector2 offset = ImGui.GetWindowPos();

            offset.Y   += ImGui.GetWindowHeight();
            _lastOffset = offset;
            composer.RenderSprite(new Vector3(offset, 0), _anim.Texture.Size * _parent.Scale, Color.White, _anim.Texture);
            for (var i = 0; i < _anim.Frames.Length; i++)
            {
                composer.RenderOutline(new Vector3(offset + _anim.Frames[i].Position * _parent.Scale, 1), _anim.Frames[i].Size * _parent.Scale, _holdingIdx == i ? Color.Green : Color.Red);
                var stringPos           = new Vector3(offset + _anim.Frames[i].Position * _parent.Scale, 1);
                DrawableFontAtlas atlas = _font.GetAtlas(15 * _parent.Scale);
                composer.RenderString(stringPos + new Vector3(1), Color.Black, i.ToString(), atlas);
                composer.RenderString(stringPos, Color.Red, i.ToString(), atlas);
            }

            ImGui.Text(_holdingIdx == -1 ? "Click on a rectangle to change it's position." : $"Select new position for frame {_holdingIdx}!");
        }
Exemplo n.º 6
0
        public void RenderText()
        {
            var asset = Engine.AssetLoader.Get <FontAsset>("Fonts/1980XX.ttf");

            Runner.ExecuteAsLoop(_ =>
            {
                RenderComposer composer = Engine.Renderer.StartFrame();
                composer.RenderString(new Vector3(10, 10, 0), Color.Red, "The quick brown fox jumps over the lazy dog.\n123456789!@#$%^&*(0", asset.GetAtlas(20));
                Engine.Renderer.EndFrame();
                Runner.VerifyScreenshot(ResultDb.ComposerRenderText);
            }).WaitOne();
        }
Exemplo n.º 7
0
        public override void Draw(RenderComposer composer)
        {
            DrawableFontAtlas atlas = _font.GetAtlas(30);
            var    l = new TextLayouter(atlas.Atlas);
            string text;

            if (!_myPaddle.Ready)
            {
                text = "Press 'Space' when ready!";
            }
            else if (_pad1 == _myPaddle && !_pad2.Ready || _pad2 == _myPaddle && !_pad1.Ready)
            {
                text = "Waiting for other player.";
            }
            else
            {
                text = $"{_pad1.Score}/{_pad2.Score}";
            }

            Vector2 textSize = l.MeasureString(text);
            float   screenHorizontalCenter = Engine.Configuration.RenderSize.X / 2;

            composer.RenderString(new Vector3(screenHorizontalCenter - textSize.X / 2, 10, 0), Color.White, text, atlas);

            composer.RenderSprite(_pad1.VisualPosition, _pad1.Size, _pad1.Ready ? Color.White : Color.Red);
            composer.RenderSprite(_pad2.VisualPosition, _pad2.Size, _pad2.Ready ? Color.White : Color.Red);

            // Uncomment to view paddle collisions.
            //LineSegment[] padCol = _pad2.GetPaddleCollision();
            //for (var i = 0; i < padCol.Length; i++)
            //{
            //    composer.RenderLine(ref padCol[i], Color.Red);
            //}

            NetworkTransform ball = IdToObject["Ball"];

            composer.RenderSprite(ball.VisualPosition, ball.Size, Color.White);

            NetworkTransform upperWall = IdToObject["UpperWall"];
            NetworkTransform lowerWall = IdToObject["LowerWall"];

            composer.RenderSprite(upperWall.VisualPosition, upperWall.Size, Color.White);
            composer.RenderSprite(lowerWall.VisualPosition, lowerWall.Size, Color.White);
        }
Exemplo n.º 8
0
        public void Draw(RenderComposer composer)
        {
            foreach (Decoration bg in Backgrounds)
            {
                bg.Render(composer);
            }

            foreach (Decoration dec in BackgroundDecorations)
            {
                if (IsTransformOnSreen(dec))
                {
                    dec.Render(composer);
                }
            }

            foreach (Unit unit in Units)
            {
                if (IsTransformOnSreen(unit))
                {
                    unit.Render(composer);
                }
            }

            foreach (Collision.LineSegment plat in CollisionPlatforms)
            {
                plat.Render(composer);
            }

            // Draw Magic Flows
            foreach (MagicFlow mf in MagicFlows)
            {
                mf.Render(composer);
            }

            // Render Scene Changers
            for (int i = 0; i < SceneChangers.Count; i++)
            {
                SceneChangers[i].Render(composer);
            }

            // Render the player
            Player.Render(composer);

            foreach (Decoration dec in ForegroundDecorations)
            {
                if (IsTransformOnSreen(dec))
                {
                    dec.Render(composer);
                }
            }

            // Draw the room ceiling
            composer.RenderLine(new Vector3(0, 0, 15), new Vector3(LoadedRoom.Size.X, 0, 6), Color.Cyan, 1);

            // Draw camera position (probably the center of the screen)
            composer.RenderCircle(Engine.Renderer.Camera.Position, 1, Color.Cyan);

            // Display the current interaction
            if (CurrentInteration != null)
            {
                CurrentInteration.Render(composer);
            }

            // Draw DebugObjects' CollisionBoxes
            for (int i = 0; i < DebugObjects.Count; i++)
            {
                DebugObject debugObj = DebugObjects[i];
                debugObj.RenderObjectRectange(composer);
            }

            // Disabled the camera and draw on Screen Space instead of World Space
            composer.SetUseViewMatrix(false);

            // Draw DebugObjects
            for (int i = 0; i < DebugObjects.Count; i++)
            {
                DebugObject  debugObj             = DebugObjects[i];
                int          fontSize             = 18;
                float        debugObjDisplayWidth = debugObj.LongestLine.Length * 8; // Magic number
                TextureAsset textureAsset         = Engine.AssetLoader.Get <TextureAsset>("Textures/better-transparent-black.png");
                composer.RenderSprite(
                    new Vector3(debugObjDisplayWidth * i, 0, 15),
                    new Vector2(debugObjDisplayWidth, Engine.Configuration.RenderSize.Y),
                    Color.White,
                    textureAsset.Texture
                    );
                composer.RenderString(
                    new Vector3(debugObjDisplayWidth * i, 0, 15),
                    Color.Red,
                    debugObj.ToString(),
                    Engine.AssetLoader.Get <FontAsset>("Fonts/Calibri 400.ttf").GetAtlas(fontSize)
                    );
            }

            // Draw circle on mouse pointer
            composer.RenderCircle(new Vector3(Engine.InputManager.MousePosition, 15), 3, Color.Red, true);
            // Draw mouse coordinates
            composer.RenderString(
                new Vector3(20, Engine.Configuration.RenderSize.Y - 80, 15),
                Color.Red,
                Engine.InputManager.MousePosition.ToString(),
                Engine.AssetLoader.Get <FontAsset>("Fonts/Calibri 400.ttf").GetAtlas(18)
                );


            // Enable the camera again
            composer.SetUseViewMatrix(true);

            // Render the Emotion Tools UI
            //composer.RenderToolsMenu();
        }
Exemplo n.º 9
0
        public void Render(RenderComposer composer)
        {
            // Disabled the camera and draw on Screen Space instead of World Space
            composer.SetUseViewMatrix(false);
            composer.RenderSprite(
                new Vector3(Vector2.Zero, BackgroundZ),
                new Vector2(1920, 1080),
                Color.White,
                Texture.Texture
                );

            Vector3 Unit1Position;

            if (Unit1OnTheLeft)
            {
                Unit1Position = LeftPosition + new Vector3(Unit1.InteractionOffset, 0);
            }
            else
            {
                Unit1Position = RightPosition + new Vector3(Unit1.InteractionOffset.X * -1, Unit1.InteractionOffset.Y, 0);
            }
            composer.RenderSprite(
                Unit1Position,
                Unit1.PortraitSize,
                Color.White,
                Unit1.TextureAsset.Texture,
                null,
                Unit1OnTheLeft
                );

            Vector3 Unit2Position;

            if (Unit1OnTheLeft)
            {
                Unit2Position = RightPosition + new Vector3(Unit2.InteractionOffset.X * -1, Unit2.InteractionOffset.Y, 0);
            }
            else
            {
                Unit2Position = LeftPosition + new Vector3(Unit2.InteractionOffset, 0);
            }
            composer.RenderSprite(
                Unit2Position,
                Unit2.PortraitSize,
                Color.White,
                Unit2.TextureAsset.Texture,
                null,
                !Unit1OnTheLeft
                );

            if (Unit2.Dialogues != null)
            {
                if (CurrentLetterIndex >= Unit2.Dialogues[0].DialogueLines[0].Length)
                {
                    // Set whenever the user initiates the next line
                    //CurrentLetterIndex = 0;
                    //LastLetterFrame = CurrentFrame;
                    Finished = true;

                    composer.RenderString(
                        new Vector3(760, 900, 12), // 200px left of the center
                        Color.Green,
                        Unit2.Dialogues[0].DialogueLines[0],
                        Font.GetAtlas(FontSize)
                        );
                }
                else
                {
                    composer.RenderString(
                        new Vector3(760, 900, 12),   // 200px left of the center
                        Color.Green,
                        Unit2.Dialogues[0].DialogueLines[0].Substring(0, CurrentLetterIndex + 1),
                        Font.GetAtlas(FontSize)
                        );
                }
            }
        }
Exemplo n.º 10
0
 public void Draw(RenderComposer composer)
 {
     composer.SetUseViewMatrix(false);
     composer.RenderString(Vector3.Zero, Color.White, "Connecting...", _font.GetAtlas(30));
     composer.SetUseViewMatrix(true);
 }
Exemplo n.º 11
0
        protected override bool RenderInternal(RenderComposer c)
        {
            var open = true;

            ImGui.SetNextWindowPos(new Vector2(0, 20), ImGuiCond.Always);
            ImGui.SetNextWindowSize(c.CurrentTarget.Size - new Vector2(0, 20));
            ImGui.Begin(Title, ref open, ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoCollapse | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoMove);

            RenderImGui();

            ImGui.End();

            Position = Vector3.Zero;
            Size     = c.CurrentTarget.Size;
            if (!open)
            {
                Parent?.RemoveChild(this);
                return(false);
            }

            if (_textureFb?.ColorAttachment == null)
            {
                return(true);                                     // Disposed or uninitialized fb
            }
            if (_currentAssetTexture == null)
            {
                return(true);
            }

            _textureFb.ColorAttachment.Smooth = false;
            c.RenderToAndClear(_textureFb);
            c.RenderSprite(Vector3.Zero, _currentAssetTexture.Size, _currentAssetTexture);

            // Render meta overlay on the spritesheet texture.
            if (_currentAsset != null)
            {
                AnimatedSprite             currentFileContext = _currentAsset.Content !;
                SpriteAnimationFrameSource frameSource        = currentFileContext.FrameSource;
                if (frameSource != null)
                {
                    for (var i = 0; i < frameSource.GetFrameCount(); i++)
                    {
                        Rectangle frameUv = frameSource.GetFrameUV(i);
                        c.RenderOutline(frameUv, _selectedFrame == i ? Color.Green : Color.Red);

                        if (_showFrameIdx && frameSource is SpriteArrayFrameSource)
                        {
                            Vector3           stringPos = frameUv.Position.ToVec3();
                            DrawableFontAtlas atlas     = _debugFont.GetAtlas(20);
                            c.RenderString(stringPos + new Vector3(1), Color.Black, i.ToString(), atlas);
                            c.RenderString(stringPos, Color.Red, i.ToString(), atlas);
                        }
                    }
                }
            }

            c.RenderTo(null);

            RenderAnimationPreview(c);

            return(true);
        }