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; }
public void Begin() { ImGuiController.ImGui_ImplOpenGL3_NewFrame(); ImGuiController.ImGui_ImplGlfw_NewFrame(); ImGui.NewFrame(); ImGuizmo.BeginFrame(); }
/// <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); }
public void BeginFrame() { #if DEBUG using Profiler fullProfiler = new Profiler(GetType()); #endif frameBegun = true; ImGui.NewFrame(); ImGuizmo.BeginFrame(); }
public static unsafe void BeforeFrame() { if (!Initialised) { throw new Exception("Tried to call BeforeFrame before initialising."); } SetContext(); ImGui.NewFrame(); ImGuizmo.BeginFrame(); NewFrame = true; }
internal void Update(float dt) { if (frameBegun) { ImGui.Render(); } SetPerFrameImGuiData(dt); UpdateImGuiInput(); frameBegun = true; ImGui.NewFrame(); ImGuizmo.BeginFrame(); }
private void DrawGizmo(EditorPanel sender) { if (ready) { ImGuizmo.SetOrthographic(_viewportPanel.ProjectioMode == ViewportPanel.ViewMode.Orthographic); _viewportPanel.EnableSelect = !ImGuizmo.IsOver(); ImGuizmo.SetRect(_viewportPanel.WindowContentAreaMin.X, _viewportPanel.WindowContentAreaMin.Y, _viewportPanel.WindowContentAreaMax.X - _viewportPanel.WindowContentAreaMin.X, _viewportPanel.WindowContentAreaMax.Y - _viewportPanel.WindowContentAreaMin.Y); //ref *(float*)(void*)null ImGuizmo.SetDrawlist(); if (ImGuizmo.Manipulate(ref cameraView.M11, ref cameraProjection.M11, currentGizmoOperation, (currentGizmoOperation != OPERATION.SCALE) ? currentGizmoMode : MODE.LOCAL, ref transformMat.M11)) { // safety feature if (!Matrix4x4Extension.HasNaNElement(transformMat)) { Context.ActiveEntity.Transform.SetWorldTransform(transformMat); } } } }
public override void OnGUI() { ImGui.Begin("Viewport"); if (ECSScene.Camera == null) { ImGui.Text("Camera missing."); ImGui.End(); } var l = ImGui.GetWindowContentRegionMin(); var h = ImGui.GetWindowContentRegionMax(); var size = h - l; ECSScene.RenderTexture.Size = size; ImGui.Image(new IntPtr(ECSScene.RenderTexture.ResolveTex), size, new(0, 1), new(1, 0)); // This renders the texture technically upside-down how OpenGL sees it // but since OpenGL textures are already upside-down it's uno reverse carding opengl's flip and it's normal now var wp = ImGui.GetWindowPos(); ImGuizmo.Enable(ImGui.IsMouseHoveringRect(wp, wp + size)); // Gizmos var dl = ImGui.GetForegroundDrawList(); ImGuizmo.SetOrthographic(false); var cr = ImGui.GetWindowContentRegionMax(); ImGuizmo.SetRect(wp.X, wp.Y, cr.X, cr.Y); ImGuizmo.SetDrawlist(dl); if (Editor.SelectedObject != null && Editor.ObjectSelected) { var v = ECSScene.Camera.View(); var p = ECSScene.Camera.Projection(); var a = Editor.SelectedObject.ModelMatrix; var op = Toolbar.ActiveMode switch { MovementMode.Translate => OPERATION.TRANSLATE, MovementMode.Rotate => OPERATION.ROTATE, _ => OPERATION.TRANSLATE }; var m = ImGuizmo.Manipulate(ref v.Row0.X, ref p.Row0.X, op, MODE.LOCAL, ref a.Row0.X); if (m) { Editor.SelectedObject.ModelMatrix = a; } } ImGui.End(); } }
public void ProcessGizmos() { var selected = _guiService.SelectedEntity; if (selected != default && selected.Has <TransformComponent>()) { foreach (var camera in _cameras) { ref var cam = ref _cameras.Get1(camera); if (cam.Camera.Active && _guiService.GizmoType.HasValue) { if (duplicated && (!InputManager.Instance.GetKeyDown(KeyCodes.AltLeft) || InputManager.Instance.GetMouseButtonUp(MouseButtonCodes.Left))) { duplicated = false; } ImGuizmo.SetID(camera); ImGuizmo.SetOrthographic(cam.Camera.ProjectionType == BootEngine.Renderer.Cameras.ProjectionType.Orthographic); ImGuizmo.SetDrawlist(ImGui.GetWindowDrawList()); float windowWidth = ImGui.GetWindowWidth(); float windowHeight = ImGui.GetWindowHeight(); ImGuizmo.SetRect(ImGui.GetWindowPos().X, ImGui.GetWindowPos().Y, windowWidth, windowHeight); bool snap = InputManager.Instance.GetKeyDown(KeyCodes.LControl); float snapValue = .1f; if (_guiService.GizmoType == OPERATION.ROTATE) { snapValue = 45f; } float[] snapValues = new float[] { snapValue, snapValue, snapValue }; ref var tc = ref selected.Get <TransformComponent>(); var rotTmp = MathUtil.Rad2Deg(tc.Rotation); float[] pos = new float[] { tc.Translation.X, tc.Translation.Y, tc.Translation.Z }; float[] rot = new float[] { rotTmp.X, rotTmp.Y, rotTmp.Z }; float[] sca = new float[] { tc.Scale.X, tc.Scale.Y, tc.Scale.Z }; float[] transform = new float[16]; ImGuizmo.RecomposeMatrixFromComponents(ref pos[0], ref rot[0], ref sca[0], ref transform[0]); // using the component's transform breaks guizmos for some reason // TODO: investigate //transform = tc.Transform.ToFloatArray(); ref var cameraTc = ref _cameras.Get2(camera); Matrix4x4.Invert(cameraTc.Transform, out Matrix4x4 cameraViewMat); float[] cameraView = cameraViewMat.ToFloatArray(); float[] cameraProj; if (cam.Camera.SwapYAxis) { // de-swapping Y axis for gizmo rendering cameraProj = (cam.Camera.ProjectionMatrix * new Matrix4x4( 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)).ToFloatArray(); } else { cameraProj = cam.Camera.ProjectionMatrix.ToFloatArray(); } float[] deltaTransform = new float[16]; if (snap) { ImGuizmo.Manipulate(ref cameraView[0], ref cameraProj[0], _guiService.GizmoType.Value, MODE.LOCAL, ref transform[0], ref deltaTransform[0], ref snapValues[0]); } else { ImGuizmo.Manipulate(ref cameraView[0], ref cameraProj[0], _guiService.GizmoType.Value, MODE.LOCAL, ref transform[0], ref deltaTransform[0]); } if (ImGuizmo.IsOver() && ImGuizmo.IsUsing()) { if (InputManager.Instance.GetKeyDown(KeyCodes.AltLeft) && !duplicated) { // copy current entity _guiService.SelectedEntity = _guiService.SelectedEntity.Copy(); ref var tag = ref _guiService.SelectedEntity.Get <TagComponent>(); #pragma warning disable S1643 // Strings should not be concatenated using '+' in a loop tag.Tag += " (Copy)"; #pragma warning restore S1643 // Strings should not be concatenated using '+' in a loop duplicated = true; } float[] translation = new float[3]; float[] rotation = new float[3]; float[] scale = new float[3]; switch (_guiService.GizmoType) { case OPERATION.TRANSLATE: ImGuizmo.DecomposeMatrixToComponents(ref deltaTransform[0], ref translation[0], ref rotation[0], ref scale[0]); tc.Translation += new Vector3(translation[0], translation[1], translation[2]); break; case OPERATION.ROTATE: ImGuizmo.DecomposeMatrixToComponents(ref deltaTransform[0], ref translation[0], ref rotation[0], ref scale[0]); tc.Rotation -= MathUtil.Deg2Rad(new Vector3(rotation[0], rotation[1], rotation[2])); break; case OPERATION.SCALE: // for some reason, scale part from deltaTransform does not return deltaScale ImGuizmo.DecomposeMatrixToComponents(ref transform[0], ref translation[0], ref rotation[0], ref scale[0]); tc.Scale = new Vector3(scale[0], scale[1], scale[2]); break; } }
private void OnImGui() { //dockspace ImGui.DockSpaceOverViewport(); if (ImGui.BeginMainMenuBar()) { pc.DrawFileMenu(); ImGui.EndMainMenuBar(); } ImGui.PushStyleVar(ImGuiStyleVar.WindowMinSize, new System.Numerics.Vector2(160f, 90f)); if (ImGui.Begin("Viewport")) { cm.Focus = ImGui.IsWindowFocused(); var cPos = ImGui.GetCursorScreenPos(); var vSize = ImGui.GetContentRegionAvail(); Renderer.ViewportSize = new Vector2i((int)vSize.X, (int)vSize.Y); //display framebuffer texture on window ImGui.GetWindowDrawList().AddImage( (IntPtr)Renderer.FramebufferTexture, cPos, cPos + vSize, new System.Numerics.Vector2(0f, 1f), new System.Numerics.Vector2(1f, 0f)); //gizmos ImGui.PushClipRect(cPos, cPos + vSize, false); if (SceneHierachy.SelectedEntity != null) { var entity = SceneHierachy.SelectedEntity; ImGuizmo.SetOrthographic(false); ImGuizmo.SetDrawlist(); ImGuizmo.SetRect(cPos.X, cPos.Y, vSize.X, vSize.Y); Camera.Main.CalculateViewProjection(out var view, out var projection); var transform = entity.Transform.GlobalTransform; ImGuizmo.Manipulate(ref view.Row0.X, ref projection.Row0.X, operation, MODE.LOCAL, ref transform.Row0.X); if (ImGuizmo.IsUsing()) { var parentGlobal = entity.Parent != null ? entity.Parent.Transform.GlobalTransform : Matrix4.Identity; var local = transform * parentGlobal.Inverted(); entity.Transform.Position = local.ExtractTranslation(); entity.Transform.Rotation = local.ExtractRotation(); entity.Transform.Scale = local.ExtractScale(); } } ImGui.SetCursorScreenPos(cPos + new System.Numerics.Vector2(4f)); ImGui.SetNextItemWidth(240f); if (ImGui.BeginCombo("Gizmo", operation == OPERATION.TRANSLATE ? "Translate" : (operation == OPERATION.ROTATE ? "Rotate" : "Scale"))) { if (ImGui.Selectable("Translate", operation == OPERATION.TRANSLATE)) { operation = OPERATION.TRANSLATE; } if (ImGui.Selectable("Rotate", operation == OPERATION.ROTATE)) { operation = OPERATION.ROTATE; } if (ImGui.Selectable("Scale", operation == OPERATION.SCALE)) { operation = OPERATION.SCALE; } } ImGui.PopClipRect(); //mouse select with raycast if (ImGui.IsWindowHovered() && ImGui.IsWindowFocused() && ImGui.IsMouseClicked(ImGuiMouseButton.Left) && !ImGuizmo.IsUsing()) { Ray ray; ray.Origin = Camera.Main.BaseTransform.GlobalTransform.ExtractTranslation(); //get cam position var mPos = (ImGui.GetMousePos() - cPos) / vSize; //get mouse pos in [0, 1] Vector2 mousePos = new Vector2(mPos.X, mPos.Y) * new Vector2(2f) - new Vector2(1f); //convert to [-1, 1] Camera.Main.CalculateViewProjection(out var view, out var proj); //get view and proj Vector4 unprojected = new Vector4(mousePos.X, -mousePos.Y, 1f, 1f) * Matrix4.Invert(view * proj); //what the f**k? ray.Direction = Vector3.Normalize(unprojected.Xyz); MouseSelect(ray); } ImGui.End(); } ImGui.PopStyleVar(); if (ImGui.Begin("Debug")) { ImGui.Text($"Frametime: {MathF.Floor(Time.UnscaledDeltaTime * 100000f) / 100f}ms"); ImGui.Text($"Framerate: {MathF.Floor(1f / Time.UnscaledDeltaTime)}"); #if DEBUG ImGui.DragFloat("Exposure", ref ((ForwardRenderer)Engine.Renderer).Exposure, 0.1f); #endif ImGui.End(); } }
/// <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); }