public static IntPtr CreateEditorCamera(int width, int height, Scene scene) { var camera = new Camera(false); camera.SetPerspective(MathUtil.Deg2Rad(45), .1f, 1000f); camera.ResizeViewport(width, height); var editorCam = scene.CreateEmptyEntity(); editorCam.AddComponent(new CameraComponent() { Camera = camera }); editorCam.AddComponent(new TransformComponent() { Translation = new System.Numerics.Vector3(1e-6f, 1e-6f, 1) }); editorCam.AddComponent(new EditorCameraComponent() { Distance = 10f }); camera.BlendState = BlendStateDescription.SingleAlphaBlend; camera.DepthStencilState = DepthStencilStateDescription.DepthOnlyLessEqual; camera.RasterizerState = new RasterizerStateDescription(FaceCullMode.None, PolygonFillMode.Solid, FrontFace.Clockwise, true, false); camera.ColorTargets = new Texture[] { resourceFactory.CreateTexture(TextureDescription.Texture2D( (uint)width, // Width (uint)height, // Height 1, // Miplevel 1, // ArrayLayers PixelFormat.R8_G8_B8_A8_UNorm, TextureUsage.RenderTarget | TextureUsage.Sampled)) }; camera.DepthTarget = resourceFactory.CreateTexture(TextureDescription.Texture2D( (uint)width, // Width (uint)height, // Height 1, // Miplevel 1, // ArrayLayers PixelFormat.R16_UNorm, TextureUsage.DepthStencil)); camera.RenderTarget = resourceFactory.CreateFramebuffer(new FramebufferDescription(camera.DepthTarget, camera.ColorTargets)); ImGuiLayer.ShouldClearBuffers = true; return(ImGuiLayer.GetOrCreateImGuiBinding(resourceFactory, camera.ColorTargets[0])); }
protected Application(Type windowType) { #if DEBUG using Profiler fullProfiler = new Profiler(GetType()); #endif CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.InvariantCulture; Logger.Init(); Logger.Assert(App == null, "App already initialized"); App = this; LayerStack = new LayerStack(); Window = WindowBase.CreateMainWindow(windowType); Window.EventCallback = OnEvent; ImGuiLayer = new ImGuiLayer(); LayerStack.PushOverlay(ImGuiLayer); }
private bool OnLoad(AppLoadEvent e) { AXProfiler.Capture(() => { _imGuiLayer = _layerFactory.CreateImGuiLayer(_window.NativeWindow, _window.InputContext); PushLayer(_imGuiLayer); foreach (Layer layer in _layers) { layer.OnLoad(); } _renderCommandDispatcher.Init(); }); return(true); }