### Running the ImGui Java Demo
Source: https://github.com/spair/imgui-java/blob/main/README.md
This snippet shows how to clone the ImGui Java repository and run the example module to try out the binding. It requires Git and Gradle to be installed, and JDK 8 or higher.
```bash
git clone git@github.com:SpaiR/imgui-java.git
cd imgui-java
./gradlew :example:run
```
--------------------------------
### Run Example with Windows Native Libraries
Source: https://github.com/spair/imgui-java/blob/main/README.md
Command to run the imgui-java example on Windows, specifying the path to the built native libraries. The '-PlibPath' argument points to the directory containing the libraries.
```bash
./gradlew example:run -PlibPath="../imgui-binding/build/libsNative/windows64"
```
--------------------------------
### Run Example with Linux Native Libraries
Source: https://github.com/spair/imgui-java/blob/main/README.md
Command to run the imgui-java example on Linux, specifying the path to the built native libraries. The '-PlibPath' argument points to the directory containing the libraries.
```bash
./gradlew example:run -PlibPath="../imgui-binding/build/libsNative/linux64"
```
--------------------------------
### Run imgui-java examples on macOS (x64)
Source: https://github.com/spair/imgui-java/blob/main/README.md
Executes the examples for the imgui-java project on macOS (Intel x64 architecture). This requires the native libraries to be built first, and the `-PlibPath` argument should point to the location of these libraries.
```bash
./gradlew example:run -PlibPath=../imgui-binding/build/libsNative/macosx64
```
--------------------------------
### Run imgui-java examples on macOS (arm64)
Source: https://github.com/spair/imgui-java/blob/main/README.md
Runs the imgui-java examples on macOS (ARM64 architecture). This command assumes the native libraries have been successfully built, and the `-PlibPath` should be set to the directory containing the compiled libraries.
```bash
./gradlew example:run -PlibPath=../imgui-binding/build/libsNative/macosxarm64
```
--------------------------------
### Build imgui-java for macOS (arm64)
Source: https://github.com/spair/imgui-java/blob/main/README.md
Builds the imgui-java native libraries for macOS (ARM64 architecture). Ensure all necessary dependencies are installed. The `-Dlocal` option controls the output directory for the generated native libraries.
```bash
./gradlew imgui-binding:generateLibs -Denvs=macosarm64 -Dlocal
```
--------------------------------
### Build imgui-java for macOS (x64)
Source: https://github.com/spair/imgui-java/blob/main/README.md
Builds the imgui-java native libraries for macOS (Intel x64 architecture). This command may require specific dependencies to be installed as per the Linux build instructions. The `-Dlocal` flag is optional and determines the output directory for the native libraries.
```bash
./gradlew imgui-binding:generateLibs -Denvs=macos -Dlocal
```
--------------------------------
### Custom Text Input Processing with Callbacks in ImGui Java
Source: https://context7.com/spair/imgui-java/llms.txt
Demonstrates how to use input text callbacks in ImGui Java for custom processing and validation of user input. This example shows how to intercept characters, modify them (e.g., replace 'h' with '!', block 'x', convert to uppercase), and log the changes. It utilizes `ImGuiInputTextCallback` and `ImGuiInputTextCallbackData`.
```java
import imgui.ImGui;
import imgui.ImGuiInputTextCallbackData;
import imgui.callback.ImGuiInputTextCallback;
import imgui.flag.ImGuiInputTextFlags;
import imgui.type.ImString;
public class InputCallbackExample {
private final ImString input = new ImString(256);
private final StringBuilder log = new StringBuilder();
private final ImGuiInputTextCallback callback = new ImGuiInputTextCallback() {
@Override
public void accept(ImGuiInputTextCallbackData data) {
char c = (char) data.getEventChar();
// Replace 'h' with '!'
if (c == 'h' || c == 'H') {
data.setEventChar('!');
log.append("Replaced 'h' with '!'\n");
}
// Block 'x' character
else if (c == 'x' || c == 'X') {
data.setEventChar(0); // Discard character
log.append("Blocked 'x'\n");
}
// Convert to uppercase
else if (Character.isLowerCase(c)) {
data.setEventChar(Character.toUpperCase(c));
}
}
};
public void render() {
if (ImGui.begin("Input Callback Demo")) {
ImGui.text("Type something (h→!, x=blocked, auto uppercase):");
ImGui.inputText("##input", input,
ImGuiInputTextFlags.CallbackCharFilter |
ImGuiInputTextFlags.CallbackResize,
callback);
ImGui.separator();
ImGui.textWrapped(log.toString());
}
ImGui.end();
}
}
```
--------------------------------
### Create and Manage ImGui Windows in Java
Source: https://context7.com/spair/imgui-java/llms.txt
Demonstrates how to create and manage GUI windows using ImGui Java. It shows basic window creation with `ImGui.begin()` and `ImGui.end()`, and how to configure windows with flags like `AlwaysAutoResize`. Requires the `imgui-java` library.
```java
import imgui.ImGui;
import imgui.flag.ImGuiWindowFlags;
import imgui.type.ImBoolean;
public class WindowExample {
private final ImBoolean showWindow = new ImBoolean(true);
public void render() {
// Simple window
if (ImGui.begin("My Window")) {
ImGui.text("Hello, World!");
}
ImGui.end();
// Window with close button and flags
if (ImGui.begin("Resizable Window", showWindow, ImGuiWindowFlags.AlwaysAutoResize)) {
ImGui.text("This window auto-resizes to content");
if (ImGui.button("Click Me")) {
System.out.println("Button clicked!");
}
}
ImGui.end();
}
}
```
--------------------------------
### Create ImGui Java Application
Source: https://context7.com/spair/imgui-java/llms.txt
Demonstrates how to create a basic ImGui application using the `imgui.app.Application` class. This involves extending the `Application` class, configuring window settings, and implementing the `process` method for rendering UI elements and handling user interactions. It also shows how to launch the application.
```java
import imgui.ImGui;
import imgui.app.Application;
import imgui.app.Configuration;
public class MyApplication extends Application {
private int counter = 0;
@Override
protected void configure(Configuration config) {
config.setTitle("My ImGui Application");
config.setWidth(1280);
config.setHeight(720);
}
@Override
public void process() {
// This method is called every frame
if (ImGui.begin("Main Window")) {
ImGui.text("Hello from ImGui Java!");
if (ImGui.button("Increment")) {
counter++;
}
ImGui.text("Counter: " + counter);
// Show FPS
ImGui.text(String.format("FPS: %.1f", ImGui.getIO().getFramerate()));
}
ImGui.end();
}
public static void main(String[] args) {
launch(new MyApplication());
System.exit(0);
}
}
```
--------------------------------
### Create a Basic imgui-java Application
Source: https://github.com/spair/imgui-java/blob/main/README.md
This Java code snippet shows a minimal imgui-java application. It extends the `Application` class, configures the window title, and displays 'Hello, World!' using `ImGui.text()`. The `main` method is responsible for launching the application.
```java
import imgui.ImGui;
import imgui.app.Application;
import imgui.app.Configuration;
public class Main extends Application {
@Override
protected void configure(Configuration config) {
config.setTitle("Dear ImGui is Awesome!");
}
@Override
public void process() {
ImGui.text("Hello, World!");
}
public static void main(String[] args) {
launch(new Main());
}
}
```
--------------------------------
### Manual OpenGL Integration with LWJGL3 in Java
Source: https://context7.com/spair/imgui-java/llms.txt
Sets up direct GLFW and OpenGL integration using the `imgui-lwjgl3` module for applications needing fine-grained control. Initializes LWJGL3 window, ImGui context, and the rendering loop. Depends on LWJGL3 and imgui-java.
```java
import imgui.ImGui;
import imgui.ImGuiIO;
import imgui.gl3.ImGuiImplGl3;
import imgui.glfw.ImGuiImplGlfw;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
public class ManualIntegration {
private long window;
private final ImGuiImplGlfw imGuiGlfw = new ImGuiImplGlfw();
private final ImGuiImplGl3 imGuiGl3 = new ImGuiImplGl3();
public void run() {
initWindow();
initImGui();
loop();
dispose();
}
private void initWindow() {
if (!glfwInit()) {
throw new IllegalStateException("Failed to initialize GLFW");
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
window = glfwCreateWindow(1280, 720, "ImGui LWJGL3", 0, 0);
if (window == 0) {
throw new RuntimeException("Failed to create window");
}
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
GL.createCapabilities();
}
private void initImGui() {
ImGui.createContext();
final ImGuiIO io = ImGui.getIO();
io.addConfigFlags(ImGuiConfigFlags.DockingEnable);
io.addConfigFlags(ImGuiConfigFlags.ViewportsEnable);
imGuiGlfw.init(window, true);
imGuiGl3.init("#version 330 core");
}
private void loop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
imGuiGlfw.newFrame();
ImGui.newFrame();
// Your ImGui code here
if (ImGui.begin("Debug")) {
ImGui.text("FPS: " + String.format("%.1f", ImGui.getIO().getFramerate()));
}
ImGui.end();
ImGui.render();
imGuiGl3.renderDrawData(ImGui.getDrawData());
if (ImGui.getIO().hasConfigFlags(ImGuiConfigFlags.ViewportsEnable)) {
glfwMakeContextCurrent(window);
}
glfwSwapBuffers(window);
}
}
private void dispose() {
imGuiGl3.dispose();
imGuiGlfw.dispose();
ImGui.destroyContext();
glfwDestroyWindow(window);
glfwTerminate();
}
}
```
--------------------------------
### Configure ImGuiIO for Enhanced Features in Java
Source: https://context7.com/spair/imgui-java/llms.txt
Shows how to initialize and configure the `ImGuiIO` object in Java for various features like disabling the .ini file, enabling keyboard navigation, docking, and multi-viewports. It also demonstrates FreeType font rendering and loading custom fonts. Requires `imgui-java` and its dependencies.
```java
import imgui.ImGui;
import imgui.ImGuiIO;
import imgui.ImFontConfig;
import imgui.flag.ImGuiConfigFlags;
public class ImGuiInitialization {
public void initialize() {
final ImGuiIO io = ImGui.getIO();
// Disable saving window positions to .ini file
io.setIniFilename(null);
// Enable keyboard navigation
io.addConfigFlags(ImGuiConfigFlags.NavEnableKeyboard);
// Enable docking support
io.addConfigFlags(ImGuiConfigFlags.DockingEnable);
// Enable multi-viewport / platform windows
io.addConfigFlags(ImGuiConfigFlags.ViewportsEnable);
io.setConfigViewportsNoTaskBarIcon(true);
// Configure fonts with FreeType renderer
io.getFonts().setFreeTypeRenderer(true);
io.getFonts().addFontDefault();
// Add custom font
final ImFontConfig fontConfig = new ImFontConfig();
fontConfig.setMergeMode(true);
io.getFonts().addFontFromFileTTF("fonts/custom.ttf", 16, fontConfig);
io.getFonts().build();
fontConfig.destroy(); // Free native memory
}
}
```
--------------------------------
### Build Node Graphs with ImNodes Extension in Java
Source: https://context7.com/spair/imgui-java/llms.txt
Demonstrates building a node editor graph using the ImNodes extension for ImGui Java. It initializes the ImNodes context and renders multiple nodes with input and output attributes, along with links between them. This is useful for creating visual programming interfaces or flow editors.
```java
import imgui.ImGui;
import imgui.extension.imnodes.ImNodes;
import imgui.extension.imnodes.flag.ImNodesColorStyle;
public class NodeEditorExample {
static {
ImNodes.createContext();
}
public void render() {
if (ImGui.begin("Node Editor")) {
ImNodes.beginNodeEditor();
// Node 1
ImNodes.beginNode(1);
ImNodes.beginNodeTitleBar();
ImGui.text("Input Node");
ImNodes.endNodeTitleBar();
ImNodes.beginOutputAttribute(2);
ImGui.text("Output");
ImNodes.endOutputAttribute();
ImNodes.endNode();
// Node 2
ImNodes.beginNode(3);
ImNodes.beginNodeTitleBar();
ImGui.text("Process Node");
ImNodes.endNodeTitleBar();
ImNodes.beginInputAttribute(4);
ImGui.text("Input");
ImNodes.endInputAttribute();
ImNodes.beginOutputAttribute(5);
ImGui.text("Output");
ImNodes.endOutputAttribute();
ImNodes.endNode();
// Node 3
ImNodes.beginNode(6);
ImNodes.beginNodeTitleBar();
ImGui.text("Output Node");
ImNodes.endNodeTitleBar();
ImNodes.beginInputAttribute(7);
ImGui.text("Input");
ImNodes.endInputAttribute();
ImNodes.endNode();
// Create links
ImNodes.link(0, 2, 4); // Output of Node 1 to Input of Node 2
ImNodes.link(1, 5, 7); // Output of Node 2 to Input of Node 3
ImNodes.endNodeEditor();
}
ImGui.end();
}
}
```
--------------------------------
### Vendor FreeType for imgui-java
Source: https://github.com/spair/imgui-java/blob/main/README.md
Prepares the FreeType library for static compilation into the imgui-java project. This script needs to be executed before building the libraries with FreeType support. It configures FreeType to be included directly within your project build.
```bash
buildSrc/scripts/vendor_freetype.sh
```
--------------------------------
### Create Plots and Charts with ImPlot in Java
Source: https://context7.com/spair/imgui-java/llms.txt
Demonstrates how to create various types of plots and charts (line, scatter, bar, pie, heatmap) using the ImPlot library within a Java ImGui application. Requires imgui-java and ImPlot extensions.
```java
import imgui.ImGui;
import imgui.extension.implot.ImPlot;
import imgui.extension.implot.ImPlotPoint;
public class PlotExample {
private final double[] xData = {0, 1, 2, 3, 4, 5};
private final double[] yData = {0, 1, 4, 9, 16, 25};
private final double[] yData2 = {0, 2, 4, 6, 8, 10};
static {
ImPlot.createContext(); // Initialize ImPlot
}
public void render() {
if (ImGui.begin("Plot Demo")) {
// Line plot
if (ImPlot.beginPlot("Quadratic Function")) {
ImPlot.plotLine("y = x²", xData, yData);
ImPlot.plotLine("y = 2x", xData, yData2);
ImPlot.endPlot();
}
// Scatter plot
if (ImPlot.beginPlot("Scatter Data")) {
ImPlot.plotScatter("Points", xData, yData);
ImPlot.endPlot();
}
// Bar chart
if (ImPlot.beginPlot("Bar Chart")) {
ImPlot.plotBars("Values", xData, yData);
ImPlot.endPlot();
}
// Pie chart
if (ImPlot.beginPlot("Distribution")) {
String[] labels = {"A", "B", "C", "D", "E"};
int[] values = {10, 20, 30, 25, 15};
ImPlot.plotPieChart(labels, values, 0.5, 0.5, 0.4);
ImPlot.endPlot();
}
// Heatmap
if (ImPlot.beginPlot("Heatmap")) {
int[] data = {1, 3, 6, 2, 8, 5, 4, 3};
ImPlot.plotHeatmap("Heat", data, 2, 4, 0, 0, "%d",
new ImPlotPoint(0, 0), new ImPlotPoint(10, 10));
ImPlot.endPlot();
}
}
ImGui.end();
}
}
```
--------------------------------
### Build Native Libraries for Linux
Source: https://github.com/spair/imgui-java/blob/main/README.md
Command to build native libraries for imgui-java on Linux. Requires openjdk8, mingw-w64-gcc, and ant. The '-Dlocal' flag is always required.
```bash
./gradlew imgui-binding:generateLibs -Denvs=linux -Dlocal
```
--------------------------------
### Build Native Libraries for Windows
Source: https://github.com/spair/imgui-java/blob/main/README.md
Command to build native libraries for imgui-java on Windows. Requires JDK 8+, Ant, and Mingw-w64 (via MSYS2). The '-Dlocal' flag is always required.
```bash
./gradlew imgui-binding:generateLibs -Denvs=windows -Dlocal
```
--------------------------------
### Add imgui-java Dependencies with Gradle
Source: https://github.com/spair/imgui-java/blob/main/README.md
This snippet shows how to configure Gradle to include imgui-java, LWJGL, and Windows native libraries. It defines versions for LWJGL and imgui-java, then adds the necessary implementation dependencies, including platform-specific natives.
```gradle
repositories {
mavenCentral()
}
ext {
lwjglVersion = '3.3.3'
imguiVersion = "${version}"
}
dependencies {
implementation platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
['', '-opengl', '-glfw'].each {
implementation "org.lwjgl:lwjgl$it:$lwjglVersion"
implementation "org.lwjgl:lwjgl$it::natives-windows"
}
implementation "io.github.spair:imgui-java-binding:$imguiVersion"
implementation "io.github.spair:imgui-java-lwjgl3:$imguiVersion"
implementation "io.github.spair:imgui-java-natives-windows:$imguiVersion"
}
```
--------------------------------
### Configure Native Library Path for Raw JARs
Source: https://github.com/spair/imgui-java/blob/main/README.md
This section explains how to use raw JAR files for imgui-java and LWJGL. It involves downloading specific JARs and native libraries from releases, adding them to the classpath, and setting VM options to specify the location of native libraries.
```bash
-Dimgui.library.path=_${path}_
-Djava.library.path=_${path}_
```
--------------------------------
### Implement Basic GUI Widgets in Java with ImGui
Source: https://context7.com/spair/imgui-java/llms.txt
Illustrates the use of fundamental GUI widgets in ImGui Java, including buttons, text input fields, integer inputs, and float sliders. It highlights the use of wrapper types for mutable values like `ImString`, `ImInt`, and `ImFloat`. This requires the `imgui-java` library.
```java
import imgui.ImGui;
import imgui.flag.ImGuiInputTextFlags;
import imgui.type.ImString;
import imgui.type.ImInt;
import imgui.type.ImFloat;
public class WidgetExample {
private final ImString textInput = new ImString("Initial text", 256);
private final ImInt intValue = new ImInt(42);
private final ImFloat floatValue = new ImFloat(3.14f);
private int clickCount = 0;
public void render() {
if (ImGui.begin("Widget Demo")) {
// Button
if (ImGui.button("Save")) {
clickCount++;
}
ImGui.sameLine();
ImGui.text("Clicked: " + clickCount);
// Text input with auto-resize
ImGui.inputText("Name", textInput, ImGuiInputTextFlags.CallbackResize);
ImGui.text("Result: " + textInput.get());
// Integer input
ImGui.inputInt("Count", intValue);
// Float slider
ImGui.sliderFloat("Value", floatValue.getData(), 0.0f, 10.0f);
ImGui.separator();
ImGui.text("Summary: " + textInput.get() + ", Count: " +
intValue.get() + ", Value: " + floatValue.get());
}
ImGui.end();
}
}
```
--------------------------------
### Add imgui-java Dependencies with Maven
Source: https://github.com/spair/imgui-java/blob/main/README.md
This snippet demonstrates how to configure Maven for imgui-java integration, including LWJGL and Windows native libraries. It sets versions in properties, manages LWJGL BOM, and lists all required dependencies with classifier for native libraries.
```maven
3.3.1
${version}
org.lwjgl
lwjgl-bom
${lwjgl.version}
import
pom
org.lwjgl
lwjgl
org.lwjgl
lwjgl-glfw
org.lwjgl
lwjgl-opengl
org.lwjgl
lwjgl
natives-windows
org.lwjgl
lwjgl-glfw
natives-windows
org.lwjgl
lwjgl-opengl
natives-windows
io.github.spair
imgui-java-binding
${imgui.java.version}
io.github.spair
imgui-java-lwjgl3
${imgui.java.version}
io.github.spair
imgui-java-natives-windows
${imgui.java.version}
```
--------------------------------
### Add imgui-java Dependency with Gradle
Source: https://github.com/spair/imgui-java/blob/main/README.md
This Gradle configuration snippet shows how to add the imgui-java application binding to your project. It specifies the `mavenCentral()` repository and the `imgui-java-app` dependency with a placeholder for the version.
```gradle
repositories {
mavenCentral()
}
dependencies {
implementation "io.github.spair:imgui-java-app:${version}"
}
```
--------------------------------
### Add imgui-java Dependency with Maven
Source: https://github.com/spair/imgui-java/blob/main/README.md
This Maven dependency configuration snippet illustrates how to include the imgui-java application binding in your project. It defines the `imgui-java-app` artifact with a placeholder for the version within the `` section.
```xml
io.github.spair
imgui-java-app
${version}
```
--------------------------------
### Implement Drag and Drop in ImGui Java
Source: https://context7.com/spair/imgui-java/llms.txt
Illustrates how to implement drag and drop functionality in ImGui Java. This includes creating drag sources with payloads and drop targets that can accept these payloads. It shows handling both string-based and custom class payloads for data transfer between UI elements.
```java
import imgui.ImGui;
import imgui.flag.ImGuiDragDropFlags;
import imgui.type.ImString;
public class DragDropExample {
private final ImString sourceText = new ImString("Drag me!", 256);
private String targetText = "Drop here";
public void render() {
if (ImGui.begin("Drag & Drop")) {
// Drag source
ImGui.inputText("Source", sourceText);
if (ImGui.beginDragDropSource(ImGuiDragDropFlags.None)) {
ImGui.setDragDropPayload("TEXT_DATA", sourceText.get());
ImGui.text("Dragging: " + sourceText.get());
ImGui.endDragDropSource();
}
ImGui.separator();
// Drop target
ImGui.button(targetText, 200, 50);
if (ImGui.beginDragDropTarget()) {
String payload = ImGui.acceptDragDropPayload("TEXT_DATA");
if (payload != null) {
targetText = payload;
}
ImGui.endDragDropTarget();
}
// Type-safe class-specific payload
ImGui.button("Class Payload");
if (ImGui.beginDragDropSource()) {
ImGui.setDragDropPayload(new CustomData("value"));
ImGui.endDragDropSource();
}
if (ImGui.beginDragDropTarget()) {
CustomData data = ImGui.acceptDragDropPayload(CustomData.class);
if (data != null) {
System.out.println("Received: " + data.getValue());
}
ImGui.endDragDropTarget();
}
}
ImGui.end();
}
private static class CustomData {
private final String value;
public CustomData(String value) { this.value = value; }
public String getValue() { return value; }
}
}
```
--------------------------------
### Enable FreeType Renderer in imgui-java
Source: https://github.com/spair/imgui-java/blob/main/README.md
Demonstrates how to enable the FreeType font renderer in imgui-java before the font atlas is generated. This allows for the use of ImGuiFreeTypeBuilderFlags in font configurations.
```java
ImGuiIO io = ImGui.getIO();
io.setFontAtlas(ImGui.getImFontAtlas());
ImGui.getImFontAtlas().setFreeTypeRenderer(true);
```
--------------------------------
### Load Custom Fonts with ImGui Java
Source: https://context7.com/spair/imgui-java/llms.txt
Loads custom fonts (e.g., Roboto, FontAwesome) into ImGui using FreeType rendering for higher quality. It supports building custom glyph ranges for different languages and merges multiple fonts. Dependencies include ImGui IO, ImFontConfig, and ImFontGlyphRangesBuilder. It reads font data from TTF files and expects font files to be present at the specified paths.
```java
import imgui.ImGui;
import imgui.ImGuiIO;
import imgui.ImFontConfig;
import imgui.ImFontGlyphRangesBuilder;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class FontExample {
public void loadFonts() {
final ImGuiIO io = ImGui.getIO();
// Enable FreeType for better quality
io.getFonts().setFreeTypeRenderer(true);
// Add default font
io.getFonts().addFontDefault();
// Build custom glyph ranges
final ImFontGlyphRangesBuilder rangesBuilder = new ImFontGlyphRangesBuilder();
rangesBuilder.addRanges(io.getFonts().getGlyphRangesDefault());
rangesBuilder.addRanges(io.getFonts().getGlyphRangesCyrillic());
rangesBuilder.addRanges(io.getFonts().getGlyphRangesJapanese());
// Font config for merging
final ImFontConfig fontConfig = new ImFontConfig();
fontConfig.setMergeMode(true);
fontConfig.setPixelSnapH(true);
// Load custom fonts
short[] glyphRanges = rangesBuilder.buildRanges();
try {
byte[] fontData = Files.readAllBytes(Paths.get("fonts/Roboto.ttf"));
io.getFonts().addFontFromMemoryTTF(fontData, 16, fontConfig, glyphRanges);
byte[] iconData = Files.readAllBytes(Paths.get("fonts/FontAwesome.ttf"));
io.getFonts().addFontFromMemoryTTF(iconData, 16, fontConfig, glyphRanges);
} catch (IOException e) {
e.printStackTrace();
}
io.getFonts().build();
fontConfig.destroy(); // Important: free native memory
}
}
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.