ImGuiNET / ImGui.NET

An ImGui wrapper for .NET.
MIT License
1.87k stars 304 forks source link

Problem with fonts #425

Closed ZereX666 closed 3 months ago

ZereX666 commented 1 year ago

I can't figure out what I did wrong....

https://github.com/ImGuiNET/ImGui.NET/blob/master/src/ImGui.NET.SampleProgram/ImGuiController.cs (i use this for example) image

Code:


        _window = VeldridStartup.CreateWindow(new WindowCreateInfo(50, 50, Settings.Config!.windowWidth, Settings.Config.windowHeight, Settings.Config.WindowState, "test"));
        _gd = VeldridStartup.CreateGraphicsDevice(_window,new GraphicsDeviceOptions(false, null, true, ResourceBindingModel.Improved, true, true) , GraphicsBackend.Direct3D11); 
        _window.Resized += () =>
        {
            _gd.MainSwapchain.Resize((uint)_window.Width, (uint)_window.Height);
            _controller.WindowResized(_window.Width, _window.Height);
        }        
        _cl = _gd.ResourceFactory.CreateCommandList();
        _controller = new ImGuiController(_gd, _gd.MainSwapchain.Framebuffer.OutputDescription, _window.Width, _window.Height);

        var stopwatch = Stopwatch.StartNew();
        float deltaTime = 0f;

        ImFontPtr imFontPtr;
        unsafe
        {
            ImGui.GetIO().Fonts.Clear();
            var config = ImGuiNative.ImFontConfig_ImFontConfig();
            imFontPtr = ImGui.GetIO().Fonts.AddFontFromFileTTF(@"ProggyClean.ttf", 13.0f, config, ImGui.GetIO().Fonts.GetGlyphRangesCyrillic());
            ImGuiNative.ImFontConfig_destroy(config);
        }

        _controller.RecreateFontDeviceTexture(_gd);

        while (_window.Exists)
        {
            deltaTime = stopwatch.ElapsedTicks / (float)Stopwatch.Frequency;
            stopwatch.Restart();
            InputSnapshot snapshot = _window.PumpEvents();

            if (!_window.Exists)
                break;

            if (_window.WindowState == WindowState.Minimized)
            {
                Thread.Sleep(1);
                continue;
            }

            _controller.Update(deltaTime, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.

            ImGui.PushFont(imFontPtr);
            SubmitUI();

            _cl.Begin();
            _cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
            _cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 1f));
            _controller.Render(_gd, _cl);
            _cl.End();
            _gd.SubmitCommands(_cl);
            _gd.SwapBuffers(_gd.MainSwapchain);
        }

        ImGui.GetIO().ConfigDockingWithShift = true;

        _gd.WaitForIdle();
        _controller.Dispose();
        _cl.Dispose();
        _gd.Dispose();
ZereX666 commented 5 months ago

still relevant

zaafar commented 5 months ago

ImGui.PushFont(imFontPtr); in this line you are pushing the font for imgui to use that your graphic card doesn't know about. You have to use the graphic card api/lib to upload the font to it and then use it in imgui.