Изначально я создал свое приложение с помощью ImGuiNET и ClickableTransparentOverlay. Однако, поскольку мне нужно отправлять нажатия клавиш в окно переднего плана, мне нужно перенести его на обычный ImGuiNet. Это потому, что CTO всегда является окном переднего плана.
В CTO я использую шрифты ttf, и все работает хорошо, но с ImGuiNET (1.91.0) шрифты, кажется, загружаются нормально, но вывод искажено. Похоже, текстуры построены неправильно или возникла проблема с их загрузкой в графический процессор.
Я использую ImGui.NET.SampleProgram (ImGuiNET + Veldrid) в качестве основы для тестирую мою реализацию шрифта. Может ли кто-нибудь помочь или указать мне на рабочий пример? Мне не удалось найти его в Интернете (или он был недостаточно полным для решения проблемы), а ChatGPT не смог найти решение.
[img]https: //i.sstatic.net/TMTEraZJ.jpg[/img]
Это часть кода:
static void Main(string[] args)
{
bool keepRunning = true;
// Create window, GraphicsDevice, and all resources necessary for the demo.
VeldridStartup.CreateWindowAndGraphicsDevice(
// new WindowCreateInfo(50, 50, 1280, 720, WindowState.Normal, "icaVoice"),
new WindowCreateInfo(50, 50, 800, 600, WindowState.Normal, "icaVoice"),
new GraphicsDeviceOptions(true, null, true, ResourceBindingModel.Improved, true, true),
out _window,
out _gd);
_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);
//hwnd = WindowHelper.GetForegroundWindow(); // Get your actual HWND
WindowHelper.SetHWND(); // Initialize window handle
// Load fonts
FontLoader fontLoader = new FontLoader(_gd, _controller);
fontLoader.LoadFonts();
var gui = new GUI(settings, commandQueue, _controller, _gd);
while (keepRunning)
{
InputSnapshot snapshot = _window.PumpEvents();
_controller.Update(deltaTime, snapshot); // Feed the input events to our ImGui controller, which passes them through to ImGui.
_showGUI = WindowHelper.SetWindowState(settings.GuiMode, settings.GuiDelay, deltaTime); // TODO : make bool, so it determines whether to render GUI
if (_showGUI)
{
// Only process if window visible
if (!_window.Exists)
{
keepRunning = false;
break;
}
// Lock ImGui window to main (Veldrid/SDL2) window size and position
ImGui.SetNextWindowSize(new Vector2(_window.Width, _window.Height));
ImGui.SetNextWindowPos(Vector2.Zero);
// Render GUI
//gui.Render();
FontTest();
//GlyphList();
// Show in window
_cl.Begin();
_cl.SetFramebuffer(_gd.MainSwapchain.Framebuffer);
_cl.ClearColorTarget(0, new RgbaFloat(_clearColor.X, _clearColor.Y, _clearColor.Z, 0.1f));
_controller.Render(_gd, _cl);
_cl.End();
_gd.SubmitCommands(_cl);
_gd.SwapBuffers(_gd.MainSwapchain);
}
Thread.Sleep(40);
}
// Clean up Veldrid resources
_gd.WaitForIdle();
_controller.Dispose();
_cl.Dispose();
_gd.Dispose();
Console.WriteLine("Finished");
}
public class FontLoader
{
private GraphicsDevice _gd;
private ImGuiController _controller;
public FontLoader(GraphicsDevice gd, ImGuiController controller)
{
_gd = gd;
_controller = controller;
}
public unsafe void LoadFonts()
{
// Access ImGui's IO structure
var io = ImGui.GetIO();
// Define font file paths (ensure the paths are correct!)
string fontFilePath = "C:/Users/ivan/AppData/Local/Icarus/fonts/dejavu-sans-mono.book.ttf";
string boldFontFilePath = @"C:\Users\Ivan\AppData\Local\Icarus\fonts\dejavu-sans-mono.bold.ttf";
if (!File.Exists(fontFilePath))
{
Console.WriteLine($"Font file {fontFilePath} not found.");
return;
}
if (!File.Exists(boldFontFilePath))
{
Console.WriteLine($"Font file {boldFontFilePath} not found.");
return;
}
// Clear existing fonts (optional, if reloading fonts)
io.Fonts.Clear();
// create the object on the native side
var nativeConfig = ImGuiNative.ImFontConfig_ImFontConfig();
// fill with data
(*nativeConfig).OversampleH = 3;
(*nativeConfig).OversampleV = 3;
(*nativeConfig).RasterizerMultiply = 1f;
(*nativeConfig).GlyphExtraSpacing = new System.Numerics.Vector2(0, 0);
(*nativeConfig).MergeMode = 0;
// Load a basic font
regularFont = io.Fonts.AddFontFromFileTTF(fontFilePath, 22.0f, nativeConfig);
if (regularFont.NativePtr == null) Console.WriteLine("Failed to load regular font.");
//// Load a bold font
boldFont = io.Fonts.AddFontFromFileTTF(boldFontFilePath, 34.0f, nativeConfig);
if (boldFont.NativePtr == null) Console.WriteLine("Failed to load bold font.");
ImGuiNative.igGetIO()->FontDefault = null; // Use the new font
// Build the font atlas
io.Fonts.Build();
// Update ImGui's font texture with the graphics device
_controller.RecreateFontDeviceTexture(_gd);
}
}
private static unsafe void FontTest()
{
// ImGui rendering logic
ImGui.Begin("Hello, World!");
ImGui.PushFont(regularFont);
ImGui.Text("This is a sample window with a custom font!");
ImGui.End();
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... e-barcodes
Шрифт ttf загружается, но отображается искаженным (что-то вроде штрих-кодов) ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Шрифт ttf загружается, но отображается искаженным (что-то вроде штрих-кодов)
Anonymous » » в форуме C# - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Шрифт ttf загружается, но отображается искаженным (что-то вроде штрих-кодов)
Anonymous » » в форуме C# - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Шрифт ttf загружается, но отображается искаженным (что-то вроде штрих-кодов)
Anonymous » » в форуме C# - 0 Ответы
- 21 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Шрифт ttf загружается, но отображается искаженным (что-то вроде штрих-кодов)
Anonymous » » в форуме C# - 0 Ответы
- 20 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Шрифт ttf загружается, но отображается искаженным (что-то вроде штрих-кодов)
Anonymous » » в форуме C# - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-