C# class library that simplifies the creation of ImGui-rendered windows.
$ dotnet add package C.ImGuiGLFWA modern C# wrapper library that simplifies creating ImGui applications with OpenGL rendering and GLFW window management.
C.ImGuiGLFW is a C# class library that simplifies the creation of ImGui-rendered windows. It uses OpenGL 4.6 core for rendering, GLFW for window management system, and Hexa.NET.ImGui for ImGui integration.
Get C.ImGuiGLFW from NuGet using one of the following methods:
dotnet add package C.ImGuiGLFW
Use this command in terminal/command prompt. Works on Windows, macOS, and Linux.
Install-Package C.ImGuiGLFW
Use this command in Visual Studio's Package Manager Console (Windows only).
Alternatively, you can install via the graphical interface in Visual Studio or your preferred IDE by searching for "C.ImGuiGLFW".
Initialize the ImGuiController in the Main() method of your program:
ImGuiController.Initialize("MyApplication", modules: Module.All);
The Initialize method has multiple overloads to accommodate different initialization scenarios:
// Basic initialization with default settings
ImGuiController.Initialize();
// Initialize with modules
ImGuiController.Initialize(modules: Module.All);
// Initialize with window title
ImGuiController.Initialize("MyApp");
// Initialize with title and modules
ImGuiController.Initialize("MyApp", Module.All);
// Initialize with title and dimensions
ImGuiController.Initialize("MyApp", 800, 600);
// Initialize with title, dimensions, and modules
ImGuiController.Initialize("MyApp", 800, 600, Module.All);
// Initialize with dimensions only
ImGuiController.Initialize(800, 600);
// Initialize with dimensions and modules
ImGuiController.Initialize(800, 600, Module.All);
// Initialize with dimensions and position
ImGuiController.Initialize(800, 600, new Vector2(100, 100));
// Initialize with dimensions, position, and modules
ImGuiController.Initialize(800, 600, new Vector2(100, 100), Module.Guizmo);
// Initialize with dimensions, position, and resizable flag
ImGuiController.Initialize(800, 600, new Vector2(100, 100), true);
// Initialize with dimensions, position, resizable flag, and modules
ImGuiController.Initialize(800, 600, new Vector2(100, 100), true, Module.Nodes, Module Plot);
// Initialize with dimensions and position coordinates
ImGuiController.Initialize(800, 600, 100, 100);
// Initialize with dimensions, position coordinates, and modules
ImGuiController.Initialize(800, 600, 100, 100, Module.Plot);
// Initialize with custom WindowSettings
ImGuiController.Initialize(windowSettings);
// Initialize with custom WindowSettings and modules
ImGuiController.Initialize(windowSettings, Module.All);
Parameters:
windowSettings: Custom window settings (optional, reads from file if null)title: Window titlewidth/height: Window dimensions in pixelsposition: Window position as Vector2 or separate X/Y coordinatesresizable: Whether the window should be resizablemodules: ImGui modules to initialize (optional params array)Subscribe to various events to handle user input and UI rendering:
// Handle main menu bar rendering
ImGuiController.OnMainMenuBarRender += MainMenuBar;
// Handle character input events
ImGuiController.OnChar += OnCharInput;
Important: All custom font loading must be completed before calling ImGuiController.Run(). Font additions are not accepted after the application starts running.
If you want to load custom fonts with priority over the built-in fonts, use the FontBuilder before calling ImGuiController.Run():
// Initialize first (optional - can be done before or after font setup)
ImGuiController.Initialize("MyApplication");
// Add fonts from TTF files
ImGuiController.FontBuilder.AddFontFromFileTTF("path/to/font.ttf", 16.0f);
ImGuiController.FontBuilder.AddFontFromFileTTF("path/to/font.ttf", 16.0f, glyphRanges);
// Add fonts from embedded resources
ImGuiController.FontBuilder.AddFontFromEmbeddedResource(assembly, "Fonts.MyFont.ttf", 16.0f);
ImGuiController.FontBuilder.AddFontFromEmbeddedResource(assembly, "Fonts.MyFont.ttf", 16.0f, glyphRanges);
// Add fonts from memory
ImGuiController.FontBuilder.AddFontFromMemoryTTF(fontData, 16.0f, glyphRanges);
// Run - no more default font additions possible after this point
ImGuiController.Run();
The FontBuilder provides several methods to load custom fonts:
From File System:
AddFontFromFileTTF(string filePath, float fontSize) - Load TTF font from diskAddFontFromFileTTF(string filePath, float fontSize, ReadOnlySpan<uint> glyphRanges) - Load TTF font with custom glyph rangesFrom Embedded Resources:
AddFontFromEmbeddedResource(Assembly assembly, string path, float size) - Load font from assembly resourceAddFontFromEmbeddedResource(Assembly assembly, string path, float size, ReadOnlySpan<uint> glyphRanges) - Load with custom glyph rangesFrom Memory:
AddFontFromMemoryTTF(ReadOnlySpan<byte> fontData, float size, ReadOnlySpan<uint> glyphRanges) - Load font directly from memoryNote: Specifying custom glyph ranges can reduce memory usage by loading only the required characters.
If you don't want to load the built-in fonts, you can disable them by setting the following properties to false (default is true):
// Disable specific built-in fonts
ImGuiController.FontBuilder.AddNotoSansFont = false;
ImGuiController.FontBuilder.AddFontAwesomeFont = false;
ImGuiController.FontBuilder.AddEmojiFont = false;
ImGuiController.FontBuilder.AddDefaultFont = false; // ImGui's default font
Note: Built-in fonts are automatically added after all custom fonts have been loaded, but only if their respective properties are set to true.
AddFontFromFileTTF()AddFontFromEmbeddedResource()AddFontFromMemoryTTF()Create and add your custom ImGui windows:
var demoWindow = new DemoWindow();
ImGuiController.AddWindow(demoWindow);
Start the main application loop:
ImGuiController.Run();
Here's a minimal example:
using System;
using C.ImGuiGLFW;
class Program
{
static void Main()
{
// Initialize ImGuiController
ImGuiController.Initialize("TESTWINDOW");
// Set up event handlers
ImGuiController.OnMainMenuBarRender += MainMenuBar;
ImGuiController.OnChar += OnCharInput;
// Create and add windows
var demoWindow = new DemoWindow();
ImGuiController.AddWindow(demoWindow);
// Start the application
ImGuiController.Run();
}
private static void MainMenuBar()
{
// Your main menu bar implementation
}
private static void OnCharInput(uint codepoint)
{
// Handle character input
}
}
To create custom windows, implement the appropriate window interface or base class:
public class DemoWIndow : Window
{
protected override void Draw()
{
ImGui.Text("Hello, World!");
}
}
The Module enum allows you to specify which ImGui modules to initialize:
Module.All: Load all available modulesModule.Guizmo: ImGuizmo for 3D gizmo manipulationModule.Nodes: ImNodes for node-based graph editingModule.Plot: ImPlot for data plotting and visualizationMultiple modules can be specified:
// Load specific modules
ImGuiController.Initialize("MyApp", Module.Guizmo, Module.Plot);
// Load all modules (equivalent to Module.All)
ImGuiController.Initialize("MyApp", Module.Guizmo, Module.Nodes, Module.Plot);
For more detailed examples and advanced usage patterns, please visit the here.
I welcome your feedback and contributions to make C.ImGuiGLFW even better! If you have:
Feature requests - Ideas for new functionality or improvements Bug reports - Issues you've encountered while using the library Method suggestions - Additional methods or overloads you'd find useful
Please feel free to submit an issue or pull request on the GitHub repository.
Your contributions help improve the library for everyone who uses it. I appreciate bug reports, feature suggestions, code improvements, and documentation enhancements.
This project depends on several NuGet packages. Run dotnet list package to see current versions, or check THIRD-PARTY-NOTICES for license details.
This project builds upon the excellent work of many open source contributors:
Special thanks to all the maintainers and contributors of these projects for making modern cross-platform GUI development in C# possible.