Esempio n. 1
0
        public override void Draw()
        {
            float totalMilliseconds = (float)(System.DateTime.Now - new System.DateTime(1970, 1, 1)).TotalMilliseconds;
            float totalSeconds      = (float)(System.DateTime.Now - new System.DateTime(1970, 1, 1)).TotalSeconds;

            surface.Bind();

            // Clear the screen
            //if (Input.Keyboard.Down(KeyCode.Space))
            //	Graphics.Clear(1d);
            //else
            Graphics.Clear(Colour.Black);

            Graphics.State.Reset();
            DepthState.LessEqual.Set();
            CullModeState.Set(cullModeState);
            PolygonModeState.Set(polygonModeState);

            Shaders.Renderer.Bind();
            Shaders.Renderer.MVP = Camera.Matrix;

            Renderer.Draw.ResetTransform();
            Renderer.Draw3D.ResetTransform();

            // Start Drawing
            Renderer.Draw3D.SetTransform(light1Transform);
            Renderer.Draw3D.Cube(light1Colour);
            Renderer.Draw3D.SetTransform(light2Transform);
            Renderer.Draw3D.Cube(light2Colour);
            Renderer.Draw3D.SetTransform(light3Transform);
            Renderer.Draw3D.Cube(light3Colour);
            Renderer.Draw3D.ResetTransform();

            Shaders.PointLightShader.Bind();
            Shaders.PointLightShader.Texture = 0;
            Shaders.PointLightShader.V       = Camera.ViewMatrix;
            Shaders.PointLightShader.P       = Camera.ProjectionMatrix;

            // Directional Light
            //Shaders.CubeShader.DirectionalLight = Vector3.Forward * Matrix.CreateRotationX(0.05f) * Matrix.CreateRotationY(-0.1f);

            // Point Light
            Shaders.PointLightShader.Light1Position = light1Transform.GlobalPosition * Camera.ViewMatrix;
            Shaders.PointLightShader.Light2Position = light2Transform.GlobalPosition * Camera.ViewMatrix;
            Shaders.PointLightShader.Light3Position = light3Transform.GlobalPosition * Camera.ViewMatrix;
            Shaders.PointLightShader.Light1Colour   = light1Colour;
            Shaders.PointLightShader.Light2Colour   = light2Colour;
            Shaders.PointLightShader.Light3Colour   = light3Colour;
            Shaders.PointLightShader.Light1Radius   = 75f;
            Shaders.PointLightShader.Light2Radius   = 75f;
            Shaders.PointLightShader.Light3Radius   = 75f;

            //SpriteSheets.SpriteSheet.Texture.Bind();
            Textures.Hoopoe.Bind();

            Shaders.PointLightShader.M            = cubeTransform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (cubeTransform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            cubeGeometryInput.Bind();
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, cubeIndexBuffer.Count, cubeIndexBuffer.IndexType);

            Shaders.PointLightShader.M            = cube2Transform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (cube2Transform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            cubeGeometryInput.Bind();             // Redundant
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, cubeIndexBuffer.Count, cubeIndexBuffer.IndexType);

            Shaders.PointLightShader.M            = cube3Transform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (cube3Transform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            cubeGeometryInput.Bind();             // Redundant
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, cubeIndexBuffer.Count, cubeIndexBuffer.IndexType);

            Shaders.PointLightShader.M            = icosphereTransform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (icosphereTransform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            icosphereGeometryInput.Bind();
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, icosphereIndexBuffer.Count, icosphereIndexBuffer.IndexType);

            Shaders.PointLightShader.M            = planeTransform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (planeTransform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            planeGeometryInput.Bind();
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, planeIndexBuffer.Count, planeIndexBuffer.IndexType);

            DepthState.Off.Set();
            Shaders.Renderer.Bind();
            //Shaders.Renderer.MVP = Camera.Matrix;
            Shaders.Renderer.MVP = surface.Matrix;
            //Textures.Hoopoe.Bind();
            //Renderer.Draw.Rectangle(40f,
            //						40f,
            //						50f,
            //						50f,
            //						Colour.White,
            //						Colour.White,
            //						Colour.White,
            //						Colour.White,
            //						UV.BottomLeft,
            //						UV.BottomRight,
            //						UV.TopLeft,
            //						UV.TopRight,
            //						-totalSeconds * 0.5f,
            //						new Vector2(65f, 65f));

            Renderer.Draw.Sprite(Sprites.Test1,
                                 new Vector2(1f, 35f),
                                 Vector2.One * 2f,
                                 Colour.White);

            Renderer.Draw.Sprite(Sprites.Test2,
                                 new Vector2(18f, 35f),
                                 Vector2.One * 2f,
                                 Colour.White);

            Renderer.Draw.Sprite(Sprites.Test3,
                                 new Vector2(35f, 35f),
                                 Vector2.One * 2f,
                                 Colour.White);

            //Renderer.Draw.Sprite(Sprites.Hoopoe,
            //					 new Vector2(100f, 20f),
            //					 Vector2.One / Sprites.Hoopoe.MaxLength * 8f * 2f,
            //					 Colour.White);

            //for (int i = 0; i < 1000; i++)
            //{
            //	Renderer.Draw.Sprite(Sprites.Test1,
            //						 new Vector2(40f + i * 0.5f + 100f * Math.Sin((totalMilliseconds + i * 10f) * 0.01f * 0.5f), 20f + i * 0.5f + 100f * Math.Sin((totalMilliseconds + i * 15f) * 0.01f * 0.5f)),
            //						 Vector2.One * 2f,
            //						 Colour.White);
            //}

            Renderer.Draw.Text(SpriteFonts.Font,
                               "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test\nStill testing...\nhhhheeeelllloooo",
                               new Vector2(2, height - 1),
                               Vector2.One * (1f + (Math.SinNormalized(totalSeconds * 2f) * 2f - 0.5f).Clamp(0.001f, 1f)),
                               Colour.White,
                               HAlign.Left,
                               VAlign.Top);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   $"|:shadow=0,-1,0.01,0,0,0,0.5:|Still testing...",
            //				   new Vector2(2, 1),
            //				   Vector2.One * (1f + (Math.SinNormalized(totalSeconds * 2f) * 2f - 0.5f).Clamp(0.001f, 1f)),
            //				   Colour.White,
            //				   HAlign.Left,
            //				   VAlign.Bottom);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test",
            //				   new Vector2(width - 1, 1),
            //				   Vector2.One * (1f + (Math.SinNormalized(totalSeconds * 2f) * 2f - 0.5f).Clamp(0.001f, 1f)),
            //				   Colour.White,
            //				   HAlign.Right,
            //				   VAlign.Bottom);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test\nStill testing...\nhhhheeeelllloooo",
            //				   new Vector2(width - 1, height - 1),
            //				   Vector2.One * (1f + (Math.SinNormalized(totalSeconds * 2f) * 2f - 0.5f).Clamp(0.001f, 1f)),
            //				   Colour.White,
            //				   HAlign.Right,
            //				   VAlign.Top);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:outline=1,0.01,0,0,0,1:|Test Test Test Test Test Test Test Test Test\nStill testing... ... ...",
            //				   new Vector2(width / 2, height / 2),
            //				   Vector2.One * (1f + (Math.SinNormalized(totalSeconds * 2f) * 2f - 0.5f).Clamp(0.001f, 1f)),
            //				   Colour.White,
            //				   HAlign.Center,
            //				   VAlign.Middle);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test\nStill testing...",
            //				   new Vector2(width / 2, height / 2 + 50),
            //				   Vector2.One * (1f + (Math.SinNormalized(totalSeconds * 2f) * 2f - 0.5f).Clamp(0.001f, 1f) * 3f),
            //				   Colour.White,
            //				   HAlign.Center,
            //				   VAlign.Middle);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   "|:shadow=0,-1,0.01,0,0,0,0.5:|Test Test\nStill testing...",
            //				   new Vector2(width / 2, height / 2 - 50),
            //				   Vector2.One * (1f + (Math.SinNormalized(totalSeconds * 2f) * 2f - 0.5f).Clamp(0.001f, 1f) * 2f),
            //				   Colour.White,
            //				   HAlign.Center,
            //				   VAlign.Middle);

            // Spritesheet test
            SpriteSheets.SpriteSheet.Texture.Bind();
            Renderer.Draw.Rectangle(0f,
                                    0f,
                                    SpriteSheets.SpriteSheet.Texture.Width,
                                    SpriteSheets.SpriteSheet.Texture.Height,
                                    Colour.White,
                                    Colour.White,
                                    Colour.White,
                                    Colour.White,
                                    UV.BottomLeft,
                                    UV.BottomRight,
                                    UV.TopLeft,
                                    UV.TopRight);

            // Draw to Screen
            Framebuffer.Default.Bind();
            Graphics.Clear(new Colour(0.1f, 0.1f, 0.1f, 1f));
            Graphics.State.Reset();

            // Render Framebuffer
            Shaders.Renderer.Bind();
            Shaders.Renderer.MVP     = Framebuffer.Default.Matrix;
            Shaders.Renderer.Texture = 0;
            scale = Math.Max(1, Math.Min(Window.Width / width, Window.Height / height));
            Renderer.Draw.Framebuffer(surface, TextureAttachment.Colour0, (Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, scale, Colour.White);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   debugString,
            //				   new Vector2(2, Framebuffer.Current.Height - 1),
            //				   Vector2.One * 3f,
            //				   Colour.White,
            //				   HAlign.Left,
            //				   VAlign.Top);

            Renderer.Flush();
        }
Esempio n. 2
0
        public override void Draw()
        {
            surface.Bind();

            // Clear the screen
            if (Input.Keyboard.Down(KeyCode.Space))
            {
                Graphics.Clear(1d);
            }
            else
            {
                Graphics.Clear(Colour.Black);
            }

            Graphics.State.Reset();
            DepthState.LessEqual.Set();
            CullModeState.Set(cullModeState);
            PolygonModeState.Set(polygonModeState);

            Shaders.Renderer.Bind();
            Shaders.Renderer.MVP = Camera.Matrix;

            Renderer.Draw.ResetTransform();
            Renderer.Draw3D.ResetTransform();

            // Start Drawing
            Renderer.Draw3D.SetTransform(light1Transform);
            Renderer.Draw3D.Cube(light1Colour);
            Renderer.Draw3D.SetTransform(light2Transform);
            Renderer.Draw3D.Cube(light2Colour);
            Renderer.Draw3D.SetTransform(light3Transform);
            Renderer.Draw3D.Cube(light3Colour);
            Renderer.Draw3D.ResetTransform();

            Shaders.PointLightShader.Bind();

            Shaders.PointLightShader.V = Camera.ViewMatrix;
            Shaders.PointLightShader.P = Camera.ProjectionMatrix;

            // Directional Light
            //Shaders.CubeShader.DirectionalLight = Vector3.Forward * Matrix.CreateRotationX(0.05f) * Matrix.CreateRotationY(-0.1f);

            // Point Light
            Shaders.PointLightShader.Light1Position = light1Transform.GlobalPosition * Camera.ViewMatrix;
            Shaders.PointLightShader.Light2Position = light2Transform.GlobalPosition * Camera.ViewMatrix;
            Shaders.PointLightShader.Light3Position = light3Transform.GlobalPosition * Camera.ViewMatrix;
            Shaders.PointLightShader.Light1Colour   = light1Colour;
            Shaders.PointLightShader.Light2Colour   = light2Colour;
            Shaders.PointLightShader.Light3Colour   = light3Colour;
            Shaders.PointLightShader.Light1Radius   = 75f;
            Shaders.PointLightShader.Light2Radius   = 75f;
            Shaders.PointLightShader.Light3Radius   = 75f;

            Shaders.PointLightShader.M            = cubeTransform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (cubeTransform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            cubeGeometryInput.Bind();
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, cubeIndexBuffer.Count, cubeIndexBuffer.IndexType);

            Shaders.PointLightShader.M            = cube2Transform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (cube2Transform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            cubeGeometryInput.Bind();             // Redundant
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, cubeIndexBuffer.Count, cubeIndexBuffer.IndexType);

            Shaders.PointLightShader.M            = cube3Transform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (cube3Transform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            cubeGeometryInput.Bind();             // Redundant
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, cubeIndexBuffer.Count, cubeIndexBuffer.IndexType);

            Shaders.PointLightShader.M            = icosphereTransform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (icosphereTransform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            icosphereGeometryInput.Bind();
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, icosphereIndexBuffer.Count, icosphereIndexBuffer.IndexType);

            Shaders.PointLightShader.M            = planeTransform.Matrix;
            Shaders.PointLightShader.NormalMatrix = (planeTransform.Matrix * Camera.ViewMatrix).ToMatrix3x3().Inverse().Transpose();
            planeGeometryInput.Bind();
            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, planeIndexBuffer.Count, planeIndexBuffer.IndexType);

            // Draw to Screen
            Framebuffer.Default.Bind();
            Graphics.Clear(new Colour(0.1f, 0.1f, 0.1f, 1f));
            Graphics.State.Reset();

            // Render Framebuffer
            Shaders.Renderer.Bind();
            Shaders.Renderer.MVP = Framebuffer.Default.Matrix;
            scale = Math.Max(1, Math.Min(Window.Width / width, Window.Height / height));
            Renderer.Draw.Framebuffer(surface, TextureAttachment.Colour0, (Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, scale, Colour.White);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   debugString,
            //				   new Vector2(2, Framebuffer.Current.Height - 1),
            //				   Vector2.One * 3f,
            //				   Colour.White,
            //				   HAlign.Left,
            //				   VAlign.Top);

            Renderer.Flush();

            // Screenshot
            if (Input.Keyboard.Pressed(KeyCode.F9))
            {
                string s = "./screenshots/";
                if (!System.IO.Directory.Exists(s))
                {
                    Directory.CreateDirectory(s);
                }

                int sequentialNumber = 1;
                while (System.IO.File.Exists($@"{s}{System.DateTime.Now:yyyy-MM-dd HH.mm.ss}-{sequentialNumber} [CKGL].png"))
                {
                    sequentialNumber++;
                }

                surface.SavePNG($@"{s}{System.DateTime.Now:yyyy-MM-dd HH.mm.ss}-{sequentialNumber} [CKGL].png");

                //System.GC.Collect();
            }
        }
Esempio n. 3
0
        public override void Draw()
        {
            surface.Bind();

            //Graphics.SetViewport(0, 0, Window.Width, Window.Height);
            //Graphics.SetScissorTest(0, 0, Window.Width, Window.Height);
            //Graphics.Clear(new Colour(0.1f, 0.1f, 0.1f, 1f));

            //// Pixel Perfect Scaling
            //int scale = Math.Max(1, Math.Min(Window.Width / width, Window.Height / height));
            //Graphics.SetViewport((Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, width * scale, height * scale);
            //Graphics.SetScissorTest((Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, width * scale, height * scale);

            //// Dynamic Viewport - Maintain Aspect Ratio
            //float aspectRatio = 16f / 9f;
            //if (Window.Width <= Window.Height * aspectRatio)
            //{
            //	width = Window.Width;
            //	height = Math.FloorToInt(Window.Width / aspectRatio);
            //}
            //else
            //{
            //	width = Math.FloorToInt(Window.Height * aspectRatio);
            //	height = Window.Height;
            //}
            //Graphics.SetViewport((Window.Width - width) / 2, (Window.Height - height) / 2, width, height);
            //Graphics.SetScissorTest((Window.Width - width) / 2, (Window.Height - height) / 2, width, height);

            // Dynamic Viewport
            //width = Window.Width;
            //height = Window.Height;
            //Camera.AspectRatio = Window.AspectRatio;
            //int scale = Math.Max(1, Math.Min(Window.Width / width, Window.Height / height));
            //Graphics.SetViewport((Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, width * scale, height * scale);
            //Graphics.SetScissorTest((Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, width * scale, height * scale);

            // Clear the screen
            Graphics.Clear(Colour.Black);

            geometryInput.Bind();

            Shaders.Basic.Bind();

            Graphics.DrawIndexedVertexArrays(PrimitiveTopology.TriangleList, 0, vertexData.Length, geometryInput.IndexBuffer.IndexType);

            Renderer.Draw.SetTransform(new Transform2D());             // Workaround - Bridge fails the null coalescing in Renderer.Draw.AddVertex

            //Draw to Screen
            Framebuffer.Default.Bind();
            Graphics.Clear(new Colour(0.1f, 0.1f, 0.1f, 1f));
            Graphics.State.Reset();

            // Render Framebuffer
            Shaders.Renderer.Bind();
            Shaders.Renderer.MVP     = Framebuffer.Default.Matrix;
            Shaders.Renderer.Texture = 0;
            scale = Math.Max(1, Math.Min(Window.Width / width, Window.Height / height));
            Renderer.Draw.Framebuffer(surface, TextureAttachment.Colour0, (Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, scale, Colour.White);

            //Renderer.Draw.Text(SpriteFonts.Font,
            //				   debugString,
            //				   new Vector2(2, Framebuffer.Current.Height - 1),
            //				   Vector2.One * 3f,
            //				   Colour.White,
            //				   HAlign.Left,
            //				   VAlign.Top);

            Renderer.Flush();

            Renderer.Draw.ResetTransform();             // Workaround - See above
        }