public void OnUpdate(TimeStep ts) { manager.OnUpdate(); RenderingAPI.SetClearColor(0, 0, 0); RenderingAPI.Clear(); }
public void OnUpdate(TimeStep ts) { cameraController.OnUpdate(ts); //Render RenderingAPI.SetClearColor(0.2f, 0.2f, 0.2f); RenderingAPI.Clear(); Renderer.BeginScene(cameraController.GetCamera()); { //Square for (int y = 0; y < 10; y++) { for (int x = 0; x < 10; x++) { Vector3 pos = new Vector3(x * 1.1f, y * 1.1f, 0); Matrix4x4 transform = Matrix4x4.CreateTranslation(pos) * Scale; Renderer.Submit(shaderLibrary.GetShader("Square"), squareVertexArray, transform); } } birdiTexture.Bind(); Renderer.Submit(shaderLibrary.GetShader("Texture"), squareVertexArray, Matrix4x4.Identity); faceTexture.Bind(); Renderer.Submit(shaderLibrary.GetShader("Texture"), squareVertexArray, Matrix4x4.Identity); } Renderer.EndScene(); }
private void WindowResize(WindowResizedEvent e) { if (e.Width == 0 || e.Height == 0) { minimized = true; return; } minimized = false; RenderingAPI.OnWindowResize((uint)e.Width, (uint)e.Height); }
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(); }); } }); }
/// <summary> /// Init, and runs the game /// </summary> /// <param name="entry"></param> /// <param name="noWindow"></param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="NullReferenceException"></exception> public static void Init(IEntryPoint entry, bool noWindow = false) { //Make sure the entry isn't null, or that there is no game name if (entry == null) { throw new ArgumentNullException(nameof(entry), "Entry cannot be null!"); } if (string.IsNullOrWhiteSpace(entry.GetGameName())) { throw new NullReferenceException("Game name cannot be null!"); } //Initiate the logger first Logger.Init(); Profiler.BeginSession("Startup", "VoltstroEngineProfile-Startup.json"); Application app = null; ProfilerTimer.Profile(() => { //Setup render RenderingAPI.Create(); //Set game name, since we load all our game related files from that path //So if the game requests for a texture, we load it from the game's bin parent directory, allowing for multiple games, but all using the same copy of the engine //E.G: // - Engine Stuff (Launcher/VoltstroEngine.dll) // - | // - Sandbox // - - Textures/ GameName = entry.GetGameName(); if (!noWindow) { //Init our forms system EtoFormsSystem.Init(); //Create the app Logger.Info("Creating {@GameName}'s application...", GameName); app = entry.CreateApplication(); if (app == null) { throw new NullReferenceException("The app cannot be null!"); } //Init the render Renderer.Init(); } else { //Init the render Renderer.Init(); } }); Profiler.EndSession(); //Run the main loop if (!noWindow) { Profiler.BeginSession("Runtime", "VoltstroEngineProfile-Runtime.json"); { ProfilerTimer.Profile("Game Loop", () => { app.Run(); }); } Profiler.EndSession(); } //Shutdown stuff Profiler.BeginSession("Shutdown", "VoltstroEngineProfile-Shutdown.json"); { ProfilerTimer.Profile("Shutdown", () => { Application.Shutdown(); Renderer.Shutdown(); EtoFormsSystem.Shutdown(); }); Logger.Shutdown(); } Profiler.EndSession(); }
private void Init(WindowProperties properties) { ProfilerTimer.Profile(() => { Logger.Info("Initializing a window for Windows..."); //Initialize glfw if it hasn't already if (windowCount == 0) { bool success = Glfw.Init(); Debug.Assert(success, "GLFW failed to init!"); Glfw.SetErrorCallback(ErrorHandler); } #if DEBUG if (RenderingAPI.GetRenderingAPI() == RenderingAPIType.OpenGL) { Glfw.WindowHint(Hint.OpenglDebugContext, true); } #endif //Set the properties and create the window windowProperties = properties; { ProfilerTimer.Profile("GLFW Create Window", () => { window = new NativeWindow(properties.Width, properties.Height, properties.Title); windowCount++; }); } //Create context context = RenderingAPI.GetRenderingAPI() switch { RenderingAPIType.OpenGL => new OpenGLContext(window), _ => throw new ArgumentOutOfRangeException() }; //Init the context context.Init(); SetVSync(properties.VSync); //Setup input Input.KeyInputImpl = new WindowsInput(window); //GLFW callbacks window.Closed += (sender, args) => OnEvent?.Invoke(new WindowCloseEvent()); window.SizeChanged += delegate(object sender, SizeChangeEventArgs args) { windowProperties.Width = args.Size.Width; windowProperties.Height = args.Size.Height; OnEvent?.Invoke(new WindowResizedEvent(args.Size.Width, args.Size.Height)); }; window.KeyAction += delegate(object sender, KeyEventArgs args) { switch (args.State) { case InputState.Release: OnEvent?.Invoke(new KeyReleasedEvent((KeyCode)args.Key)); break; case InputState.Press: OnEvent?.Invoke(new KeyPressedEvent((KeyCode)args.Key)); break; case InputState.Repeat: OnEvent?.Invoke(new KeyPressedEvent((KeyCode)args.Key, 1)); break; default: throw new ArgumentOutOfRangeException(nameof(args.State), args.State, null); } }; window.MouseButton += delegate(object sender, MouseButtonEventArgs args) { switch (args.Action) { case InputState.Press: OnEvent?.Invoke(new MouseButtonPressedEvent((int)args.Button)); break; case InputState.Release: OnEvent?.Invoke(new MouseButtonReleasedEvent((int)args.Button)); break; } }; window.MouseScroll += (sender, args) => OnEvent?.Invoke(new MouseScrollEvent((float)args.X, (float)args.Y)); window.MouseMoved += (sender, args) => OnEvent?.Invoke(new MouseMovedEvent((float)args.X, (float)args.Y)); Logger.Debug("Created a window for Windows ({@Width}x{@Height}, {@VSync})", properties.Width, properties.Height, properties.VSync); }); }