/// <summary> /// Constructs a new ImGuiController. /// </summary> public ImGuiController(GraphicsDevice gd, OutputDescription outputDescription, WindowBase window) { #if DEBUG using Profiler fullProfiler = new Profiler(GetType()); #endif mainWindow = window; Sdl2Window sdlWindow = window.SdlWindow; windowWidth = sdlWindow.Width; windowHeight = sdlWindow.Height; ImPlot.CreateContext(); ImNodes.Initialize(); IntPtr imguiCtx = ImGui.CreateContext(); ImGui.SetCurrentContext(imguiCtx); ImPlot.SetImGuiContext(imguiCtx); ImNodes.SetImGuiContext(imguiCtx); ImGuizmo.SetImGuiContext(imguiCtx); ImGui.StyleColorsDark(); CreateDeviceResources(gd, outputDescription); SetupImGuiIo(sdlWindow); SetImGuiKeyMappings(); SetPerFrameImGuiData(1f / 60); }
internal void Init() { Main = this; Engine.MainWindow.TextInput += TextInput; IntPtr context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); ImGuizmo.SetImGuiContext(context); ImGuiIOPtr io = ImGui.GetIO(); io.Fonts.AddFontFromFileTTF(Path.Combine(AppContext.BaseDirectory, "EditorAssets/Fonts/Inconsolata.ttf"), 16); io.BackendFlags |= ImGuiBackendFlags.HasMouseCursors | ImGuiBackendFlags.RendererHasVtxOffset; io.ConfigFlags |= ImGuiConfigFlags.DockingEnable | ImGuiConfigFlags.NavEnableKeyboard; io.ConfigWindowsResizeFromEdges = true; SetStyle(); CreateDeviceResources(); SetKeyMappings(); SetPerFrameImGuiData(0.166666f); ImGui.NewFrame(); ImGuizmo.BeginFrame(); frameBegun = true; }
/// <summary> /// Constructs a new ImGuiController. /// </summary> public unsafe ImGuiController(GraphicsDevice gd, Sdl2Window window, OutputDescription outputDescription, int width, int height) { _gd = gd; _window = window; _windowWidth = width; _windowHeight = height; //Create ImGui Context var context = ImGui.CreateContext(); ImGui.SetCurrentContext(context); //Create ImPlot Context ImPlot.SetImGuiContext(context); ImPlot.CreateContext(); //Create ImNodes Context imnodes.SetImGuiContext(context); imnodes.Initialize(); //Create ImGuizmo Context ImGuizmo.SetImGuiContext(context); ImGuiIOPtr io = ImGui.GetIO(); io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard; io.ConfigFlags |= ImGuiConfigFlags.NavEnableGamepad; ImGuiPlatformIOPtr platformIo = ImGui.GetPlatformIO(); ImGuiViewportPtr mainViewport = platformIo.Viewports[0]; mainViewport.PlatformHandle = window.Handle; _mainViewportWindow = new VeldridImGuiWindow(gd, mainViewport, _window); _createWindow = CreateWindow; _destroyWindow = DestroyWindow; _getWindowPos = GetWindowPos; _showWindow = ShowWindow; _setWindowPos = SetWindowPos; _setWindowSize = SetWindowSize; _getWindowSize = GetWindowSize; _setWindowFocus = SetWindowFocus; _getWindowFocus = GetWindowFocus; _getWindowMinimized = GetWindowMinimized; _setWindowTitle = SetWindowTitle; platformIo.Platform_CreateWindow = Marshal.GetFunctionPointerForDelegate(_createWindow); platformIo.Platform_DestroyWindow = Marshal.GetFunctionPointerForDelegate(_destroyWindow); platformIo.Platform_ShowWindow = Marshal.GetFunctionPointerForDelegate(_showWindow); platformIo.Platform_SetWindowPos = Marshal.GetFunctionPointerForDelegate(_setWindowPos); platformIo.Platform_SetWindowSize = Marshal.GetFunctionPointerForDelegate(_setWindowSize); platformIo.Platform_SetWindowFocus = Marshal.GetFunctionPointerForDelegate(_setWindowFocus); platformIo.Platform_GetWindowFocus = Marshal.GetFunctionPointerForDelegate(_getWindowFocus); platformIo.Platform_GetWindowMinimized = Marshal.GetFunctionPointerForDelegate(_getWindowMinimized); platformIo.Platform_SetWindowTitle = Marshal.GetFunctionPointerForDelegate(_setWindowTitle); ImGuiNative.ImGuiPlatformIO_Set_Platform_GetWindowPos(platformIo.NativePtr, Marshal.GetFunctionPointerForDelegate(_getWindowPos)); ImGuiNative.ImGuiPlatformIO_Set_Platform_GetWindowSize(platformIo.NativePtr, Marshal.GetFunctionPointerForDelegate(_getWindowSize)); unsafe { io.NativePtr->BackendPlatformName = (byte *)new FixedAsciiString("Veldrid.SDL2 Backend").DataPtr; } io.BackendFlags |= ImGuiBackendFlags.HasMouseCursors; io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos; io.BackendFlags |= ImGuiBackendFlags.PlatformHasViewports; io.BackendFlags |= ImGuiBackendFlags.RendererHasViewports; io.Fonts.AddFontDefault(); CreateDeviceResources(gd, outputDescription); SetKeyMappings(); SetPerFrameImGuiData(1f / 60f); UpdateMonitors(); ImGui.NewFrame(); _frameBegun = true; }
public unsafe override void OnAttach() { ImGuiContext = ImGui.CreateContext(); //ImGui.SetCurrentContext(context); ImGuizmo.SetImGuiContext(ImGuiContext); Application app = Application.Instance; GLFW.Window windowHandle = app.Window.Handle; if (ImGuiController.ImGui_ImplGlfw_InitForOpenGL(windowHandle, true)) { Log.Core.Info("ImGui GLFW part initialized"); } if (ImGuiController.ImGui_ImplOpenGL3_Init("#version 330 core")) { Log.Core.Info("ImGui OpenGL part initialized"); } ImGuiIOPtr io = ImGui.GetIO(); io.DisplaySize = new Vector2( app.Window.Width / Vector2.One.X, app.Window.Height / Vector2.One.Y); io.DisplayFramebufferScale = Vector2.One; io.DeltaTime = 1.0f / 60.0f; // base theme //ImGui.StyleColorsClassic(); //ImGui.StyleColorsLight(); ImGui.StyleColorsDark(); SetDarkThemeColors(); io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; //io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard; // Enable Keyboard Controls ////io.ConfigFlags |= ImGuiConfigFlags.NavEnableGamepad; // Enable Gamepad Controls //io.ConfigFlags |= ImGuiConfigFlags.DockingEnable; // Enable Docking //io.ConfigFlags |= ImGuiConfigFlags.ViewportsEnable; // Enable Multi-Viewport / Platform Windows ////io.ConfigFlags |= ImGuiConfigFlags.ViewportsNoTaskBarIcons; ////io.ConfigFlags |= ImGuiConfigFlags.ViewportsNoMerge; //io.BackendFlags |= ImGuiBackendFlags.HasMouseCursors; //io.BackendFlags |= ImGuiBackendFlags.HasSetMousePos; //io.Fonts.AddFontDefault(io.Fonts.AddFontFromFileTTF(FileEnvironment.ResourceFolder + "fonts/consola.ttf", 16.0f, null, io.Fonts.GetGlyphRangesChineseSimplifiedCommon()).ConfigData); //ImFontAtlasPtr fonts = ImGui.GetIO().Fonts; //io.Fonts.AddFontDefault(); //io.Fonts.AddFontFromFileTTF(FileEnvironment.ResourceFolder + "fonts/arial.ttf", 18.0f); //io.Fonts.AddFontDefault(io.Fonts.AddFontFromFileTTF(FileEnvironment.ResourceFolder + "fonts/arial.ttf", 18.0f).ConfigData); //io.FontDefault = io.Fonts.AddFontFromFileTTF(FileEnvironment.ResourceFolder + "fonts/arial.ttf", 18.0f); // // // //ImGuiStylePtr style = ImGui.GetStyle(); //if ((io.ConfigFlags & ImGuiConfigFlags.ViewportsEnable) > 0) //{ // style.WindowRounding = 0.0f; // style.Colors[(int)ImGuiCol.WindowBg].W = 1.0f; //} // }
public static unsafe void Initialise() { GL.LoadBindings(new SDLBindingsContext()); Context = ImGui.CreateContext(); ImGui.SetCurrentContext(Context); ImGuizmo.SetImGuiContext(Context); var io = ImGui.GetIO(); GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.DebugOutputSynchronous); GL.DebugMessageCallback(_DebugCb, IntPtr.Zero); io.DisplaySize.X = Engine.Width; io.DisplaySize.Y = Engine.Height; io.KeyMap[(int)ImGuiKey.Tab] = (int)SC.SDL_SCANCODE_TAB; io.KeyMap[(int)ImGuiKey.LeftArrow] = (int)SC.SDL_SCANCODE_LEFT; io.KeyMap[(int)ImGuiKey.RightArrow] = (int)SC.SDL_SCANCODE_RIGHT; io.KeyMap[(int)ImGuiKey.UpArrow] = (int)SC.SDL_SCANCODE_UP; io.KeyMap[(int)ImGuiKey.DownArrow] = (int)SC.SDL_SCANCODE_DOWN; io.KeyMap[(int)ImGuiKey.PageUp] = (int)SC.SDL_SCANCODE_PAGEUP; io.KeyMap[(int)ImGuiKey.PageDown] = (int)SC.SDL_SCANCODE_PAGEDOWN; io.KeyMap[(int)ImGuiKey.Home] = (int)SC.SDL_SCANCODE_HOME; io.KeyMap[(int)ImGuiKey.End] = (int)SC.SDL_SCANCODE_END; io.KeyMap[(int)ImGuiKey.Insert] = (int)SC.SDL_SCANCODE_INSERT; io.KeyMap[(int)ImGuiKey.Delete] = (int)SC.SDL_SCANCODE_DELETE; io.KeyMap[(int)ImGuiKey.Backspace] = (int)SC.SDL_SCANCODE_BACKSPACE; io.KeyMap[(int)ImGuiKey.Space] = (int)SC.SDL_SCANCODE_SPACE; io.KeyMap[(int)ImGuiKey.Enter] = (int)SC.SDL_SCANCODE_RETURN; io.KeyMap[(int)ImGuiKey.Escape] = (int)SC.SDL_SCANCODE_ESCAPE; io.KeyMap[(int)ImGuiKey.KeyPadEnter] = (int)SC.SDL_SCANCODE_KP_ENTER; io.KeyMap[(int)ImGuiKey.A] = (int)SC.SDL_SCANCODE_A; io.KeyMap[(int)ImGuiKey.C] = (int)SC.SDL_SCANCODE_C; io.KeyMap[(int)ImGuiKey.V] = (int)SC.SDL_SCANCODE_V; io.KeyMap[(int)ImGuiKey.X] = (int)SC.SDL_SCANCODE_X; io.KeyMap[(int)ImGuiKey.Y] = (int)SC.SDL_SCANCODE_Y; io.KeyMap[(int)ImGuiKey.Z] = (int)SC.SDL_SCANCODE_Z; var maj = GL.GetInteger(GetPName.MajorVersion); var min = GL.GetInteger(GetPName.MinorVersion); Log.Info($"OpenGLManager: This appears to be OpenGL {maj}.{min}."); var t = new GLVersion() { Major = maj, Minor = min, VersionString = $"{maj}.{min}" }; Version = t; if (Version.Major < 4 || (Version.Major == 4 && Version.Minor < 5)) { // This is not OpenGL 4.5 or higher. Log.Fatal("This version of OpenGL is too old! Luminal applications require at least GL 4.5."); Log.Fatal("Showing message box and exiting."); MessageBox.Error("Sorry, applications built with Luminal cannot run on your graphics card.\n" + $"Your graphics card only supports OpenGL {Version.VersionString}, and at least OpenGL 4.5 is required.", "Engine incompatible: OpenGL version too old"); Engine.Quit(1); } VtxBufSize = 10000; IdxBufSize = 2000; IG_VAO = new("ImGui"); IG_VAO.Bind(); VertexSource = File.ReadAllText("EngineResources/Shaders/2D/2D.vert"); FragSource = File.ReadAllText("EngineResources/Shaders/2D/2D.frag"); VS = new GLShader(VertexSource, GLShaderType.Vertex); FS = new GLShader(FragSource, GLShaderType.Fragment); VS.Compile(); FS.Compile(); ImGuiProgram = new GLShaderProgram().Attach(VS).Attach(FS).Link(); GLHelper.VertexBuffer("ImGui VBO", out VertexBuffer); GLHelper.ElementBuffer("ImGui EBO", out IndexBuffer); GL.NamedBufferData(VertexBuffer, VtxBufSize, IntPtr.Zero, BufferUsageHint.DynamicDraw); GL.NamedBufferData(IndexBuffer, IdxBufSize, IntPtr.Zero, BufferUsageHint.DynamicDraw); var va = IG_VAO.GLObject; GL.VertexArrayVertexBuffer(va, 0, VertexBuffer, IntPtr.Zero, Unsafe.SizeOf <ImDrawVert>()); GL.VertexArrayElementBuffer(va, IndexBuffer); GL.EnableVertexArrayAttrib(va, 0); GL.VertexArrayAttribBinding(va, 0, 0); GL.VertexArrayAttribFormat(va, 0, 2, VertexAttribType.Float, false, 0); GL.EnableVertexArrayAttrib(va, 1); GL.VertexArrayAttribBinding(va, 1, 0); GL.VertexArrayAttribFormat(va, 1, 2, VertexAttribType.Float, false, 8); GL.EnableVertexArrayAttrib(va, 2); GL.VertexArrayAttribBinding(va, 2, 0); GL.VertexArrayAttribFormat(va, 2, 4, VertexAttribType.UnsignedByte, true, 16); _SetClipboard = SetClipboard; io.SetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(_SetClipboard); _GetClipboard = GetClipboard; io.GetClipboardTextFn = Marshal.GetFunctionPointerForDelegate(_GetClipboard); Initialised = true; OnInitGL?.Invoke(); }
public static void SetContext() { ImGui.SetCurrentContext(Context); ImGuizmo.SetImGuiContext(Context); }