Skip to content

Commit

Permalink
added: zig_glfw_opengl3_image_load example
Browse files Browse the repository at this point in the history
changed: Icon png : icon_qr_my_github_red.png
added: HIDE_CONSOLE_WINDOW option
fixed: Buffer Overwrite bug
refactor: etc
  • Loading branch information
dinau committed Jun 15, 2024
1 parent d9548fa commit 3b66ab5
Show file tree
Hide file tree
Showing 33 changed files with 850 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ImageSaved*
zig-out/
.zig-out/
zig-cache/
Expand Down
16 changes: 9 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# All example are built at a time.
EXAMPLE_DIRS := examples/glfw_opengl3 \
examples/glfw_opengl3_image_load \
examples/glfw_opengl3_image_save \
examples/glfw_opengl3_jp \
examples/sdl2_opengl3 \
examples/sdl3_opengl3 \
examples/zig_glfw_opengl3
EXAMPLE_DIRS := \
examples/zig_glfw_opengl3 \
examples/zig_glfw_opengl3_image_load \
examples/glfw_opengl3 \
examples/glfw_opengl3_image_load \
examples/glfw_opengl3_image_save \
examples/glfw_opengl3_jp \
examples/sdl2_opengl3 \
examples/sdl3_opengl3

all:
$(foreach exdir,$(EXAMPLE_DIRS), $(call def_make,$(exdir),$@ ))
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Prerequisites](#prerequisites)
- [Build and run](#build-and-run)
- [Examples screen shots](#examples-screen-shots)
- [Hiding console window](#hiding-console-window)
- [Regenarate ImGui bindings](#regenarate-imgui-bindings)
- [Build with Clang, Zig cc](#build-with-clang-zig-cc)
- [My tools version](#my-tools-version)
Expand All @@ -14,7 +15,7 @@

# Dear_Bindings_Build

This project aims to easily build ImGui examples with **C language** and **Zig language** using [Dear_Bindings](https://github.com/dearimgui/dear_bindings).
This project aims to easily build ImGui examples with **C language** and **Zig language** using [Dear_Bindings](https://github.com/dearimgui/dear_bindings) and ImGui.

ImGui version **1.90.8 WIP** (2024/05)

Expand Down Expand Up @@ -69,10 +70,41 @@ ImGui version **1.90.8 WIP** (2024/05)
- [glfw_opengl3_image_save](examples/glfw_opengl3_image_save)
![alt](img/glfw_opengl3_image_save.png)


## Hiding console window

---

- Zig lang. examples
Open `build.zig` in each example folder and **enable** option line as follows,

```zig
... snip ...
exe.subsystem = .Windows; // Hide console window
... snip ...
```

and execute `make`.


- C lang. examples
Open `Makefile` in each example folder and **change** option as follows,

```Makefile
... snip ...
HIDE_CONSOLE_WINDOW = true
... snip ...
```

and execute `make`.


## Regenarate ImGui bindings

---

For instance,

```sh
pwd
glfw_opengl3
Expand All @@ -95,6 +127,8 @@ glfw_opengl3
make TC=clang # or TC=zigcc
```

Note: Except Zig lang. examples.

## My tools version

---
Expand Down
35 changes: 35 additions & 0 deletions examples/compile_flags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-I../libs/sdl/SDL2-2.30.3/i686-w64-mingw32/include/SDL2
-I../libs/sdl/sdl3/32/SDL3-2024-06-02/SDL3/include

-Wno-stringop-overflow
-DCIMGUI_USE_GLFW
-DCIMGUI_USE_OPENGL3
-I../libs/glfw/glfw-3.3.9.bin.WIN32/include
-I../libs/glfw/glfw-3.3.9.bin.WIN64/include
-static
-Wall
-Wno-unused-function
-O2
-Ilibs/cimgui
-I../libs/imgui
-I.
-I../libs/imgui/backends
-Iutils
-Iutils/fonticon
-I../libs/stb
-DCIMGUI_DEFINE_ENUMS_AND_STRUCTS
-DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1
-DImDrawIdx=unsigned int
-DIMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS
-fno-exceptions
-fno-rtti
-std=c++11


# See
# clangdで別ディレクトリのヘッダーを指定したい
# https://qiita.com/sudo00/items/99d9619de38574830f65
#
# Compiledb
# https://github.com/nickdiego/compiledb
# $ compiledb make
3 changes: 3 additions & 0 deletions examples/glfw_opengl3/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
STATIC_GLFW = true

HIDE_CONSOLE_WINDOW = false

include ../arc.mk
include ../glfw_opengl3.mk
include ../makefile.common.mk
Expand Down
5 changes: 3 additions & 2 deletions examples/glfw_opengl3/glfw_opengl3.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>

#include "cimgui.h"
#include <GLFW/glfw3.h>
#include <stdio.h>

#include "cimgui_impl_glfw.h"
#include "cimgui_impl_opengl3.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ int main(int argc, char *argv[]) {
bool showAnotherWindow = false;
ImVec4 clearColor = {.x = 0.25f, .y = 0.55f, .z = 0.90f, .w = 1.00f};
char sBuf[200];
for (int i = 0; i<sizeof(sBuf); i++) {
for (int i = 0; i < sizeof(sBuf); i++) {
sBuf[i] = '\0';
}

Expand Down
5 changes: 4 additions & 1 deletion examples/glfw_opengl3_image_load/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
STATIC_GLFW = true

HIDE_CONSOLE_WINDOW = false

include ../arc.mk
include ../glfw_opengl3.mk
include ../makefile.common.mk

gen: $(CIMGUI_ROOT) gencimgui impl_opengl3 impl_glfw
gen: $(CIMGUI_DIR) gencimgui impl_opengl3 impl_glfw
6 changes: 3 additions & 3 deletions examples/glfw_opengl3_image_load/glfw_opengl3_image_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "stb_image.h"

GLFWwindow *window;
uint8_t* pIconData; // == 0, Memory pointer for icon.
unsigned char* pIconData; // == 0, Memory pointer for icon.

int main(int argc, char *argv[]) {
(void)argc; (void) argv;
Expand Down Expand Up @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) {
glfwSwapInterval(1); // Enable Vsync

// Load title bar icon
const char* IconName = "icon_qr_my_github.png";
const char* IconName = "icon_qr_my_github_red.png";
pIconData = LoadTitleBarIcon(window, IconName);

printf("opengl version: %s\n", (char *)glGetString(GL_VERSION));
Expand Down Expand Up @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) {
}

ImGui_StyleColorsDark(NULL);
// ImGui_StyleColorsClassic(NULL);
// ImGui_StyleColorsClassic(NULL);

setupFonts();

Expand Down
Binary file removed examples/glfw_opengl3_image_load/icon_qr_my_github.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions examples/glfw_opengl3_image_save/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
STATIC_GLFW = true

HIDE_CONSOLE_WINDOW = false

include ../arc.mk
include ../glfw_opengl3.mk
include ../makefile.common.mk
Expand Down
11 changes: 6 additions & 5 deletions examples/glfw_opengl3_image_save/glfw_opengl3_image_save.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "cimgui.h"
#include <GLFW/glfw3.h>
#include <stdio.h>

#include "cimgui.h"
#include "cimgui_impl_glfw.h"
#include "cimgui_impl_opengl3.h"

Expand Down Expand Up @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) {
bool showDemoWindow = true;
bool showAnotherWindow = false;
ImVec4 clearColor = {.x = 0.25f, .y = 0.55f, .z = 0.90f, .w = 1.00f};
char sBuf[200];
char sBuf[1024];
for (int i = 0; i<sizeof(sBuf); i++) {
sBuf[i] = '\0';
}
Expand All @@ -113,7 +113,8 @@ int main(int argc, char *argv[]) {
{
static float fVal = 0.0f;
static int counter = 0;
char svName[100];
char svName[1024];
char sTooltipBuf[1024];
if (ImGui_Begin(ICON_FA_THUMBS_UP" " "ImGui: Dear_Bindings", NULL, 0)) {
ImGui_Text(ICON_FA_COMMENT" " "GLFW v"); ImGui_SameLine();
ImGui_Text("%s" , glfwGetVersionString());
Expand Down Expand Up @@ -150,8 +151,8 @@ int main(int argc, char *argv[]) {
ImGui_PopID();

//#-- Show tooltip help
snprintf(sBuf, sizeof(sBuf), "Save to \"%s\"", svName);
setTooltip(sBuf);
snprintf(sTooltipBuf, sizeof(sTooltipBuf), "Save to \"%s\"", svName);
setTooltip(sTooltipBuf);
counter++;

ImGui_SameLine();
Expand Down
5 changes: 4 additions & 1 deletion examples/glfw_opengl3_jp/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
STATIC_GLFW = true

HIDE_CONSOLE_WINDOW = false

include ../arc.mk
include ../glfw_opengl3.mk
include ../makefile.common.mk

gen: $(CIMGUI_ROOT) gencimgui impl_opengl3 impl_glfw
gen: $(CIMGUI_DIR) gencimgui impl_opengl3 impl_glfw
9 changes: 4 additions & 5 deletions examples/glfw_opengl3_jp/glfw_opengl3_jp.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include "cimgui.h"
#include <GLFW/glfw3.h>
#include <stdio.h>

#include "cimgui.h"
#include "cimgui_impl_glfw.h"
#include "cimgui_impl_opengl3.h"

#include "setupFonts.h"


GLFWwindow *window;

int main(int argc, char *argv[]) {
Expand Down Expand Up @@ -59,11 +58,11 @@ int main(int argc, char *argv[]) {
bool showAnotherWindow = false;
ImVec4 clearColor = {.x = 0.25f, .y = 0.55f, .z = 0.90f, .w = 1.00f};
char sBuf[200];
for (int i = 0; i<sizeof(sBuf); i++) {
for (int i = 0; i < sizeof(sBuf); i++) {
sBuf[i] = '\0';
}

//ImGui_StyleColorsClassic(NULL);
// ImGui_StyleColorsClassic(NULL);
ImGui_StyleColorsDark(NULL);

setupFonts();
Expand All @@ -87,7 +86,7 @@ int main(int argc, char *argv[]) {
ImGui_Text("%s", glfwGetVersionString());
ImGui_Text(ICON_FA_COMMENT" " "OpenGL v"); ImGui_SameLine();
ImGui_Text("%s", (char *)glGetString(GL_VERSION));
ImGui_InputTextWithHint("テキスト入力","ここへ入力", sBuf, sizeof(sBuf), 0);
ImGui_InputTextWithHint("テキスト入力", "ここへ入力", sBuf, sizeof(sBuf), 0);
ImGui_Text("入力結果:"); ImGui_SameLine(); ImGui_Text("%s", sBuf);
ImGui_Checkbox("デモ・ウインドウ", &showDemoWindow);
ImGui_Checkbox("その他のウインドウ", &showAnotherWindow);
Expand Down
8 changes: 8 additions & 0 deletions examples/makefile.common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ DEPS_CIMGUI = $(CIMGUI_DIR)/cimgui.h
DEPS_OTHER = $(wildcard *.h) $(wildcard $(UTILS_DIR)/*.h)
DEPS_PROJ = $(wildcard *.h)

# Hide console winodw
ifeq ($(HIDE_CONSOLE_WINDOW),true)
LDFLAGS += -mwindows
endif

CXXFLAGS += $(CFLAGS)
CXXFLAGS += -fno-exceptions -fno-rtti -std=c++11
LDFLAGS += -L$(CIMGUI_ARCHIVE_DIR)
Expand All @@ -114,6 +119,9 @@ MAKE_DIRS = $(BUILD_DIR) \
$(CIMGUI_BUILD_DIR) \
$(OTHER_OBJ_DIR)




all: $(MAKE_DIRS) $(LIB_CIMGUI_ARCHIVE) $(TARGET)$(EXE) afterbuild
lib: $(LIB_CIMGUI_ARCHIVE)
afterbuild:
Expand Down
4 changes: 3 additions & 1 deletion examples/sdl2_opengl3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ LDFLAGS += -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32
LDFLAGS += -luuid -lcomdlg32 -ladvapi32 -lsetupapi -lhid -lversion
LDFLAGS += -lws2_32 -ldinput8 -ldxguid -ldxerr8 -lwinmm

HIDE_CONSOLE_WINDOW = false

include ../makefile.common.mk

gen: $(CIMGUI_ROOT) gencimgui impl_opengl3 impl_sdl2
gen: $(CIMGUI_DIR) gencimgui impl_opengl3 impl_sdl2
11 changes: 6 additions & 5 deletions examples/sdl2_opengl3/sdl2_opengl3.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp

#include "cimgui.h"
#include "cimgui_impl_sdl2.h"
#include "cimgui_impl_opengl3.h"
#include <stdio.h>
#define SDL_MAIN_HANDLED
#include <SDL.h>
#include <SDL_opengl.h>

#include "cimgui.h"
#include "cimgui_impl_sdl2.h"
#include "cimgui_impl_opengl3.h"

#include "setupFonts.h"

#define nullptr NULL
Expand All @@ -23,7 +24,7 @@ const int MainWinWidth = 1024;
const int MainWinHeight = 800;

// Main code
int main(int argc, char *argv[]){
int main(int argc, char *argv[]) {
(void)argc; (void) argv;
// Setup SDL
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
Expand Down Expand Up @@ -144,7 +145,7 @@ int main(int argc, char *argv[]){
}
}
if (showAnotherWindow) {
ImGui_Begin("Another Window", &showAnotherWindow,0); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
ImGui_Begin("Another Window", &showAnotherWindow, 0); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
ImGui_Text("Hello from another window!");
if (ImGui_Button("Close Me"))
showAnotherWindow = false;
Expand Down
6 changes: 5 additions & 1 deletion examples/sdl3_opengl3/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ LDFLAGS += -luuid -lcomdlg32 -ladvapi32 -lsetupapi -lhid -lversion
LDFLAGS += -lws2_32 -ldinput8 -ldxguid -ldxerr8 -lwinmm

AFTER_BUILD = @cp -u $(SDL3_DIR)/bin/SDL3.dll .

# TODO no effect ?
HIDE_CONSOLE_WINDOW = true

include ../makefile.common.mk

gen: $(CIMGUI_ROOT) gencimgui impl_opengl3 impl_sdl3
gen: $(CIMGUI_DIR) gencimgui impl_opengl3 impl_sdl3
14 changes: 3 additions & 11 deletions examples/sdl3_opengl3/sdl3_opengl3.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
// Dear ImGui: standalone example application for SDL2 + OpenGL
// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)

// Learn about Dear ImGui:
// - FAQ https://dearimgui.com/faq
// - Getting Started https://dearimgui.com/getting-started
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
// - Introduction, links and more at the top of imgui.cpp
#include <stdio.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_opengl.h>

#include "cimgui.h"
#include "cimgui_impl_sdl3.h"
#include "cimgui_impl_opengl3.h"
#include <stdio.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_opengl.h>

#include "setupFonts.h"

Expand Down
Loading

0 comments on commit 3b66ab5

Please sign in to comment.