Skip to content

Commit

Permalink
SDL2 compilation is OK on Linux mint 22
Browse files Browse the repository at this point in the history
  • Loading branch information
dinau committed Oct 11, 2024
1 parent 41aa66f commit 75416cc
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 29 deletions.
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,25 @@ ImGui/CimGui version **1.91.3dock** (2024/10)

---

- Windows10 OS or later
- Linux Mint 22 (Ubuntu/Debian families ?): Work in progress.
- Now using zig-windows-x86_64-0.14.0-dev.1743
- Zig version
Now using zig-windows-x86_64-0.14.0-dev.1743
Probably [zig-windows-x86_64-0.14.0-dev.xxxx+yyyy...](https://ziglang.org/download/) might be ok. (-:)
- MSys2/MinGW basic commands (make, rm, cp, strip ...)
- WindowsOS
- Windows10 or later
- MSys2/MinGW basic commands (make, rm, cp, strip ...)
- Linux OS
Linux Mint 22 (or Ubuntu/Debian families ?)

```sh
$ sudo apt install xorg-dev libopengl-dev libgl1-mesa-dev
```

and for glfw3 and sdl2,

```sh
$ sudo apt install libglfw3 libglfw3-dev
$ sudo apt install libsdl2-dev
```

## Build and run

Expand All @@ -80,13 +94,7 @@ Probably [zig-windows-x86_64-0.14.0-dev.xxxx+yyyy...](https://ziglang.org/downlo
1. Build and Run

```sh
make run
```

or

```sh
zig build --release=fast run
make run # or zig build --release=fast run
```

## Examples screen shots
Expand Down Expand Up @@ -240,11 +248,17 @@ https://github.com/JBetz/build-sdl3-win32

---

- Make: GNU Make 4.4.1
- Zig: 0.14.0.dev
- SDL2 ver.2.30.8
- SDL3 3.1.3
- Git version 2.46.0.windows.1
- Windows11 (main)
- Zig: 0.14.0.dev
- Make: GNU Make 4.4.1
- SDL2 ver.2.30.8
- SDL3 3.1.3
- Git version 2.46.0.windows.1
- Linux Mint 22 (sub)
- Zig: 0.14.0-dev.1831+ce5a5c361
- Make: GNU Make 4.3
- SDL2 ver.2.30.0
- Git version 2.43.0

## Similar project

Expand Down
5 changes: 3 additions & 2 deletions examples/makefile.common.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Use zig-0.14.0
# Use zig-0.12.0
# by dinau (2024/06)
#

#
#OPT += --release=fast
#OPT += --release=small
Expand All @@ -14,7 +15,7 @@ all:
.PHONY: run gen cleanall cleanexe trans

run: all
(cd $(ZIG_BIN_DIR); ./$(TARGET).exe)
(cd $(ZIG_BIN_DIR); ./$(TARGET)$(EXE))
cp $(ZIG_BIN_DIR)/imgui.ini .

gen:
Expand Down
13 changes: 11 additions & 2 deletions examples/sdl2_opengl3/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ pub fn build(b: *std.Build) void {
//---------------
// [imlibs] --- Include paths
//---------------
imlibs.addIncludePath(b.path(b.pathJoin(&.{sdl2_path, "include/SDL2"})));
//
if (builtin.target.os.tag == .windows){
imlibs.addIncludePath(b.path(b.pathJoin(&.{sdl2_path, "include/SDL2"})));
}else if (builtin.target.os.tag == .linux){
const sdl2_inc_path: std.Build.LazyPath = .{
.cwd_relative = "/usr/include/SDL2"
};
imlibs.addIncludePath(sdl2_inc_path);
}

// ImGui/CImGui
imlibs.addIncludePath(b.path("../../libs/cimgui/imgui"));
imlibs.addIncludePath(b.path("../../libs/cimgui/imgui/backends"));
Expand Down Expand Up @@ -161,7 +170,7 @@ pub fn build(b: *std.Build) void {
}else if (builtin.target.os.tag == .linux){
exe.linkSystemLibrary("glfw3");
exe.linkSystemLibrary("GL");
exe.linkSystemLibrary("SDL2");
exe.linkSystemLibrary("sdl2");
}

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

-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
31 changes: 22 additions & 9 deletions examples/utils/setupFonts.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,24 @@
#define ImGui_GetIO igGetIO

const char* IconFontPath = "../utils/fonticon/fa6/fa-solid-900.ttf";
const char* JpFontName = "meiryo.ttc";
char sBufFontPath[2048];

/*-----------------
* getFontPath()
*----------------*/
char* getFontPath(char* sBuf, int bufSize, const char* fontName) {
const char* WinJpFontName = "meiryo.ttc";

char* getWinFontPath(char* sBuf, int bufSize, const char* fontName) {
char* sWinDir = getenv("windir");
if (sWinDir == NULL) return NULL;
snprintf(sBuf, bufSize, "%s\\Fonts\\%s", sWinDir, fontName);
return sBuf;
}
/*-----------------
* getLinuxFontPath()
*----------------*/
// For Linux Mint 22 (Ubuntu/Debian family ok ?)
char* LinuxJpFontName = "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc"; // ,"Noto Sans CJK",12.0) # Linux Mint

/*------------
* point2px()
Expand All @@ -35,7 +41,7 @@ float point2px(float point) {
const ImFontConfig config = {.FontDataOwnedByAtlas = true
, .FontNo = 0
, .OversampleH = 3
, .OversampleV = 1
, .OversampleV = 2
, .PixelSnapH = false
, .GlyphMaxAdvanceX = FLT_MAX
, .RasterizerMultiply = 1.0
Expand All @@ -49,12 +55,19 @@ 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);
char* fontPath = getFontPath(sBufFontPath, sizeof(sBufFontPath), JpFontName);
if (false == existsFile(fontPath)) {
printf("Error!: Not found JpFontPath: [%s] in %s\n", fontPath, __FILE__);
return;
ImFontAtlas_AddFontFromFileTTF(pio->Fonts, IconFontPath, point2px(10), &config , ranges_icon_fonts);

char* fontPath = getWinFontPath(sBufFontPath, sizeof(sBufFontPath), WinJpFontName);
if (existsFile(fontPath)) {
// ok
}else{
fontPath = LinuxJpFontName;
if (existsFile(LinuxJpFontName)) {
// ok
}else{
printf("Error!: Not found FontPath: [%s] in %s\n", fontPath, __FILE__);
return;
}
}
printf("Found JpFontPath: [%s]\n",fontPath);

Expand Down

0 comments on commit 75416cc

Please sign in to comment.