|
40 | 40 |
|
41 | 41 | @SuppressWarnings("MagicNumber")
|
42 | 42 | public final class ImGuiGlfwExample {
|
43 |
| - private static final int DEFAULT_WIDTH = 1280; |
44 |
| - private static final int DEFAULT_HEIGHT = 768; |
45 |
| - |
46 | 43 | private long window; // current GLFW window pointer
|
47 | 44 |
|
48 | 45 | // Those are used to track window size properties
|
@@ -99,7 +96,7 @@ private void initGlfw() {
|
99 | 96 | glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE); // the window will be maximized
|
100 | 97 |
|
101 | 98 | // Create the window
|
102 |
| - window = glfwCreateWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, "Dear ImGui + GLFW + LWJGL Example", NULL, NULL); |
| 99 | + window = glfwCreateWindow(1280, 768, "Dear ImGui + GLFW + LWJGL Example", NULL, NULL); |
103 | 100 |
|
104 | 101 | if (window == NULL) {
|
105 | 102 | throw new RuntimeException("Failed to create the GLFW window");
|
@@ -149,8 +146,8 @@ private void initImGui() {
|
149 | 146 | io.setIniFilename(null); // We don't want to save .ini file
|
150 | 147 | io.setConfigFlags(ImGuiConfigFlags.NavEnableKeyboard); // Navigation with keyboard
|
151 | 148 | io.setBackendFlags(ImGuiBackendFlags.HasMouseCursors); // Mouse cursors to display while resizing windows etc.
|
152 |
| - io.setBackendPlatformName("imgui_java_impl_glfw"); // For debug purpose |
153 |
| - io.setBackendRendererName("imgui_java_impl_lwjgl"); // For debug purpose |
| 149 | + io.setBackendPlatformName("imgui_java_impl_glfw"); // For clarity reasons |
| 150 | + io.setBackendRendererName("imgui_java_impl_lwjgl"); // For clarity reasons |
154 | 151 |
|
155 | 152 | // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array.
|
156 | 153 | final int[] keyMap = new int[ImGuiKey.COUNT];
|
@@ -249,29 +246,42 @@ public String get() {
|
249 | 246 | // ------------------------------------------------------------
|
250 | 247 | // Fonts configuration
|
251 | 248 |
|
| 249 | + // ------------------- |
| 250 | + // Fonts merge example |
| 251 | + |
252 | 252 | final ImFontAtlas fontAtlas = io.getFonts();
|
253 | 253 |
|
254 |
| - // Dear ImGui uses 'ProggyClean.ttf, 13px' by default |
| 254 | + // First of all we add a default font, which is 'ProggyClean.ttf, 13px' |
255 | 255 | fontAtlas.addFontDefault();
|
256 | 256 |
|
257 | 257 | final ImFontConfig fontConfig = new ImFontConfig(); // Keep in mind that creation of the ImFontConfig will allocate native memory
|
| 258 | + fontConfig.setMergeMode(true); // All fonts added while this mode is turned on will be merged with the previously added font |
| 259 | + fontConfig.setPixelSnapH(true); |
| 260 | + fontConfig.setGlyphRanges(fontAtlas.getGlyphRangesCyrillic()); // Additional glyphs could be added like this or in addFontFrom*() methods |
| 261 | + |
| 262 | + // We merge font loaded from resources with the default one. Thus we will get an absent cyrillic glyphs |
| 263 | + fontAtlas.addFontFromMemoryTTF(loadFromResources("basis33.ttf"), 16, fontConfig); |
| 264 | + |
| 265 | + // Disable merged mode and add all other fonts normally |
| 266 | + fontConfig.setMergeMode(false); |
| 267 | + fontConfig.setPixelSnapH(false); |
| 268 | + |
| 269 | + // ------------------------------ |
| 270 | + // Fonts from file/memory example |
| 271 | + |
258 | 272 | fontConfig.setRasterizerMultiply(1.2f); // This will make fonts a bit more readable
|
259 |
| - fontConfig.setGlyphRanges(fontAtlas.getGlyphRangesCyrillic()); // Additional glyphs could be added like here or in addFontFrom*() methods |
260 | 273 |
|
261 | 274 | // We can add new fonts directly from file
|
262 | 275 | fontAtlas.addFontFromFileTTF("src/test/resources/DroidSans.ttf", 13, fontConfig);
|
263 | 276 | fontAtlas.addFontFromFileTTF("src/test/resources/DroidSans.ttf", 14, fontConfig);
|
264 |
| - fontAtlas.addFontFromFileTTF("src/test/resources/JetBrainsMono-Regular.ttf", 13, fontConfig); |
265 |
| - fontAtlas.addFontFromFileTTF("src/test/resources/JetBrainsMono-Regular.ttf", 14, fontConfig); |
266 | 277 |
|
267 | 278 | // Or directly from memory
|
268 | 279 | fontConfig.setName("Roboto-Regular.ttf, 13px"); // This name will be displayed in Style Editor
|
269 | 280 | fontAtlas.addFontFromMemoryTTF(loadFromResources("Roboto-Regular.ttf"), 13, fontConfig);
|
270 | 281 | fontConfig.setName("Roboto-Regular.ttf, 14px"); // We can apply a new config value every time we add a new font
|
271 | 282 | fontAtlas.addFontFromMemoryTTF(loadFromResources("Roboto-Regular.ttf"), 14, fontConfig);
|
272 | 283 |
|
273 |
| - // After fonts were added and since we won't use fontConfig again - we should clean it |
274 |
| - fontConfig.destroy(); |
| 284 | + fontConfig.destroy(); // After all fonts were added we don't need this config more |
275 | 285 |
|
276 | 286 | // IMPORTANT!!!
|
277 | 287 | // Method initializes renderer itself.
|
|
0 commit comments