public static void Set(CullModeState cullModeState) { if (Current != cullModeState) { Graphics.State.OnStateChanging?.Invoke(); Graphics.SetCullMode(cullModeState); Current = cullModeState; Graphics.State.OnStateChanged?.Invoke(); } }
internal override void SetCullMode(CullModeState cullModeState) { if (cullModeState.Enabled) { GL.enable(CULL_FACE); } else { GL.disable(CULL_FACE); } GL.cullFace(cullModeState.Face.ToWebGL2()); }
internal override void SetCullMode(CullModeState cullModeState) { if (cullModeState.Enabled) { GL.Enable(EnableCap.CullFace); } else { GL.Disable(EnableCap.CullFace); } GL.CullFace(cullModeState.Face.ToOpenGL()); }
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.Cube(Colour.Green); // 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 (!Directory.Exists(s)) { Directory.CreateDirectory(s); } int sequentialNumber = 1; while (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(); } }
public override void Update() { if (Input.Keyboard.Down(KeyCode.Backspace) || Input.Controllers.First.SelectDown) { Platform.Quit(); } if (Input.Keyboard.Pressed(KeyCode.F11)) { Window.Fullscreen = !Window.Fullscreen; } if (Input.Keyboard.Pressed(KeyCode.F10)) { Window.Borderless = !Window.Borderless; } if (Input.Keyboard.Pressed(KeyCode.F8)) { Window.Resizable = !Window.Resizable; } if (Input.Keyboard.Pressed(KeyCode.F7)) { Window.VSync = !Window.VSync; } if (Input.Keyboard.Pressed(KeyCode.Escape)) { Platform.RelativeMouseMode = !Platform.RelativeMouseMode; } if (Input.Keyboard.Pressed(KeyCode.F2)) { if (polygonModeState == PolygonModeState.Fill) { polygonModeState = PolygonModeState.Line; } else if (polygonModeState == PolygonModeState.Line) { polygonModeState = PolygonModeState.Point; } else if (polygonModeState == PolygonModeState.Point) { polygonModeState = PolygonModeState.Fill; } } if (Input.Keyboard.Pressed(KeyCode.F3)) { if (cullModeState == CullModeState.Off) { cullModeState = CullModeState.Back; } else if (cullModeState == CullModeState.Back) { cullModeState = CullModeState.Front; } else if (cullModeState == CullModeState.Front) { cullModeState = CullModeState.FrontAndBack; } else if (cullModeState == CullModeState.FrontAndBack) { cullModeState = CullModeState.Off; } } if (!Platform.RelativeMouseMode) { if (Input.Mouse.LeftPressed) { windowDraggingPosition = Input.Mouse.LastPosition; } else if (Input.Mouse.LeftDown) { Window.Position = Input.Mouse.PositionDisplay - windowDraggingPosition; } } float speed = 10f; if (Input.Keyboard.Down(KeyCode.Z) || Input.Controllers.First.L2Down) { Camera2D.Rotation += 0.01f; } if (Input.Keyboard.Down(KeyCode.C) || Input.Controllers.First.R2Down) { Camera2D.Rotation -= 0.01f; } if ((Input.Keyboard.Down(KeyCode.Z) && Input.Keyboard.Down(KeyCode.C)) || (Input.Controllers.First.L2Down && Input.Controllers.First.R2Down)) { Camera2D.Rotation = 0f; } Vector3 direction = Vector3.Zero; if (Input.Keyboard.Down(KeyCode.A) || Input.Controllers.First.LeftStickDigitalLeftDown || Input.Controllers.First.LeftDown) { direction += Vector3.Cross(cameraLookatNoVertical, Vector3.Up).Normalized; } if (Input.Keyboard.Down(KeyCode.D) || Input.Controllers.First.LeftStickDigitalRightDown || Input.Controllers.First.RightDown) { direction += Vector3.Cross(Vector3.Up, cameraLookatNoVertical).Normalized; } if (Input.Keyboard.Down(KeyCode.W) || Input.Controllers.First.LeftStickDigitalUpDown || Input.Controllers.First.UpDown) { direction += cameraLookatNoVertical; } if (Input.Keyboard.Down(KeyCode.S) || Input.Controllers.First.LeftStickDigitalDownDown || Input.Controllers.First.DownDown) { direction -= cameraLookatNoVertical; } if (Input.Keyboard.Down(KeyCode.Q) || Input.Controllers.First.L1Down) { direction += Vector3.Down; } if (Input.Keyboard.Down(KeyCode.E) || Input.Controllers.First.R1Down) { direction += Vector3.Up; } if (Input.Mouse.ScrollY != 0) { Camera.FoV -= Input.Mouse.ScrollY; } Camera.Position += direction.Normalized * speed * Time.DeltaTime; // Mouse look if (Platform.RelativeMouseMode) { float mouseSpeed = 0.0005f; cameraYaw = Math.Clamp(cameraYaw + (Input.Mouse.PositionRelative.Y) * mouseSpeed, -0.249f, 0.249f); cameraPitch += (Input.Mouse.PositionRelative.X) * mouseSpeed; } // Controller look float controllerSpeed = 0.01f; cameraYaw = Math.Clamp(cameraYaw + (-Input.Controllers.First.RightStickY * controllerSpeed), -0.249f, 0.249f); cameraPitch += Input.Controllers.First.RightStickX * controllerSpeed; //Camera.Rotation = Quaternion.CreateLookAt(cameraLookat, Vector3.Up); Camera.Rotation = Quaternion.CreateRotationY(cameraPitch) * Quaternion.CreateRotationX(cameraYaw); cameraLookat = Vector3.Forward * Camera.Rotation; cameraLookatNoVertical = new Vector3(cameraLookat.X, 0f, cameraLookat.Z).Normalized; debugString = $"|:outline=1,0.01,0,0,0,1:|Cam Pos: {Camera.Position.X:n1}, {Camera.Position.Y:n1}, {Camera.Position.Z:n1}\nCam Rot: {Camera.Rotation.Euler.X:n2}, {Camera.Rotation.Euler.Y:n2}, {Camera.Rotation.Euler.Z:n2}\nMem: {Engine.RAM:n1}MB\nVSync: {Window.GetVSyncMode()}\n{Time.UPS:n0}ups | {Time.FPSSmoothed:n0}fps\nDraw Calls: {Graphics.DrawCalls}\nState Changes: {Graphics.State.Changes}\nFramebuffer Swaps/Blits: {Framebuffer.Swaps}/{Framebuffer.Blits}\nTexture Swaps: {Texture.Swaps}\nShader/Uniform Swaps: {Shader.Swaps}/{Shader.UniformSwaps}\nWinPos: [{Window.X}, {Window.Y}]\nSize: [{Window.Size}]\nMouse Global: [{Input.Mouse.PositionDisplay}]\nMouse: [{Input.Mouse.Position}]\nMouse Relative: [{Input.Mouse.PositionRelative}]"; }
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(); } }
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(); }
public bool Equals(CullModeState cullModeState) { return(this == cullModeState); }
public static void SetDefault(CullModeState cullModeState) => Default = cullModeState;
internal abstract void SetCullMode(CullModeState cullModeState);
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(); CullModeState.Set(cullModeState); DepthState.LessEqual.Set(); PolygonModeState.Set(polygonModeState); if (Input.Mouse.RightDown) { Shaders.RendererFog.Bind(); Shaders.RendererFog.MVP = Camera.Matrix; Shaders.RendererFog.MV = Camera.ViewMatrix; Shaders.RendererFog.FogType = InternalShaders.FogType.Linear; //Shaders.RendererFog.FogDensity = 0.013f; Shaders.RendererFog.FogColour = Colour.Black; Shaders.RendererFog.FogStart = Camera.zNear; Shaders.RendererFog.FogEnd = Camera.zFar; } else { Shaders.Renderer.Bind(); Shaders.Renderer.MVP = Camera.Matrix; } Renderer.Draw.ResetTransform(); Renderer.Draw3D.ResetTransform(); // Start Drawing Renderer.Draw3D.SetTransform(test); Renderer.Draw3D.Cube(Colour.Cyan, Colour.Yellow, Colour.Red, Colour.Blue, Colour.Green, Colour.Magenta); Renderer.Draw3D.ResetTransform(); Renderer.Draw3D.SetTransform(test2); Colour c2 = new Colour(Math.CosNormalized(Time.TotalSeconds * 1.5f), Math.CosNormalized(Time.TotalSeconds * 1.4f), Math.CosNormalized(Time.TotalSeconds * 1.3f), 1f); Renderer.Draw3D.CubeWireframe(c2); Renderer.Draw3D.ResetTransform(); Renderer.Draw3D.SetTransform(test3); Renderer.Draw3D.Cube(new Colour(0f, 0f, 0f, 1f), new Colour(1f, 0f, 0f, 1f), new Colour(0f, 1f, 0f, 1f), new Colour(1f, 1f, 0f, 1f), new Colour(0f, 0f, 1f, 1f), new Colour(1f, 0f, 1f, 1f), new Colour(0f, 1f, 1f, 1f), new Colour(1f, 1f, 1f, 1f)); Renderer.Draw3D.ResetTransform(); Transform cubeGridTransformParent = new Transform(); cubeGridTransformParent.Position = new Vector3(80, 0, 80); for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { for (int z = 0; z < 5; z++) { Transform cubeGridTransform = new Transform(); cubeGridTransform.Parent = cubeGridTransformParent; cubeGridTransform.Position = new Vector3(x * 6, y * 6, z * 6); cubeGridTransform.Rotation = Quaternion.CreateFromEuler(new Vector3(-Time.TotalSeconds * 0.3f * x, -Time.TotalSeconds * 0.25f * y, -Time.TotalSeconds * 0.09f * z)); cubeGridTransform.Shear = new Shear3D(Math.Sin(y * Time.TotalSeconds * 1.7f) * 0.2f, z * Math.Sin(Time.TotalSeconds * 1.9f) * 0.4f, Math.Sin(x * Time.TotalSeconds * 1.8f) * 0.3f, z * Math.Sin(Time.TotalSeconds * 1.8f) * 0.3f, Math.Sin(x * Time.TotalSeconds * 1.9f) * 0.4f, y * Math.Sin(Time.TotalSeconds * 1.7f) * 0.2f); Renderer.Draw3D.SetTransform(cubeGridTransform); //Renderer.Draw3D.CubeLines(new Colour(Math.SinNormalized(x + Time.TotalSeconds * 1.5f), Math.SinNormalized(y + Time.TotalSeconds * 1.4f), Math.SinNormalized(z + Time.TotalSeconds * 1.3f), 1f)); Renderer.Draw3D.Cube(Colour.Cyan, Colour.Yellow, Colour.Red, Colour.Blue, Colour.Green, Colour.Magenta); //Renderer.Draw3D.Cube(new Colour(0f, 0f, 0f, 1f), // new Colour(1f, 0f, 0f, 1f), // new Colour(0f, 1f, 0f, 1f), // new Colour(1f, 1f, 0f, 1f), // new Colour(0f, 0f, 1f, 1f), // new Colour(1f, 0f, 1f, 1f), // new Colour(0f, 1f, 1f, 1f), // new Colour(1f, 1f, 1f, 1f)); } } } Renderer.Draw3D.ResetTransform(); Transform2D t2D = new Transform2D(); //t2D.Rotation = Math.Sin(Time.TotalSeconds) * 0.03f; t2D.ShearX = Math.Sin(Time.TotalSeconds) * 0.4f; t2D.ShearY = Math.Sin(Time.TotalSeconds * 0.7f) * 0.5f; Renderer.Draw.SetTransform(t2D); Transform t = new Transform(); //t.Rotation = Quaternion.CreateRotationZ(Math.Sin(Time.TotalSeconds) * 0.01f); //t.Shear = new Shear3D(0, 0, Math.Sin(Time.TotalSeconds * 0.7f) * 0.5f, Math.Cos(Time.TotalSeconds * 0.7f) * 0.5f, 0, 0); Renderer.Draw3D.SetTransform(t); Colour gridColour = new Colour(0.1f, 0.1f, 0.1f, 1f); int length = 100; //for (int yy = -length; yy <= length; yy++) //for (int yy = 0; yy <= 0; yy++) //{ //float yy = cameraPosition.Y - 2f; float yy = -5f; for (int i = 0; i <= length; i++) { Renderer.Draw3D.Line(new Vector3(-length, yy, i), new Vector3(length, yy, i), gridColour); if (i != 0) { Renderer.Draw3D.Line(new Vector3(-length, yy, -i), new Vector3(length, yy, -i), gridColour); } Renderer.Draw3D.Line(new Vector3(i, yy, -length), new Vector3(i, yy, length), gridColour); if (i != 0) { Renderer.Draw3D.Line(new Vector3(-i, yy, -length), new Vector3(-i, yy, length), gridColour); } } Renderer.Draw3D.Line(new Vector3(-length, yy, -length), new Vector3(-length, yy + length, -length), gridColour); Renderer.Draw3D.Line(new Vector3(length, yy, -length), new Vector3(length, yy + length, -length), gridColour); Renderer.Draw3D.Line(new Vector3(-length, yy, length), new Vector3(-length, yy + length, length), gridColour); Renderer.Draw3D.Line(new Vector3(length, yy, length), new Vector3(length, yy + length, length), gridColour); //} //for (int y = -length; y <= length; y++) //{ // for (int x = -length; x <= length; x++) // { // for (int z = -length; z <= length; z++) // { // Renderer.Draw.Points.Point(new Vector3(x, y, z), gridColour); // } // } //} Renderer.Draw.Triangle(new Vector2(0f, 1f), new Vector2(0f, 1f) * Matrix2D.CreateRotationZ(Rotation.Third), new Vector2(0f, 1f) * Matrix2D.CreateRotationZ(Rotation.TwoThirds), Colour.Red, Colour.Green, Colour.Blue, null, null, null, -Time.TotalSeconds * 0.5f, Vector2.Zero); // Right Renderer.Draw3D.Triangle(new Vector3(20f, 10f, 0f), new Vector3(20f, 10f, 0f) * Quaternion.CreateRotationX(Rotation.Third), new Vector3(20f, 10f, 0f) * Quaternion.CreateRotationX(Rotation.TwoThirds), Colour.Red, Colour.Green, Colour.Blue); Renderer.Draw3D.Triangle(new Vector3(50f, 50f, 0f), new Vector3(50f, 50f, 0f) * Quaternion.CreateRotationX(Rotation.Third), new Vector3(50f, 50f, 0f) * Quaternion.CreateRotationX(Rotation.TwoThirds), Colour.Red, Colour.Green, Colour.Blue); // Left Renderer.Draw3D.Triangle(new Vector3(-20f, 10f, 0f), new Vector3(-20f, 10f, 0f) * Quaternion.CreateRotationX(Rotation.TwoThirds), new Vector3(-20f, 10f, 0f) * Quaternion.CreateRotationX(Rotation.Third), Colour.Red, Colour.Green, Colour.Blue); Renderer.Draw3D.Triangle(new Vector3(-50f, 50f, 0f), new Vector3(-50f, 50f, 0f) * Quaternion.CreateFromAxisAngle(Vector3.Left, Rotation.Third), new Vector3(-50f, 50f, 0f) * Quaternion.CreateFromAxisAngle(Vector3.Left, Rotation.TwoThirds), Colour.Red, Colour.Green, Colour.Blue); // Forward //Renderer.Draw3D.Triangle(new Vector3(0f, 2f, 10f), // new Vector3(0f, 2f, 10f) * Quaternion.CreateRotationZ(Rotation.Third), // new Vector3(0f, 2f, 10f) * Quaternion.CreateRotationZ(Rotation.TwoThirds), // Colour.Red, // Colour.Green, // Colour.Blue); //Renderer.Draw3D.Triangle(new Vector3(0f, 10f, 20f), // new Vector3(0f, 10f, 20f) * Quaternion.CreateRotationZ(Rotation.Third), // new Vector3(0f, 10f, 20f) * Quaternion.CreateRotationZ(Rotation.TwoThirds), // Colour.Red, // Colour.Green, // Colour.Blue); //Renderer.Draw3D.Triangle(new Vector3(0f, 50f, 50f), // new Vector3(0f, 50f, 50f) * Quaternion.CreateRotationZ(Rotation.Third).Matrix, // new Vector3(0f, 50f, 50f) * Quaternion.CreateRotationZ(Rotation.TwoThirds).Matrix, // Colour.Red, // Colour.Green, // Colour.Blue); for (int i = 0; i < 500; i += 5) { Renderer.Draw3D.Triangle(new Vector3(0f, i * 0.2f, i * 0.5f) * Quaternion.CreateRotationZ(Rotation.Zero + i * 0.001f - Time.TotalSeconds * 0.1f), new Vector3(0f, i * 0.2f, i * 0.5f) * Quaternion.CreateRotationZ(Rotation.Third + i * 0.001f - Time.TotalSeconds * 0.1f), new Vector3(0f, i * 0.2f, i * 0.5f) * Quaternion.CreateRotationZ(Rotation.TwoThirds + i * 0.001f - Time.TotalSeconds * 0.1f), Colour.Red, Colour.Green, Colour.Blue); } // Backward Renderer.Draw3D.Triangle(new Vector3(0f, 10f, -20f), new Vector3(0f, 10f, -20f) * Quaternion.CreateRotationZ(Rotation.TwoThirds), new Vector3(0f, 10f, -20f) * Quaternion.CreateRotationZ(Rotation.Third), Colour.Red, Colour.Green, Colour.Blue); Renderer.Draw3D.Triangle(new Vector3(0f, 50f, -50f), new Vector3(0f, 50f, -50f) * Quaternion.CreateFromAxisAngle(Vector3.Backward, Rotation.Third), new Vector3(0f, 50f, -50f) * Quaternion.CreateFromAxisAngle(Vector3.Backward, Rotation.TwoThirds), Colour.Red, Colour.Green, Colour.Blue); // Up Renderer.Draw3D.Triangle(new Vector3(0f, 20f, -10f), new Vector3(0f, 20f, -10f) * Quaternion.CreateRotationY(Rotation.Third), new Vector3(0f, 20f, -10f) * Quaternion.CreateRotationY(Rotation.TwoThirds), Colour.Red, Colour.Green, Colour.Blue); Renderer.Draw3D.Triangle(new Vector3(0f, 50f, -50f), new Vector3(0f, 50f, -50f) * Quaternion.CreateRotationY(Rotation.Third), new Vector3(0f, 50f, -50f) * Quaternion.CreateRotationY(Rotation.TwoThirds), Colour.Red, Colour.Green, Colour.Blue); // Down Renderer.Draw3D.Triangle(new Vector3(0f, -20f, -10f), new Vector3(0f, -20f, -10f) * Quaternion.CreateRotationY(Rotation.TwoThirds), new Vector3(0f, -20f, -10f) * Quaternion.CreateRotationY(Rotation.Third), Colour.Red, Colour.Green, Colour.Blue); Renderer.Draw3D.Triangle(new Vector3(0f, -50f, -50f), new Vector3(0f, -50f, -50f) * Quaternion.CreateFromAxisAngle(Vector3.Down, Rotation.Third), new Vector3(0f, -50f, -50f) * Quaternion.CreateFromAxisAngle(Vector3.Down, Rotation.TwoThirds), Colour.Red, Colour.Green, Colour.Blue); DepthMaskState.Disabled.Set(); Textures.Test.Bind(); Renderer.Draw.Rectangle(2f, -0.5f, 1f, 1f, Colour.White, Colour.White, Colour.White, Colour.White, UV.BottomLeft, UV.BottomRight, UV.TopLeft, UV.TopRight, -Time.TotalSeconds * 0.5f, new Vector2(2.5f, 0f)); Renderer.Draw.Sprite(Sprites.Test1, new Vector2(4f, -0.5f), Vector2.One / Sprites.Test1.MaxLength, Colour.White); Renderer.Draw.Sprite(Sprites.Test2, new Vector2(6f, -0.5f), Vector2.One / Sprites.Test2.MaxLength, Colour.White); Renderer.Draw.Sprite(Sprites.Test3, new Vector2(8f, -0.5f), Vector2.One / Sprites.Test3.MaxLength, Colour.White); Renderer.Draw.Text(SpriteFonts.Font, "|:shadow=0,-1,0.01,0,0,0,0.5:|ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n1234567890\n_-+=(){}[]<>\\|/;:'\"?.,!@#$%^&*~`", new Vector2(0f, 4f), Vector2.One / 7f, Colour.White, HAlign.Center, VAlign.Middle); DepthMaskState.Reset(); Renderer.Draw.ResetTransform(); // Test Geometry Shader //Shaders.GeometryTest.Bind(); //Shaders.GeometryTest.MVP = Camera.Matrix; //for (int x = 0; x < 20; x++) //{ // for (int y = 0; y < 20; y++) // { // Renderer.Draw3D.Point(x * 1.1f, y * 1.1f, 0f, Colour.Red); // } //} // NoiseShader Test Shaders.Noise.Bind(); Shaders.Noise.MVP = Camera.Matrix; Shaders.Noise.Time = Time.TotalSeconds; Renderer.Draw3D.Rectangle(new Vector3(-10f, -5f, -1f), new Vector3(10f, -5f, -1f), new Vector3(-10f, 5f, -1f), new Vector3(10f, 5f, -1f), Colour.White, //UV.BottomLeft, //UV.BottomRight, //UV.TopLeft, //UV.TopRight new Vector2(-1, -0.75f), new Vector2(1, -0.75f), new Vector2(-1, 0.75f), new Vector2(1, 0.75f) ); // GUI Layer DepthState.Off.Set(); Scene.Current?.Draw(); Camera2D.Width = Framebuffer.Current.Width; Camera2D.Height = Framebuffer.Current.Height; Shaders.Renderer.Bind(); Shaders.Renderer.MVP = Camera2D.Matrix; //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(Time.TotalSeconds * 2f).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:|{Camera.Rotation}\nStill testing...", // new Vector2(2, 1), // Vector2.One * (1f + Math.SinNormalized(Time.TotalSeconds * 2f).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(Time.TotalSeconds * 2f).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(Time.TotalSeconds * 2f).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(Time.TotalSeconds * 2f).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(Time.TotalSeconds * 2f).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(Time.TotalSeconds * 2f).Clamp(0.001f, 1f) * 2f), // Colour.White, // HAlign.Center, // VAlign.Middle); //Renderer.Draw.TriangleListStrip.Begin(); ////int ii = Random.Range(1000, 10000); //for (int i = 0; i < 10000; i++) // Renderer.Draw.TriangleListStrip.AddVertex(new Vector3(Random.Range(-100f, 100f), Random.Range(-100f, 100f), 0.0f), // new Colour(Random.Range(1f), Random.Range(1f), Random.Range(1f), Random.Range(1f))); //Renderer.Draw.TriangleListStrip.End(); // TODO - LineListStrip //Renderer.Draw.LineListStrip.Begin(); //for (int i = 0; i < 10; i++) // Renderer.Draw.LineListStrip.AddVertex(new Vector3(Random.Range(-6f, -2f), Random.Range(-2f, 2f), 0.0f), // new Colour(Random.Range(1f), Random.Range(1f), Random.Range(1f), Random.Range(1f))); //Renderer.Draw.LineListStrip.End(); //Renderer.Draw.Circle(new Vector2(0f, -8f), 10f, Colour.Green, Colour.Green.Alpha(0.1f), (int)Math.Lerp(8f, 64f, Math.SinNormalized(Time.TotalSeconds))); //for (int i = 0; i < 10000; i++) // Renderer.Draw.PolyPoint(new Vector2(Random.Range(0, width), Random.Range(0, height)), // new Colour(Random.Range(1f), Random.Range(1f), Random.Range(1f), 1f)); //Framebuffer.Bind(null); //Renderer.Draw.Framebuffer(surface, 0, // -5f, 5f, 0.1f, // Colour.White); //Renderer.Draw.Text(SpriteFonts.Font, // debugString, // new Vector2(2, Framebuffer.Current.Height - 1), // Vector2.One, // Colour.White, // HAlign.Left, // VAlign.Top); // Draw Depth Buffer if (Input.Keyboard.Down(KeyCode.F1)) { Graphics.State.Reset(); Shaders.LinearizeDepth.Bind(); Shaders.LinearizeDepth.MVP = surface.Matrix; Shaders.LinearizeDepth.zNear = Camera.zNear; Shaders.LinearizeDepth.zFar = Camera.zFar; Renderer.Draw.Framebuffer(surface, TextureAttachment.Depth, 0, 0, Colour.White); Shaders.Renderer.Bind(); Shaders.Renderer.MVP = Framebuffer.Default.Matrix; } // Draw to Screen Framebuffer.Default.Bind(); Graphics.Clear(new Colour(0.1f, 0.1f, 0.1f, 1f)); Graphics.State.Reset(); scale = Math.Max(1, Math.Min(Window.Width / width, Window.Height / height)); // Render Framebuffer Shaders.Renderer.Bind(); Shaders.Renderer.MVP = Framebuffer.Default.Matrix; Renderer.Draw.Framebuffer(surface, TextureAttachment.Colour0, (Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, scale, Colour.White); //Renderer.Draw.Framebuffer(surface, TextureAttachment.Colour0, (Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, scale, Math.Sin(Time.TotalSeconds) * 0.03f, new Vector2(Window.Width / 2f, Window.Height / 2f), Colour.White); // Blit Framebuffer //surface.BlitTextureTo(Framebuffer.Default, TextureAttachment.Colour0, BlitFilter.Nearest, new RectangleI((Window.Width - width * scale) / 2, (Window.Height - height * scale) / 2, width * scale, height * scale)); 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 = "X:/Dropbox/Clint/Gamedev/2018-03-22 CKGL/screenshots/"; if (!System.IO.Directory.Exists(s)) { s = "C:/Users/Clint Kilmer/Dropbox/Clint/Gamedev/2018-03-22 CKGL/screenshots/"; } 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(); } }