예제 #1
0
 protected override void OnRender(Registry registry)
 {
     if (registry.TryGetSingletonComponent(out LoadingScreenComponent component))
     {
         Renderer2D.BeginScene();
         Renderer2D.DrawQuad(component.Texture, component.Transform);
         Renderer2D.EndScene();
     }
 }
예제 #2
0
        public void OnUpdate(TimeStep ts)
        {
            ProfilerTimer.Profile("Sandbox.OnUpdate", () =>
            {
                //Update
                {
                    ProfilerTimer.Profile("Sandbox Update", () => cameraController.OnUpdate(ts));
                }

                //Render
                {
                    ProfilerTimer.Profile("Renderer Prep", () =>
                    {
                        RenderingAPI.SetClearColor(0.1f, 0.1f, 0.1f);
                        RenderingAPI.Clear();
                    });
                }

                {
                    ProfilerTimer.Profile("Renderer Draw", () =>
                    {
                        Renderer2D.BeginScene(cameraController.GetCamera());
                        {
                            Renderer2D.DrawRotatedQuad(new Transform
                            {
                                Position = new Vector3(-1.0f, 0.0f, 0.0f),
                                Scale    = new Vector2(0.8f, 0.8f),
                                Rotation = 45.0f
                            }, new Vector4(0.8f, 0.2f, 0.3f, 1.0f));

                            Renderer2D.DrawQuad(new Transform
                            {
                                Position = new Vector3(0.5f, -0.5f, 1.0f),
                                Scale    = new Vector2(0.5f, 0.75f)
                            }, new Vector4(0.2f, 0.3f, 0.8f, 1.0f));

                            Renderer2D.DrawQuad(new Transform
                            {
                                Position = new Vector3(0f, 0f, -0.1f),
                                Scale    = new Vector2(10f, 10f)
                            }, birdiTexture, new Vector4(1.0f, 0.9f, 0.9f, 1.0f), 10.0f);
                        }
                        Renderer2D.EndScene();
                    });
                }
            });
        }
예제 #3
0
        public override void Draw(Scene scene, Matrix4x4 viewProjectionMatrix, Framebuffer framebuffer = null)
        {
            if (framebuffer != null)
            {
                framebuffer.EnableColorDrawBuffer(scene.Pipeline.FbStructureIndex.Color, true);
                framebuffer.EnableColorDrawBuffer(scene.Pipeline.FbStructureIndex.Id, true);
            }

            // TODO: add transparency
            Renderer2D.BeginScene(viewProjectionMatrix);
            {
                if (bucket != null)
                {
                    foreach (var spEnt in bucket)
                    {
                        SpriteRendererComponent src = spEnt.Item2;
                        // check if enabled
                        if (!src.Usable)
                        {
                            continue;
                        }
                        TransformComponent trans = spEnt.Item1;

                        // forced z index
                        //if (!ForceZIndex)
                        //else

                        Matrix4x4 matrix = Matrix4x4.CreateScale(new Vector3(src.Size, 1.0f)) * Matrix4x4.CreateTranslation(new Vector3(src.DrawOffset, 0.0f)) * trans.WorldTransformMatrix;

                        //                          small check can be implemented later
                        if (src.TextureAsset == null)
                        {
                            Renderer2D.DrawQuad(matrix, src.Color, spEnt.CommonEntity.UID);
                        }
                        else if (src.TextureAsset.IsLoaded)
                        {
                            Renderer2D.DrawQuad(matrix, src.TextureAsset.Texture, src.Color, src.TextureOffsets, spEnt.CommonEntity.UID);
                        }
                    }
                }

                scene.OnRender(new SpriteRenderEvent());
            }
            Renderer2D.EndScene();
        }
예제 #4
0
 public void FinishShadowMap()
 {
     Renderer2D.DrawQuad(new Vector2(0.0f, 0.0f), new Vector2(100, 100), depthBufferTexture);
 }
예제 #5
0
        override protected void OnRender(Registry registry)
        {
            Renderer2D.BeginScene();

            var staticEntities = registry.GetEntitiesWithComponent <SpriteRenderer>();

            foreach (var entity in staticEntities)
            {
                if (registry.TryGetComponent <TransformComponent>(entity, out var transformComponent))
                {
                    var spriteComp = registry.GetComponent <SpriteRenderer>(entity);
                    Renderer2D.DrawQuad(spriteComp.Texture, transformComponent.GetTransform());
                }
            }

            var animatedEntities = registry.GetEntitiesWithComponent <SpriteAnimator>();

            foreach (var entity in animatedEntities)
            {
                if (registry.TryGetComponent(entity, out TransformComponent transformComponent))
                {
                    var spriteComp = registry.GetComponent <SpriteAnimator>(entity);
                    spriteComp.TimeCache += (float)Application.DeltaTime;
                    float timeBetweenFrames = (1f / spriteComp.FrameRate);
                    if (spriteComp.TimeCache >= timeBetweenFrames)
                    {
                        spriteComp.AddToCurrentFrame((int)(spriteComp.TimeCache / timeBetweenFrames));
                        spriteComp.TimeCache = 0;
                    }
                    Renderer2D.DrawQuad(spriteComp.Texture, spriteComp.TextureOffset, transformComponent.GetTransform());
                }
            }

            foreach (var entity in registry.GetEntitiesWithComponent <ParticleEmitter2D>())
            {
                if (registry.TryGetComponent(entity, out TransformComponent transformComponent))
                {
                    var emitter = registry.GetComponent <ParticleEmitter2D>(entity);
                    if (emitter.IsActive && emitter.HasBeenSet)
                    {
                        for (int i = 0; i < emitter.Length; i++)
                        {
                            Matrix4 particleTransform = Matrix4.Identity;
                            particleTransform *= Matrix4.CreateScale(emitter.Sizes[i].X / Quad.DefaultSize, emitter.Sizes[i].Y / Quad.DefaultSize, 1);
                            particleTransform *= Matrix4.CreateRotationZ(emitter.AnglesAndTorques[i].X);
                            particleTransform *= Matrix4.CreateTranslation(new Vector3(emitter.PositionsAndVelocitys[i].X, emitter.PositionsAndVelocitys[i].Y, 10));
                            Renderer2D.DrawQuad(new Vector4(emitter.Colors[i].R, emitter.Colors[i].G, emitter.Colors[i].B, emitter.Colors[i].A), particleTransform);
                        }
                    }
                }
            }
#if DEBUG
            if ((Renderer2D.DebugFlags & DebugRenderingFlags.DebugRenderers) == DebugRenderingFlags.DebugRenderers)
            {
                var debugEntities = registry.GetEntitiesWithComponent <DebugRenderer>();

                foreach (var entity in debugEntities)
                {
                    if (registry.TryGetComponent <TransformComponent>(entity, out var transformComponent) &&
                        registry.TryGetComponent(entity, out BoxCollider boxCollider))
                    {
                        Matrix4 renderTransform = Matrix4.Identity;
                        renderTransform *= Matrix4.CreateScale(boxCollider.Width / Quad.DefaultSize, boxCollider.Height / Quad.DefaultSize, 1);
                        renderTransform *= Matrix4.CreateFromQuaternion(Quaternion.FromEulerAngles(transformComponent.Rotation));
                        renderTransform *= Matrix4.CreateTranslation(transformComponent.Position);
                        Renderer2D.DrawQuad(registry.GetComponent <DebugRenderer>(entity).Color, renderTransform);
                    }
                }
            }

            if ((Renderer2D.DebugFlags & DebugRenderingFlags.Colliders) == DebugRenderingFlags.Colliders)
            {
                var entities = registry.GetEntitiesWithComponent <RigidBody2D>();
                foreach (var entity in entities)
                {
                    if (registry.TryGetComponent(entity, out TransformComponent transformComponent) &&
                        registry.TryGetComponent(entity, out BoxCollider boxCollider))
                    {
                        var     rigidBody       = registry.GetComponent <RigidBody2D>(entity);
                        Matrix4 renderTransform = Matrix4.Identity;
                        renderTransform *= Matrix4.CreateScale(boxCollider.Width / Quad.DefaultSize, boxCollider.Height / Quad.DefaultSize, 1);
                        renderTransform *= Matrix4.CreateFromQuaternion(Quaternion.FromEulerAngles(transformComponent.Rotation));
                        renderTransform *= Matrix4.CreateTranslation(transformComponent.Position.X, transformComponent.Position.Y, 10);
                        Renderer2D.DrawWireFrameQuad(new Vector4(0, 1, 0, 0.5f), renderTransform);
                    }
                }
            }
#endif
            Renderer2D.EndScene();
        }