Skip to content

Commit f096c7e

Browse files
committed
updated: ImGui / CImGui to 1.92.6
1 parent c29356a commit f096c7e

39 files changed

Lines changed: 17004 additions & 12269 deletions

.github/workflows/linux.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
with:
1717
submodules: 'recursive'
1818
- run: |
19-
sudo apt install xorg-dev libopengl-dev libgl1-mesa-dev
20-
sudo apt install libglfw3 libglfw3-dev libsdl2-dev
19+
sudo apt update
20+
sudo apt install -y xorg-dev libopengl-dev libgl1-mesa-dev
21+
sudo apt install -y libglfw3 libglfw3-dev libsdl2-dev
2122
make

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,13 @@ all:
55
.PHONY: clean
66

77
clean:
8-
$(MAKE) -C demo/c clean
9-
$(MAKE) -C demo/cpp clean
8+
@-$(MAKE) -C demo/c clean
9+
@-$(MAKE) -C demo/cpp clean
10+
11+
CIMGUI_ORG_DIR = ../cimgui
12+
gen:
13+
-rm -fr libs/cimgui
14+
-mkdir -p libs/cimgui/imgui/backends
15+
-cp $(CIMGUI_ORG_DIR)/{cimgui*.*,LICENSE,*.md,Makefile} libs/cimgui/
16+
-cp $(CIMGUI_ORG_DIR)/imgui/*.* libs/cimgui/imgui/
17+
-cp $(CIMGUI_ORG_DIR)/imgui/backends/imgui_impl_{glfw.*,opengl3*} libs/cimgui/imgui/backends/

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
![alt](https://github.com/dinau/cimgui-knobs/actions/workflows/windows.yml/badge.svg)
55
![alt](https://github.com/dinau/cimgui-knobs/actions/workflows/linux.yml/badge.svg)
66

7-
This is a port/adaptation of [ImGui-Knobs](https://github.com/altschuler/imgui-knobs), for C language (contributed to [ImGuin](https://github.com/dinau/imguin) project) by [system64MC](https://github.com/system64MC) at [2024/12](https://github.com/dinau/imguin/issues/16#issuecomment-2538066999).
8-
I've just isolated the sources from ImGuin project for maintenance and convenience and added [a simple demo program in C language](demo/c/main.c).
7+
This is a port/adaptation of [ImGui-Knobs](https://github.com/altschuler/imgui-knobs), for C (contributed to [ImGuin](https://github.com/dinau/imguin) project) by [system64MC](https://github.com/system64MC) at [2024/12](https://github.com/dinau/imguin/issues/16#issuecomment-2538066999).
8+
I've just isolated the sources from ImGuin project for maintenance and convenience and added [a simple demo program in C](demo/c/main.c).
99

1010
![alt](img/cimgui-knobs.png)
1111

@@ -24,15 +24,15 @@ imgui-knobs.h
2424

2525
to your project and include `cimgui-knobs.h` in some source file.
2626

27-
### Building and runiing demo in C language
27+
### Build and run demo in C
2828

2929
---
3030

3131
#### Prerequisites
3232

3333
---
3434

35-
- Windows10 OS or later
35+
- Windows11 OS or later
3636
- [Msys2/MinGW](https://www.msys2.org/) tools installed. (gcc, make, etc)
3737

3838
```sh
@@ -48,7 +48,7 @@ to your project and include `cimgui-knobs.h` in some source file.
4848
```
4949

5050

51-
#### Building and running demo
51+
#### Build and run demo
5252

5353
---
5454

demo/c/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ BUILD_DIR = .build
2828

2929
VPATH = $(IM_KNOBS_DIR): $(CIM_KNOBS_DIR) : $(CIMGUI_DIR): $(IMGUI_DIR) : $(UTILS_DIR) : $(IMGUI_DIR)/backends
3030

31-
CSOURCES = main.c setupFonts.c utils.c
31+
CSOURCES = main.c setupFonts.c utils.c appImGui.c
3232
SOURCES += imgui_impl_glfw.cpp \
3333
imgui_impl_opengl3.cpp \
3434
cimgui.cpp

demo/c/imgui.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Collapsed=0
66
[Window][Dear ImGui Demo]
77
Pos=651,10
88
Size=470,527
9-
Collapsed=1
9+
Collapsed=0
1010

1111
[Window][Hello, world!]
1212
Pos=12,8

demo/c/main.c

Lines changed: 17 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,14 @@
1-
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
2-
#include "cimgui.h"
3-
#include "cimgui_impl.h"
4-
#include <GLFW/glfw3.h>
51
#include <stdio.h>
6-
#ifdef _MSC_VER
7-
#include <windows.h>
8-
#endif
9-
#include <GL/gl.h>
2+
#include <string.h>
3+
#include "appImGui.h"
104

11-
#include "setupFonts.h"
12-
#include "IconsFontAwesome6.h"
135
#include "cimgui-knobs.h"
146

15-
#ifdef IMGUI_HAS_IMSTR
16-
#define igBegin igBegin_Str
17-
#define igSliderFloat igSliderFloat_Str
18-
#define igCheckbox igCheckbox_Str
19-
#define igColorEdit3 igColorEdit3_Str
20-
#define igButton igButton_Str
21-
#endif
227

23-
//------"
24-
// main
25-
//------"
26-
int main(int argc, char *argv[]) {
27-
if (!glfwInit())
28-
return -1;
29-
30-
// Decide GL+GLSL versions
31-
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
32-
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
33-
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
34-
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
35-
36-
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
37-
const char *glsl_version = "#version 330";
38-
39-
// just an extra window hint for resize
40-
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
41-
42-
GLFWwindow *window = glfwCreateWindow(1024, 400, "CImGui-Knobs with C language 2025/02", NULL, NULL);
43-
if (!window) {
44-
printf("Failed to create window! Terminating!\n");
45-
glfwTerminate();
46-
return -1;
47-
}
48-
49-
glfwMakeContextCurrent(window);
50-
51-
// enable vsync
52-
glfwSwapInterval(1);
53-
54-
// check opengl version sdl uses
55-
printf("opengl version: %s\n", (char *) glGetString(GL_VERSION));
56-
57-
// setup imgui
58-
igCreateContext(NULL);
59-
60-
// set docking
61-
ImGuiIO *ioptr = igGetIO();
62-
ioptr->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;// Enable Keyboard Controls
63-
//ioptr->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
64-
#undef IMGUI_HAS_DOCK
65-
#ifdef IMGUI_HAS_DOCK
66-
ioptr->ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
67-
ioptr->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;// Enable Multi-Viewport / Platform Windows
68-
#endif
69-
70-
ImGui_ImplGlfw_InitForOpenGL(window, true);
71-
ImGui_ImplOpenGL3_Init(glsl_version);
72-
73-
igStyleColorsDark(NULL);
74-
//igStyleColorsClassic(NULL);
75-
//igStyleColorsLight(NULL);
8+
//-------------
9+
//--- gui_main
10+
//-------------
11+
void gui_main(Window *window) {
7612

7713
bool showDemoWindow = true;
7814
ImVec4 clearColor = {.x = 0.45f, .y = 0.55f, .z = 0.60f, .w = 1.0f};
@@ -81,13 +17,9 @@ int main(int argc, char *argv[]) {
8117
setupFonts();
8218

8319
// main event loop
84-
while (!glfwWindowShouldClose(window)) {
20+
while (!glfwWindowShouldClose(window->handle)) {
8521
glfwPollEvents();
86-
87-
// start imgui frame
88-
ImGui_ImplOpenGL3_NewFrame();
89-
ImGui_ImplGlfw_NewFrame();
90-
igNewFrame();
22+
newFrame();
9123

9224
if (showDemoWindow)
9325
igShowDemoWindow(&showDemoWindow);
@@ -96,7 +28,6 @@ int main(int argc, char *argv[]) {
9628
{
9729
char *title = "ImGui: CImGui-Knobs demo with C lang. 2025/02 " ICON_FA_DOG " " ICON_FA_CAT " " ICON_FA_HORSE " " ICON_FA_KIWI_BIRD;
9830
igBegin(title, NULL, 0);
99-
igSetWindowFontScale(1.2);
10031
static float val1 = 0;
10132
static float val2 = 0;
10233
static float val3 = 0;
@@ -154,38 +85,21 @@ int main(int argc, char *argv[]) {
15485
igNewLine();
15586
igText("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / igGetIO()->Framerate, igGetIO()->Framerate);
15687
//
157-
igSetWindowFontScale(1.0);
15888
igEnd();
15989
}
16090

16191
// render
162-
igRender();
163-
glfwMakeContextCurrent(window);
164-
glViewport(0, 0, (int) ioptr->DisplaySize.x, (int) ioptr->DisplaySize.y);
165-
glClearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
166-
glClear(GL_COLOR_BUFFER_BIT);
167-
ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData());
168-
#ifdef IMGUI_HAS_DOCK
169-
if (ioptr->ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
170-
GLFWwindow *backup_current_window = glfwGetCurrentContext();
171-
igUpdatePlatformWindows();
172-
igRenderPlatformWindowsDefault(NULL, NULL);
173-
glfwMakeContextCurrent(backup_current_window);
174-
}
175-
#endif
176-
glfwSwapBuffers(window);
177-
178-
if (showWindowDelay >= 0){ showWindowDelay--; }
179-
if (showWindowDelay == 0){ glfwShowWindow(window); }
92+
render(window);
18093
}
94+
}
18195

182-
// clean up
183-
ImGui_ImplOpenGL3_Shutdown();
184-
ImGui_ImplGlfw_Shutdown();
185-
igDestroyContext(NULL);
96+
//------
97+
// main
98+
//------
99+
int main(int argc, char *argv[]) {
100+
Window *window = createImGui(1024, 768);
186101

187-
glfwDestroyWindow(window);
188-
glfwTerminate();
102+
gui_main(window);
189103

190-
return 0;
104+
destroyImGui(window);
191105
}

demo/cpp/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ IMGUI_KNOBS_DIR = ../../libs/imgui-knobs/example
33
all:
44
$(MAKE) -C $(IMGUI_KNOBS_DIR)
55

6+
run: all
7+
../../libs/imgui-knobs/example/imgui_knobs_example
8+
69
.PHONY: clean
710

811
clean:

demo/cpp/imgui.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Window][Debug##Default]
2+
Pos=60,60
3+
Size=400,400
4+
5+
[Window][Knob knob]
6+
Pos=60,60
7+
Size=856,218
8+

demo/utils/appImGui.c

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#include "appImGui.h"
2+
#include <stdlib.h>
3+
#include <stdbool.h>
4+
5+
//------------------
6+
// --- setTheme
7+
//------------------
8+
void setTheme(int32_t num){
9+
switch (num){
10+
case 0:
11+
igStyleColorsDark(NULL);
12+
break;
13+
case 1:
14+
igStyleColorsClassic(NULL);
15+
break;
16+
case 2:
17+
igStyleColorsLight(NULL);
18+
break;
19+
default:
20+
break;
21+
}
22+
}
23+
24+
//---------------
25+
// --- initImGui
26+
//---------------
27+
Window* createImGui(int32_t width, int32_t height){
28+
if (!glfwInit())
29+
return NULL;
30+
31+
// Decide GL+GLSL versions
32+
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
33+
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
34+
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
35+
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
36+
37+
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // Hide window at startup.
38+
39+
const char *glsl_version = "#version 330";
40+
// just an extra window hint for resize
41+
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
42+
43+
GLFWwindow* glfwwindow = glfwCreateWindow(width, height, "CImGuiFileDialog example", NULL, NULL);
44+
if (!glfwwindow)
45+
{
46+
printf("Failed to create window! Terminating!\n");
47+
glfwTerminate();
48+
return NULL;
49+
}
50+
51+
glfwMakeContextCurrent(glfwwindow);
52+
53+
// enable vsync
54+
glfwSwapInterval(1);
55+
56+
// check opengl version sdl uses
57+
printf("opengl version: %s\n", (char *)glGetString(GL_VERSION));
58+
59+
// setup imgui
60+
igCreateContext(NULL);
61+
62+
// set docking
63+
ImGuiIO *ioptr = igGetIO();
64+
ioptr->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
65+
//ioptr->ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
66+
#undef IMGUI_HAS_DOCK
67+
#ifdef IMGUI_HAS_DOCK
68+
ioptr->ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
69+
ioptr->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
70+
#endif
71+
72+
ImGui_ImplGlfw_InitForOpenGL(glfwwindow, true);
73+
ImGui_ImplOpenGL3_Init(glsl_version);
74+
75+
Window* window = (Window*)malloc(sizeof(Window));
76+
window->handle = glfwwindow;
77+
window->clearColor.x = 0.45f;
78+
window->clearColor.y = 0.55f;
79+
window->clearColor.z = 0.60f;
80+
window->clearColor.w = 1.00f;
81+
window->showDelayWindow = 1;
82+
83+
return window;
84+
}
85+
86+
//------------------
87+
// --- destroyImGui
88+
//------------------
89+
void destroyImGui(Window* window){
90+
// clean up
91+
ImGui_ImplOpenGL3_Shutdown();
92+
ImGui_ImplGlfw_Shutdown();
93+
igDestroyContext(NULL);
94+
95+
glfwDestroyWindow(window->handle);
96+
glfwTerminate();
97+
free(window);
98+
}
99+
100+
//------------
101+
// --- render
102+
//------------
103+
void render(Window* window){
104+
ImGuiIO* ioptr = igGetIO();
105+
// render
106+
igRender();
107+
glfwMakeContextCurrent(window->handle);
108+
glViewport(0, 0, (int)ioptr->DisplaySize.x, (int)ioptr->DisplaySize.y);
109+
glClearColor(window->clearColor.x, window->clearColor.y, window->clearColor.z, window->clearColor.w);
110+
111+
glClear(GL_COLOR_BUFFER_BIT);
112+
ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData());
113+
#ifdef IMGUI_HAS_DOCK
114+
if (ioptr->ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
115+
{
116+
GLFWwindow *backup_current_window = glfwGetCurrentContext();
117+
igUpdatePlatformWindows();
118+
igRenderPlatformWindowsDefault(NULL, NULL);
119+
glfwMakeContextCurrent(backup_current_window);
120+
}
121+
#endif
122+
glfwSwapBuffers(window->handle);
123+
124+
if (window->showDelayWindow >= 0) window->showDelayWindow--;
125+
if (window->showDelayWindow == 0) glfwShowWindow(window->handle); // Avoid flickering screen at startup.
126+
}
127+
128+
//-------------
129+
//--- newFrame
130+
//-------------
131+
void newFrame(void){
132+
// start imgui frame
133+
ImGui_ImplOpenGL3_NewFrame();
134+
ImGui_ImplGlfw_NewFrame();
135+
igNewFrame();
136+
}

0 commit comments

Comments
 (0)