From dcadd6e364b0226bf55e88d8143814f8270efbd6 Mon Sep 17 00:00:00 2001 From: dinau Date: Thu, 5 Dec 2024 15:10:54 +0900 Subject: [PATCH] Updated ImGui / CImGui to 1.91.5 --- README.md | 24 ++++++++++++------- examples/glfw_opengl3/imgui.ini | 2 +- examples/glfw_opengl3/src/main.zig | 8 +++---- examples/glfw_opengl3_image_load/src/main.zig | 6 ++--- examples/glfw_opengl3_implot/src/main.zig | 6 ++--- examples/glfw_opengl3_jp/src/main.zig | 6 ++--- examples/iconFontViewer/src/main.zig | 7 +++--- examples/imPlotDemo/src/main.zig | 6 ++--- examples/sdl2_opengl3/src/main.zig | 5 ++-- examples/sdl3_opengl3/imgui.ini | 4 ++-- examples/sdl3_opengl3/src/main.zig | 6 ++--- examples/utils/setupFonts.c | 16 ++++--------- examples/utils/utils.c | 3 +++ libs/cimgui | 2 +- 14 files changed, 50 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 26ffed2..6b6853e 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ - [Build and run](#build-and-run) - [Examples screen shots](#examples-screen-shots) - [Image load](#image-load) - - [Showing CJK fonts and text input](#showing-cjk-fonts-and-text-input) + - [Showing CJK multi byte fonts and input UTF-8 text](#showing-cjk-multi-byte-fonts-and-input-utf-8-text) - [Icon font viewer](#icon-font-viewer) - [Image load / save](#image-load--save) - [glfw_opengl3_implot](#glfw_opengl3_implot) @@ -41,7 +41,13 @@ This project aims to simply and easily build [Dear ImGui](https://github.com/oco [(CImGui)](https://github.com/cimgui/cimgui) / [ImPlot](https://github.com/epezent/implot) [(CImPlot)](https://github.com/cimgui/cimplot) examples in Zig language with less external dependencies. -ImGui / CImGui version **1.91.4dock** (2024/10) +- ImGui / CImGui version **1.91.5dock** (2024/12) +- OS: Windows and Linux +- Frontends and Backends + + | | GLFW | SDL2 | SDL3 | + | --- | :----: | :---- | :----: | + | OpenGL3
backend | v | v | v | - Features - Included [Font Awesome](https://fontawesome.com/search?m=free&o=r) Icon fonts. @@ -57,11 +63,12 @@ ImGui / CImGui version **1.91.4dock** (2024/10) --- -- Zig version +- Zig version + Probably [zig-windows-x86_64-0.14.0-dev.xxxx+yyyy...](https://ziglang.org/download/) might all be OK + 1. Zig: 0.14.0-dev.2367+aa7d13846 is OK (2024/12) 1. zig-windows-x86_64-0.14.0-dev.2265 is OK (2024/11/21) 1. [zig-windows-x86_64-0.14.0-dev.2183+ee9f00d67.zip](https://ziglang.org/builds/zig-windows-x86_64-0.14.0-dev.2183+ee9f00d67.zip) OK 1. [zig-linux-x86_64-0.14.0-dev.2183+ee9f00d67.tar.xz](https://ziglang.org/builds/zig-linux-x86_64-0.14.0-dev.2183+ee9f00d67.tar.xz) OK - Probably [zig-windows-x86_64-0.14.0-dev.xxxx+yyyy...](https://ziglang.org/download/) might be OK 1. zig-0.12.1 and zig-0.13.0 are OK - WindowsOS @@ -117,7 +124,7 @@ Image load and magnifying glass ![alt](https://github.com/dinau/imguinz/raw/main/img/sdl2_opengl3.png) -#### Showing CJK fonts and text input +#### Showing CJK multi byte fonts and input UTF-8 text --- @@ -137,13 +144,13 @@ Image load and magnifying glass --- -Image load / save and magnifying glass +Image load / save and magnifying glass. +Image file captured would be saved in .the folder `./zig-out/bin`. +Image can be saved as `JPEG / PNG / BMP / TGA` file. [glfw_opengl3_image_load.zig](https://github.com/dinau/imguinz/raw/main/examples/glfw_opengl3_image_load/src/main.zig) ![alt](https://github.com/dinau/imguinz/raw/main/img/glfw_opengl3_image_load.png) -Image file captured would be saved in the folder `./zig-out/bin`. -Image can be saved as `JPEG / PNG / BMP / TGA` file. #### glfw_opengl3_implot @@ -298,3 +305,4 @@ https://github.com/JBetz/build-sdl3-win32 | **Nim** | Compiler | [Nim-Platformer](https://github.com/dinau/nim-platformer) | | **LuaJIT** | Script | [LuaJIT-Platformer](https://github.com/dinau/luajit-platformer) | | **Nelua** | Compiler | [NeLua-Platformer](https://github.com/dinau/nelua-platformer) | +| **Zig** | Compiler | [Zig-Platformer](https://github.com/dinau/zig-platformer) (WIP) | diff --git a/examples/glfw_opengl3/imgui.ini b/examples/glfw_opengl3/imgui.ini index bb5e5b2..e664f66 100644 --- a/examples/glfw_opengl3/imgui.ini +++ b/examples/glfw_opengl3/imgui.ini @@ -39,7 +39,7 @@ Size=382,342 Collapsed=0 [Window][ Dear ImGui] -Pos=9,7 +Pos=10,9 Size=416,340 Collapsed=0 diff --git a/examples/glfw_opengl3/src/main.zig b/examples/glfw_opengl3/src/main.zig index 75259b4..52ed926 100644 --- a/examples/glfw_opengl3/src/main.zig +++ b/examples/glfw_opengl3/src/main.zig @@ -4,7 +4,7 @@ const ig = @import ("imgui.zig"); const fonts = @import("fonts.zig"); const utils = @import("utils.zig"); -const IMGUI_HAS_DOCK = false; // true: Can't compile at this time. +const IMGUI_HAS_DOCK = false; // Docking feature fn glfw_error_callback(err: c_int, description: [*c]const u8) callconv(.C) void { std.debug.print ("GLFW Error {d}: {s}\n", .{ err, description }); @@ -138,7 +138,7 @@ pub fn main () !void { var textureHeight : c_int = 0; _ = ig.LoadTextureFromFile(ImageName, &textureId, &textureWidth, &textureHeight); fonts.setupFonts(); // Setup CJK fonts and Icon fonts - + var zoomTextureID: ig.GLuint = 0; //# Must be == 0 at first defer ig.glDeleteTextures(1, &zoomTextureID); @@ -247,10 +247,10 @@ pub fn main () !void { ig.ImGui_ImplOpenGL3_RenderDrawData(ig.igGetDrawData()); // Docking featrue --- N/A if (IMGUI_HAS_DOCK){ - if (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewPortsEnable) { + if (0 != (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewportsEnable)) { const backup_current_window = ig.glfwGetCurrentContext(); ig.igUpdatePlatformWindows(); - ig.igRenderPlatformWindowsDefault(); + ig.igRenderPlatformWindowsDefault(null, null); ig.glfwMakeContextCurrent(backup_current_window); } } diff --git a/examples/glfw_opengl3_image_load/src/main.zig b/examples/glfw_opengl3_image_load/src/main.zig index 5ae06b2..0c224c0 100644 --- a/examples/glfw_opengl3_image_load/src/main.zig +++ b/examples/glfw_opengl3_image_load/src/main.zig @@ -22,7 +22,7 @@ var cbItemIndex:usize = @intFromEnum(enKind.jpg); // Constants const SaveImageName = "ImageSaved"; -const IMGUI_HAS_DOCK = false; // true: Can't compile at this time. +const IMGUI_HAS_DOCK = false; // Docking feature fn glfw_error_callback (err: c_int, description: [*c] const u8) callconv (.C) void { @@ -309,10 +309,10 @@ pub fn main () !void { ig.ImGui_ImplOpenGL3_RenderDrawData(ig.igGetDrawData()); // Docking featrue --- N/A if (IMGUI_HAS_DOCK){ - if (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewPortsEnable) { + if (0 != (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewportsEnable)) { const backup_current_window = ig.glfwGetCurrentContext(); ig.igUpdatePlatformWindows(); - ig.igRenderPlatformWindowsDefault(); + ig.igRenderPlatformWindowsDefault(null, null); ig.glfwMakeContextCurrent(backup_current_window); } } diff --git a/examples/glfw_opengl3_implot/src/main.zig b/examples/glfw_opengl3_implot/src/main.zig index 6d4f7fd..43c828f 100644 --- a/examples/glfw_opengl3_implot/src/main.zig +++ b/examples/glfw_opengl3_implot/src/main.zig @@ -8,7 +8,7 @@ pub const c = @cImport({ @cInclude("stdlib.h"); }); -const IMGUI_HAS_DOCK = false; // true: Can't compile at this time. +const IMGUI_HAS_DOCK = false; // Docking feature fn glfw_error_callback(err: c_int, description: [*c]const u8) callconv(.C) void { std.debug.print("GLFW Error {d}: {s}\n", .{ err, description }); @@ -238,10 +238,10 @@ pub fn main() !void { ig.ImGui_ImplOpenGL3_RenderDrawData(ig.igGetDrawData()); // Docking featrue --- N/A if (IMGUI_HAS_DOCK) { - if (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewPortsEnable) { + if (0 != (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewportsEnable)) { const backup_current_window = ig.glfwGetCurrentContext(); ig.igUpdatePlatformWindows(); - ig.igRenderPlatformWindowsDefault(); + ig.igRenderPlatformWindowsDefault(null, null); ig.glfwMakeContextCurrent(backup_current_window); } } diff --git a/examples/glfw_opengl3_jp/src/main.zig b/examples/glfw_opengl3_jp/src/main.zig index 2822db2..1b3fff3 100644 --- a/examples/glfw_opengl3_jp/src/main.zig +++ b/examples/glfw_opengl3_jp/src/main.zig @@ -3,7 +3,7 @@ const builtin = @import ("builtin"); const ig = @import ("imgui.zig"); const fonts = @import("fonts.zig"); -const IMGUI_HAS_DOCK = false; // true: Can't compile at this time. +const IMGUI_HAS_DOCK = false; // Docking feature fn glfw_error_callback(err: c_int, description: [*c]const u8) callconv(.C) void { std.debug.print ("GLFW Error {d}: {s}\n", .{ err, description }); @@ -213,10 +213,10 @@ pub fn main () !void { ig.ImGui_ImplOpenGL3_RenderDrawData(ig.igGetDrawData()); // Docking featrue --- N/A if (IMGUI_HAS_DOCK){ - if (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewPortsEnable) { + if (0 != (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewportsEnable)) { const backup_current_window = ig.glfwGetCurrentContext(); ig.igUpdatePlatformWindows(); - ig.igRenderPlatformWindowsDefault(); + ig.igRenderPlatformWindowsDefault(null, null); ig.glfwMakeContextCurrent(backup_current_window); } } diff --git a/examples/iconFontViewer/src/main.zig b/examples/iconFontViewer/src/main.zig index 74970e9..24359c0 100644 --- a/examples/iconFontViewer/src/main.zig +++ b/examples/iconFontViewer/src/main.zig @@ -6,7 +6,7 @@ const fonts = @import("fonts.zig"); const ift = @import("iconFontsTblDef.zig"); const utils = @import("utils.zig"); -const IMGUI_HAS_DOCK = false; // true: Can't compile at this time. +const IMGUI_HAS_DOCK = false; // Docking feature fn glfw_error_callback(err: c_int, description: [*c]const u8) callconv(.C) void { std.debug.print ("GLFW Error {d}: {s}\n", .{ err, description }); @@ -75,7 +75,6 @@ pub fn main () !void { const allocator = gpa.allocator(); const exe_path = try std.fs.selfExePathAlloc(allocator); defer allocator.free(exe_path); - // const opt_exe_dir = std.fs.path.dirname(exe_path); if (opt_exe_dir) |exe_dir| { var paths = [_][]const u8{ exe_dir, TitleBarIconName }; @@ -221,10 +220,10 @@ pub fn main () !void { ig.ImGui_ImplOpenGL3_RenderDrawData(ig.igGetDrawData()); // Docking featrue --- N/A if (IMGUI_HAS_DOCK){ - if (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewPortsEnable) { + if (0 != (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewportsEnable)) { const backup_current_window = ig.glfwGetCurrentContext(); ig.igUpdatePlatformWindows(); - ig.igRenderPlatformWindowsDefault(); + ig.igRenderPlatformWindowsDefault(null, null); ig.glfwMakeContextCurrent(backup_current_window); } } diff --git a/examples/imPlotDemo/src/main.zig b/examples/imPlotDemo/src/main.zig index b19510c..93bfe4c 100644 --- a/examples/imPlotDemo/src/main.zig +++ b/examples/imPlotDemo/src/main.zig @@ -9,7 +9,7 @@ pub const c = @cImport ({ @cInclude ("stdlib.h"); }); -const IMGUI_HAS_DOCK = false; // true: Can't compile at this time. +const IMGUI_HAS_DOCK = false; // Docking feature fn glfw_error_callback (err: c_int, description: [*c] const u8) callconv (.C) void { @@ -235,10 +235,10 @@ pub fn main () !void { ig.ImGui_ImplOpenGL3_RenderDrawData(ig.igGetDrawData()); // Docking featrue --- N/A if (IMGUI_HAS_DOCK){ - if (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewPortsEnable) { + if (0 != (pio.*.ConfigFlags & ig.ImGuiConfigFlags_ViewportsEnable)) { const backup_current_window = ig.glfwGetCurrentContext(); ig.igUpdatePlatformWindows(); - ig.igRenderPlatformWindowsDefault(); + ig.igRenderPlatformWindowsDefault(null, null); ig.glfwMakeContextCurrent(backup_current_window); } } diff --git a/examples/sdl2_opengl3/src/main.zig b/examples/sdl2_opengl3/src/main.zig index b6e044c..74a17f0 100644 --- a/examples/sdl2_opengl3/src/main.zig +++ b/examples/sdl2_opengl3/src/main.zig @@ -5,7 +5,7 @@ const fonts = @import ("fonts.zig"); const utils = @import("utils.zig"); -const IMGUI_HAS_DOCK = false; // true: Can't compile at this time. +const IMGUI_HAS_DOCK = false; // Docking feature const MainWinWidth :i32 = 1024; const MainWinHeight:i32 = 800; @@ -217,10 +217,9 @@ pub fn main () !void { } } - //----------- - // End procs //----------- // Rendering + //----------- ig.igRender (); ig.glViewport(0, 0, @intFromFloat(pio.*.DisplaySize.x), @intFromFloat(pio.*.DisplaySize.y)); ig.glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); diff --git a/examples/sdl3_opengl3/imgui.ini b/examples/sdl3_opengl3/imgui.ini index e549a65..c518753 100644 --- a/examples/sdl3_opengl3/imgui.ini +++ b/examples/sdl3_opengl3/imgui.ini @@ -34,12 +34,12 @@ Size=339,180 Collapsed=0 [Window][ ImGui: Dear Bindings] -Pos=11,5 +Pos=12,5 Size=414,343 Collapsed=0 [Window][Image load test] -Pos=9,355 +Pos=13,355 Size=416,435 Collapsed=0 diff --git a/examples/sdl3_opengl3/src/main.zig b/examples/sdl3_opengl3/src/main.zig index 7e41794..b1bf48b 100644 --- a/examples/sdl3_opengl3/src/main.zig +++ b/examples/sdl3_opengl3/src/main.zig @@ -5,7 +5,7 @@ const ig= @import ("imgui.zig"); const fonts = @import ("fonts.zig"); const utils = @import("utils.zig"); -const IMGUI_HAS_DOCK = false; // true: Can't compile at this time. +const IMGUI_HAS_DOCK = false; // Docking feature const MainWinWidth :i32 = 1024; const MainWinHeight:i32 = 800; @@ -212,11 +212,9 @@ pub fn main () !void { utils.zoomGlass(&zoomTextureID, textureWidth, imageBoxPosTop, imageBoxPosEnd); } } - - //----------- - // End procs //----------- // Rendering + //----------- ig.igRender (); ig.glViewport(0, 0, @intFromFloat(pio.*.DisplaySize.x), @intFromFloat(pio.*.DisplaySize.y)); ig.glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]); diff --git a/examples/utils/setupFonts.c b/examples/utils/setupFonts.c index e2883b6..eee4f8f 100644 --- a/examples/utils/setupFonts.c +++ b/examples/utils/setupFonts.c @@ -38,16 +38,6 @@ float point2px(float point) { return (point * 96) / 72; } -const ImFontConfig config = {.FontDataOwnedByAtlas = true - , .FontNo = 0 - , .OversampleH = 3 - , .OversampleV = 2 - , .PixelSnapH = false - , .GlyphMaxAdvanceX = FLT_MAX - , .RasterizerMultiply = 1.0 - , .RasterizerDensity = 1.0 - , .MergeMode = true - , .EllipsisChar = (ImWchar)-1}; const ImWchar ranges_icon_fonts[] = {(ImWchar)ICON_MIN_FA, (ImWchar)ICON_MAX_FA, (ImWchar)0}; /*-------------- * setupFonts() @@ -55,7 +45,9 @@ const ImWchar ranges_icon_fonts[] = {(ImWchar)ICON_MIN_FA, (ImWchar)ICON_MAX_FA void setupFonts(void) { ImGuiIO* pio = ImGui_GetIO(); ImFontAtlas_AddFontDefault(pio->Fonts, NULL); - ImFontAtlas_AddFontFromFileTTF(pio->Fonts, IconFontPath, point2px(10), &config , ranges_icon_fonts); + ImFontConfig* config = ImFontConfig_ImFontConfig(); + config->MergeMode = true; + ImFontAtlas_AddFontFromFileTTF(pio->Fonts, IconFontPath, point2px(10), config , ranges_icon_fonts); char* fontPath = getWinFontPath(sBufFontPath, sizeof(sBufFontPath), WinJpFontName); if (existsFile(fontPath)) { @@ -72,7 +64,7 @@ void setupFonts(void) { printf("Found JpFontPath: [%s]\n",fontPath); ImFont* font = ImFontAtlas_AddFontFromFileTTF(pio->Fonts, fontPath, point2px(14) - , &config + , config , ImFontAtlas_GetGlyphRangesJapanese(pio->Fonts)); if (font == NULL) { printf("Error!: AddFontFromFileTTF(): [%s] \n", fontPath); diff --git a/examples/utils/utils.c b/examples/utils/utils.c index 6b49446..d464eab 100644 --- a/examples/utils/utils.c +++ b/examples/utils/utils.c @@ -5,6 +5,9 @@ * existFile() * -----------*/ bool existsFile(const char* path) { + if (path == NULL){ + return false; + } FILE* fp = fopen(path, "r"); if (fp == NULL) return false; fclose(fp); diff --git a/libs/cimgui b/libs/cimgui index 7640b00..4e89eac 160000 --- a/libs/cimgui +++ b/libs/cimgui @@ -1 +1 @@ -Subproject commit 7640b00d27e8f7970b496b0cb68a536390d762d9 +Subproject commit 4e89eac9386d8801abe458b50830e406bec31eae