Skip to content

Commit

Permalink
Updated ImGui / CImGui to 1.91.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dinau committed Dec 5, 2024
1 parent 7f91426 commit dcadd6e
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 51 deletions.
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<br>backend | v | v | v |

- Features
- Included [Font Awesome](https://fontawesome.com/search?m=free&o=r) Icon fonts.
Expand All @@ -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
Expand Down Expand Up @@ -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

---

Expand All @@ -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

Expand Down Expand Up @@ -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) |
2 changes: 1 addition & 1 deletion examples/glfw_opengl3/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Size=382,342
Collapsed=0

[Window][ Dear ImGui]
Pos=9,7
Pos=10,9
Size=416,340
Collapsed=0

Expand Down
8 changes: 4 additions & 4 deletions examples/glfw_opengl3/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/glfw_opengl3_image_load/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/glfw_opengl3_implot/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/glfw_opengl3_jp/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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);
}
}
Expand Down
7 changes: 3 additions & 4 deletions examples/iconFontViewer/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/imPlotDemo/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}
Expand Down
5 changes: 2 additions & 3 deletions examples/sdl2_opengl3/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions examples/sdl3_opengl3/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 2 additions & 4 deletions examples/sdl3_opengl3/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
Expand Down
16 changes: 4 additions & 12 deletions examples/utils/setupFonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,16 @@ 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()
*-------------*/
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)) {
Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions examples/utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit dcadd6e

Please sign in to comment.