public DevModeOverlay( GraphicsDevice graphicsDevice, Framebuffer framebuffer, LogEventRecorder logEventRecorder) { Framebuffer mainFramebuffer = framebuffer; _imguiRenderer = new ImGuiRenderer( graphicsDevice, mainFramebuffer.OutputDescription, (int)mainFramebuffer.Width, (int)mainFramebuffer.Height ); ImGui.EndFrame(); ImGuiIOPtr io = ImGui.GetIO(); io.Fonts.Clear(); io.Fonts.AddFontFromFileTTF( "Fonts/NotoSansCJKjp-Regular.ttf", 16, null, io.Fonts.GetGlyphRangesJapanese() ); _imguiRenderer.RecreateFontDeviceTexture(graphicsDevice); ImGui.NewFrame(); _gd = graphicsDevice; _cl = _gd.ResourceFactory.CreateCommandList(); _framebuffer = mainFramebuffer; _logView = new LogView(logEventRecorder); }
public static ImFontPtr LoadSystemFont(this ImGuiRenderer renderer, string fontFileName) { var windows = Environment.GetEnvironmentVariable("WINDIR"); if (windows == null) { return(null); } var fontPath = Path.Combine(windows, "Fonts", fontFileName); var font = ImGui.GetIO().Fonts.AddFontFromFileTTF(fontPath, 13); if (!font.IsNull()) { renderer.RecreateFontDeviceTexture(); } return(font); }
public GuiVisual() { var window = IoC.Resolve <Sdl2Window>(); graphicsDevice = IoC.Resolve <GraphicsDevice>(); imGuiRenderer = new ImGuiRenderer(graphicsDevice, graphicsDevice.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height); var style = ImGui.GetStyle(); style.FrameBorderSize = 1f; style.WindowBorderSize = 3f; var io = ImGui.GetIO(); io.ConfigFlags |= ImGuiConfigFlags.NavEnableKeyboard; io.ConfigWindowsResizeFromEdges = true; var fonts = io.Fonts; //fonts.ClearFonts(); //var config = new ImFontConfig //{ // OversampleH = 2, // OversampleV = 2, //}; //IntPtr unmanagedAddr = Marshal.AllocHGlobal(Marshal.SizeOf(config)); //Marshal.StructureToPtr(config, unmanagedAddr, true); font = fonts.AddFontFromFileTTF("Content/DroidSans.ttf", 32); //font.ConfigDataCount = 1; //var i = font.ConfigDataCount; //font = fonts.AddFontFromFileTTF(@"D:\arial.ttf", 26, new ImFontConfigPtr(unmanagedAddr)); //io.FontDefault = font; imGuiRenderer.RecreateFontDeviceTexture(); window.Resized += () => { imGuiRenderer.WindowResized(window.Width, window.Height); }; }
static void MainImGui(string[] args) { VeldridStartup.CreateWindowAndGraphicsDevice( new WindowCreateInfo(50, 50, 1920, 1080, WindowState.Normal, "ImGui Test"), out var window, out var gd); var cl = gd.ResourceFactory.CreateCommandList(); // [1] var imguiRenderer = new ImGuiRenderer( gd, gd.MainSwapchain.Framebuffer.OutputDescription, window.Width, window.Height); var io = ImGui.GetIO(); // // var data = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ushort)) * 3); // var ranges = new ImVector<ushort>(3, 3, data); // ranges[0] = 0xf000; // ranges[1] = 0xf3ff; // ranges[2] = 0; // var font = io.Fonts.AddFontFromFileTTF("Inconsolata-Regular.ttf", 16); // io.Fonts.Build(); imguiRenderer.RecreateFontDeviceTexture(); if (!font.IsLoaded()) { throw new Exception("Could not load font"); } var field = typeof(ImGuiRenderer).GetField("_scaleFactor", BindingFlags.Instance | BindingFlags.NonPublic); field.SetValue(imguiRenderer, new Vector2(2.5f, 2.5f)); window.Resized += () => { imguiRenderer.WindowResized(window.Width, window.Height); gd.MainSwapchain.Resize((uint)window.Width, (uint)window.Height); }; var buffer = new StringBuilder("[ryan@manjaro-xfce-vm-laptop ~]$ "); // for (int i = 127; i < 256 + 128; i++) // buffer.AppendLine($"{i}: {(char)i}"); var nextToggle = DateTime.UtcNow.AddMilliseconds(750); bool visible = true; while (window.Exists) { var snapshot = new InputSnapshotWrapper(window.PumpEvents(), new Vector2(2.5f, 2.5f)); imguiRenderer.Update(1f / 60f, snapshot); // [2] bool scrollToBottom = false; foreach (var c in snapshot.KeyCharPresses) { buffer.Append(c); scrollToBottom = true; } foreach (var k in snapshot.KeyEvents) { if (k.Down && k.Key == Key.Enter) { buffer.AppendLine(); scrollToBottom = true; } } if (DateTime.UtcNow >= nextToggle) { visible = !visible; nextToggle = nextToggle.AddMilliseconds(750); } // Draw whatever you want here. ImGui.Begin("Test Window", ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoMove | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoNav); ImGui.SetWindowPos(new Vector2(0, 0)); ImGui.SetWindowSize(new Vector2(window.Width / 2.5f, window.Height / 2.5f)); { ImGui.PushFont(font); ImGui.TextWrapped(buffer.ToString() + (visible ? '_' : ' ')); if (scrollToBottom) { ImGui.SetScrollHereY(1); } } cl.Begin(); cl.SetFramebuffer(gd.MainSwapchain.Framebuffer); cl.ClearColorTarget(0, new RgbaFloat(0, 0, 0.2f, 1f)); imguiRenderer.Render(gd, cl); // [3] cl.End(); gd.SubmitCommands(cl); gd.SwapBuffers(gd.MainSwapchain); } }