├── README.md
├── index.html
└── showcase
├── Makefile
├── README.md
├── imgui.js
├── imgui.wasm
├── imgui
├── backends
│ ├── imgui_impl_glfw.cpp
│ ├── imgui_impl_glfw.h
│ ├── imgui_impl_opengl3.cpp
│ ├── imgui_impl_opengl3.h
│ └── imgui_impl_opengl3_loader.h
├── freetype
│ ├── imgui_freetype.cpp
│ └── imgui_freetype.h
├── imconfig.h
├── imgui.cpp
├── imgui.h
├── imgui_draw.cpp
├── imgui_internal.h
├── imgui_tables.cpp
├── imgui_widgets.cpp
├── imstb_rectpack.h
├── imstb_textedit.h
└── imstb_truetype.h
├── index.html
├── json
└── json.hpp
└── src
├── fonts
└── ubuntu_compressed.h
├── main.cpp
├── menu
├── menu.cpp
└── menu.h
└── settings.h
/README.md:
--------------------------------------------------------------------------------
1 | ### Nixware
2 | This is a web part for [cheat](https://github.com/pa1n-dev/nixware_x64) on [Garry's Mod](https://store.steampowered.com/app/4000/Garrys_Mod/)
3 |
4 | #### Links
5 | - [Loading screen](https://pa1n-dev.github.io/nixware/)
6 | - [Showcase](https://pa1n-dev.github.io/nixware/showcase/)
7 |
8 | #### Software used
9 | - [WebGui](https://github.com/jnmaloney/WebGui)
10 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | nixware
5 |
6 |
7 |
8 |
33 |
34 |
35 |
36 |

37 |
An Angel Stands in Balaam's Way
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/showcase/Makefile:
--------------------------------------------------------------------------------
1 | CXX = emcc
2 | OUTPUT = imgui.js
3 | SRC_DIR := src
4 | IMGUI_DIR := imgui
5 | FILES_TO_DELETE := imgui.js imgui.wasm imgui.data
6 |
7 | SOURCES = $(SRC_DIR)/main.cpp
8 | SOURCES += $(SRC_DIR)/menu/menu.cpp
9 | SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp
10 | SOURCES += $(IMGUI_DIR)/freetype/imgui_freetype.cpp
11 | SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_widgets.cpp $(IMGUI_DIR)/imgui_tables.cpp
12 |
13 | LIBS = -lGL -lfreetype
14 | WEBGL_VER = -s USE_WEBGL2=1 -s USE_GLFW=3 -s FULL_ES3=1 -s USE_FREETYPE=1
15 | USE_WASM = -s WASM=1
16 |
17 | all: $(SOURCES) $(OUTPUT)
18 |
19 | $(OUTPUT): $(SOURCES)
20 | $(CXX) $(SOURCES) -std=c++17 -o $(OUTPUT) $(LIBS) $(WEBGL_VER) -O2 $(USE_WASM) -I $(IMGUI_DIR) -I $(IMGUI_DIR)/backends -I $(IMGUI_DIR)/freetype
21 |
22 | clean:
23 | del $(FILES_TO_DELETE)
24 |
25 |
--------------------------------------------------------------------------------
/showcase/README.md:
--------------------------------------------------------------------------------
1 | ### Showcase
2 |
3 | Here is a preview of the [cheat](https://github.com/pa1n-dev/nixware_x64) menu. It's completely clickable
4 |
5 | I saw this idea in a popular cheat on gmod (meth)
6 |
7 | This example uses Emscripted to compile c++ into Web Assembly (WASM) binaries that can be run as an application in the browser.
8 |
9 | The source depends on OpenGL3, ES3, GLFW as well as Freetype and IMGui. I have attempted to make the most lightweight version of IMGUI possible to run in the browser.
10 |
11 | #### How to build
12 |
13 | You need to install [EMCC](https://emscripten.org/docs/getting_started/downloads.html) (Emscripten Compiler) and [GNU make](https://www.gnu.org/software/make/#download)
14 |
15 | Execute this in the showcase folder:
16 |
17 | ```bash
18 | make clean # Delete all files that should be compiled again
19 | make
20 | ```
21 |
22 | To see the result of your work you need to start a local web server:
23 | ```bash
24 | python -m http.server 8080
25 | ```
26 |
27 | Open in browser:
28 |
29 | http://localhost:8080/index.html
30 |
31 | #### Screenshots
32 |
33 | 
34 |
--------------------------------------------------------------------------------
/showcase/imgui.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pa1n-dev/nixware/242ef2e35be33ec44c464babf768b36e14c1db0b/showcase/imgui.wasm
--------------------------------------------------------------------------------
/showcase/imgui/backends/imgui_impl_glfw.cpp:
--------------------------------------------------------------------------------
1 | // dear imgui: Platform Backend for GLFW
2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
4 | // (Requires: GLFW 3.1+. Prefer GLFW 3.3+ or GLFW 3.4+ for full feature support.)
5 |
6 | // Implemented features:
7 | // [X] Platform: Clipboard support.
8 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
9 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
10 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
11 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
12 |
13 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
14 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
15 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
16 | // Read online: https://github.com/ocornut/imgui/tree/master/docs
17 |
18 | // CHANGELOG
19 | // (minor and older changes stripped away, please see git history for details)
20 | // 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen/ImGuiMouseSource_Pen on Windows ONLY, using a custom WndProc hook. (#2702)
21 | // 2023-03-16: Inputs: Fixed key modifiers handling on secondary viewports (docking branch). Broken on 2023/01/04. (#6248, #6034)
22 | // 2023-03-14: Emscripten: Avoid using glfwGetError() and glfwGetGamepadState() which are not correctly implemented in Emscripten emulation. (#6240)
23 | // 2023-02-03: Emscripten: Registering custom low-level mouse wheel handler to get more accurate scrolling impulses on Emscripten. (#4019, #6096)
24 | // 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty.
25 | // 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908)
26 | // 2022-10-18: Perform a dummy glfwGetError() read to cancel missing mouse cursors errors. Using GLFW_VERSION_COMBINED directly. (#5785)
27 | // 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
28 | // 2022-09-26: Inputs: Renamed ImGuiKey_ModXXX introduced in 1.87 to ImGuiMod_XXX (old names still supported).
29 | // 2022-09-01: Inputs: Honor GLFW_CURSOR_DISABLED by not setting mouse position.
30 | // 2022-04-30: Inputs: Fixed ImGui_ImplGlfw_TranslateUntranslatedKey() for lower case letters on OSX.
31 | // 2022-03-23: Inputs: Fixed a regression in 1.87 which resulted in keyboard modifiers events being reported incorrectly on Linux/X11.
32 | // 2022-02-07: Added ImGui_ImplGlfw_InstallCallbacks()/ImGui_ImplGlfw_RestoreCallbacks() helpers to facilitate user installing callbacks after initializing backend.
33 | // 2022-01-26: Inputs: replaced short-lived io.AddKeyModsEvent() (added two weeks ago) with io.AddKeyEvent() using ImGuiKey_ModXXX flags. Sorry for the confusion.
34 | // 2021-01-20: Inputs: calling new io.AddKeyAnalogEvent() for gamepad support, instead of writing directly to io.NavInputs[].
35 | // 2022-01-17: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
36 | // 2022-01-17: Inputs: always update key mods next and before key event (not in NewFrame) to fix input queue with very low framerates.
37 | // 2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback().
38 | // 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
39 | // 2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API.
40 | // 2021-08-17: *BREAKING CHANGE*: Now using glfwSetWindowFocusCallback() to calling io.AddFocusEvent(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() and forward it to the backend via ImGui_ImplGlfw_WindowFocusCallback().
41 | // 2021-07-29: *BREAKING CHANGE*: Now using glfwSetCursorEnterCallback(). MousePos is correctly reported when the host platform window is hovered but not focused. If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() callback and forward it to the backend via ImGui_ImplGlfw_CursorEnterCallback().
42 | // 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
43 | // 2020-01-17: Inputs: Disable error callback while assigning mouse cursors because some X11 setup don't have them and it generates errors.
44 | // 2019-12-05: Inputs: Added support for new mouse cursors added in GLFW 3.4+ (resizing cursors, not allowed cursor).
45 | // 2019-10-18: Misc: Previously installed user callbacks are now restored on shutdown.
46 | // 2019-07-21: Inputs: Added mapping for ImGuiKey_KeyPadEnter.
47 | // 2019-05-11: Inputs: Don't filter value from character callback before calling AddInputCharacter().
48 | // 2019-03-12: Misc: Preserve DisplayFramebufferScale when main window is minimized.
49 | // 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
50 | // 2018-11-07: Inputs: When installing our GLFW callbacks, we save user's previously installed ones - if any - and chain call them.
51 | // 2018-08-01: Inputs: Workaround for Emscripten which doesn't seem to handle focus related calls.
52 | // 2018-06-29: Inputs: Added support for the ImGuiMouseCursor_Hand cursor.
53 | // 2018-06-08: Misc: Extracted imgui_impl_glfw.cpp/.h away from the old combined GLFW+OpenGL/Vulkan examples.
54 | // 2018-03-20: Misc: Setup io.BackendFlags ImGuiBackendFlags_HasMouseCursors flag + honor ImGuiConfigFlags_NoMouseCursorChange flag.
55 | // 2018-02-20: Inputs: Added support for mouse cursors (ImGui::GetMouseCursor() value, passed to glfwSetCursor()).
56 | // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
57 | // 2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
58 | // 2018-01-25: Inputs: Added gamepad support if ImGuiConfigFlags_NavEnableGamepad is set.
59 | // 2018-01-25: Inputs: Honoring the io.WantSetMousePos by repositioning the mouse (when using navigation and ImGuiConfigFlags_NavMoveMouse is set).
60 | // 2018-01-20: Inputs: Added Horizontal Mouse Wheel support.
61 | // 2018-01-18: Inputs: Added mapping for ImGuiKey_Insert.
62 | // 2017-08-25: Inputs: MousePos set to -FLT_MAX,-FLT_MAX when mouse is unavailable/missing (instead of -1,-1).
63 | // 2016-10-15: Misc: Added a void* user_data parameter to Clipboard function handlers.
64 |
65 | #include "imgui.h"
66 | #include "imgui_impl_glfw.h"
67 |
68 | // Clang warnings with -Weverything
69 | #if defined(__clang__)
70 | #pragma clang diagnostic push
71 | #pragma clang diagnostic ignored "-Wold-style-cast" // warning: use of old-style cast
72 | #pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness
73 | #endif
74 |
75 | // GLFW
76 | #include
77 |
78 | #ifdef _WIN32
79 | #undef APIENTRY
80 | #define GLFW_EXPOSE_NATIVE_WIN32
81 | #include // for glfwGetWin32Window()
82 | #endif
83 | #ifdef __APPLE__
84 | #define GLFW_EXPOSE_NATIVE_COCOA
85 | #include // for glfwGetCocoaWindow()
86 | #endif
87 |
88 | #ifdef __EMSCRIPTEN__
89 | #include
90 | #include
91 | #endif
92 |
93 | // We gather version tests as define in order to easily see which features are version-dependent.
94 | #define GLFW_VERSION_COMBINED (GLFW_VERSION_MAJOR * 1000 + GLFW_VERSION_MINOR * 100 + GLFW_VERSION_REVISION)
95 | #ifdef GLFW_RESIZE_NESW_CURSOR // Let's be nice to people who pulled GLFW between 2019-04-16 (3.4 define) and 2019-11-29 (cursors defines) // FIXME: Remove when GLFW 3.4 is released?
96 | #define GLFW_HAS_NEW_CURSORS (GLFW_VERSION_COMBINED >= 3400) // 3.4+ GLFW_RESIZE_ALL_CURSOR, GLFW_RESIZE_NESW_CURSOR, GLFW_RESIZE_NWSE_CURSOR, GLFW_NOT_ALLOWED_CURSOR
97 | #else
98 | #define GLFW_HAS_NEW_CURSORS (0)
99 | #endif
100 | #define GLFW_HAS_GAMEPAD_API (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetGamepadState() new api
101 | #define GLFW_HAS_GETKEYNAME (GLFW_VERSION_COMBINED >= 3200) // 3.2+ glfwGetKeyName()
102 | #define GLFW_HAS_GETERROR (GLFW_VERSION_COMBINED >= 3300) // 3.3+ glfwGetError()
103 |
104 | // GLFW data
105 | enum GlfwClientApi
106 | {
107 | GlfwClientApi_Unknown,
108 | GlfwClientApi_OpenGL,
109 | GlfwClientApi_Vulkan
110 | };
111 |
112 | struct ImGui_ImplGlfw_Data
113 | {
114 | GLFWwindow* Window;
115 | GlfwClientApi ClientApi;
116 | double Time;
117 | GLFWwindow* MouseWindow;
118 | GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
119 | ImVec2 LastValidMousePos;
120 | bool InstalledCallbacks;
121 | bool CallbacksChainForAllWindows;
122 |
123 | // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
124 | GLFWwindowfocusfun PrevUserCallbackWindowFocus;
125 | GLFWcursorposfun PrevUserCallbackCursorPos;
126 | GLFWcursorenterfun PrevUserCallbackCursorEnter;
127 | GLFWmousebuttonfun PrevUserCallbackMousebutton;
128 | GLFWscrollfun PrevUserCallbackScroll;
129 | GLFWkeyfun PrevUserCallbackKey;
130 | GLFWcharfun PrevUserCallbackChar;
131 | GLFWmonitorfun PrevUserCallbackMonitor;
132 | #ifdef _WIN32
133 | WNDPROC GlfwWndProc;
134 | #endif
135 |
136 | ImGui_ImplGlfw_Data() { memset((void*)this, 0, sizeof(*this)); }
137 | };
138 |
139 | // Backend data stored in io.BackendPlatformUserData to allow support for multiple Dear ImGui contexts
140 | // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
141 | // FIXME: multi-context support is not well tested and probably dysfunctional in this backend.
142 | // - Because glfwPollEvents() process all windows and some events may be called outside of it, you will need to register your own callbacks
143 | // (passing install_callbacks=false in ImGui_ImplGlfw_InitXXX functions), set the current dear imgui context and then call our callbacks.
144 | // - Otherwise we may need to store a GLFWWindow* -> ImGuiContext* map and handle this in the backend, adding a little bit of extra complexity to it.
145 | // FIXME: some shared resources (mouse cursor shape, gamepad) are mishandled when using multi-context.
146 | static ImGui_ImplGlfw_Data* ImGui_ImplGlfw_GetBackendData()
147 | {
148 | return ImGui::GetCurrentContext() ? (ImGui_ImplGlfw_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;
149 | }
150 |
151 | // Functions
152 | static const char* ImGui_ImplGlfw_GetClipboardText(void* user_data)
153 | {
154 | return glfwGetClipboardString((GLFWwindow*)user_data);
155 | }
156 |
157 | static void ImGui_ImplGlfw_SetClipboardText(void* user_data, const char* text)
158 | {
159 | glfwSetClipboardString((GLFWwindow*)user_data, text);
160 | }
161 |
162 | static ImGuiKey ImGui_ImplGlfw_KeyToImGuiKey(int key)
163 | {
164 | switch (key)
165 | {
166 | case GLFW_KEY_TAB: return ImGuiKey_Tab;
167 | case GLFW_KEY_LEFT: return ImGuiKey_LeftArrow;
168 | case GLFW_KEY_RIGHT: return ImGuiKey_RightArrow;
169 | case GLFW_KEY_UP: return ImGuiKey_UpArrow;
170 | case GLFW_KEY_DOWN: return ImGuiKey_DownArrow;
171 | case GLFW_KEY_PAGE_UP: return ImGuiKey_PageUp;
172 | case GLFW_KEY_PAGE_DOWN: return ImGuiKey_PageDown;
173 | case GLFW_KEY_HOME: return ImGuiKey_Home;
174 | case GLFW_KEY_END: return ImGuiKey_End;
175 | case GLFW_KEY_INSERT: return ImGuiKey_Insert;
176 | case GLFW_KEY_DELETE: return ImGuiKey_Delete;
177 | case GLFW_KEY_BACKSPACE: return ImGuiKey_Backspace;
178 | case GLFW_KEY_SPACE: return ImGuiKey_Space;
179 | case GLFW_KEY_ENTER: return ImGuiKey_Enter;
180 | case GLFW_KEY_ESCAPE: return ImGuiKey_Escape;
181 | case GLFW_KEY_APOSTROPHE: return ImGuiKey_Apostrophe;
182 | case GLFW_KEY_COMMA: return ImGuiKey_Comma;
183 | case GLFW_KEY_MINUS: return ImGuiKey_Minus;
184 | case GLFW_KEY_PERIOD: return ImGuiKey_Period;
185 | case GLFW_KEY_SLASH: return ImGuiKey_Slash;
186 | case GLFW_KEY_SEMICOLON: return ImGuiKey_Semicolon;
187 | case GLFW_KEY_EQUAL: return ImGuiKey_Equal;
188 | case GLFW_KEY_LEFT_BRACKET: return ImGuiKey_LeftBracket;
189 | case GLFW_KEY_BACKSLASH: return ImGuiKey_Backslash;
190 | case GLFW_KEY_RIGHT_BRACKET: return ImGuiKey_RightBracket;
191 | case GLFW_KEY_GRAVE_ACCENT: return ImGuiKey_GraveAccent;
192 | case GLFW_KEY_CAPS_LOCK: return ImGuiKey_CapsLock;
193 | case GLFW_KEY_SCROLL_LOCK: return ImGuiKey_ScrollLock;
194 | case GLFW_KEY_NUM_LOCK: return ImGuiKey_NumLock;
195 | case GLFW_KEY_PRINT_SCREEN: return ImGuiKey_PrintScreen;
196 | case GLFW_KEY_PAUSE: return ImGuiKey_Pause;
197 | case GLFW_KEY_KP_0: return ImGuiKey_Keypad0;
198 | case GLFW_KEY_KP_1: return ImGuiKey_Keypad1;
199 | case GLFW_KEY_KP_2: return ImGuiKey_Keypad2;
200 | case GLFW_KEY_KP_3: return ImGuiKey_Keypad3;
201 | case GLFW_KEY_KP_4: return ImGuiKey_Keypad4;
202 | case GLFW_KEY_KP_5: return ImGuiKey_Keypad5;
203 | case GLFW_KEY_KP_6: return ImGuiKey_Keypad6;
204 | case GLFW_KEY_KP_7: return ImGuiKey_Keypad7;
205 | case GLFW_KEY_KP_8: return ImGuiKey_Keypad8;
206 | case GLFW_KEY_KP_9: return ImGuiKey_Keypad9;
207 | case GLFW_KEY_KP_DECIMAL: return ImGuiKey_KeypadDecimal;
208 | case GLFW_KEY_KP_DIVIDE: return ImGuiKey_KeypadDivide;
209 | case GLFW_KEY_KP_MULTIPLY: return ImGuiKey_KeypadMultiply;
210 | case GLFW_KEY_KP_SUBTRACT: return ImGuiKey_KeypadSubtract;
211 | case GLFW_KEY_KP_ADD: return ImGuiKey_KeypadAdd;
212 | case GLFW_KEY_KP_ENTER: return ImGuiKey_KeypadEnter;
213 | case GLFW_KEY_KP_EQUAL: return ImGuiKey_KeypadEqual;
214 | case GLFW_KEY_LEFT_SHIFT: return ImGuiKey_LeftShift;
215 | case GLFW_KEY_LEFT_CONTROL: return ImGuiKey_LeftCtrl;
216 | case GLFW_KEY_LEFT_ALT: return ImGuiKey_LeftAlt;
217 | case GLFW_KEY_LEFT_SUPER: return ImGuiKey_LeftSuper;
218 | case GLFW_KEY_RIGHT_SHIFT: return ImGuiKey_RightShift;
219 | case GLFW_KEY_RIGHT_CONTROL: return ImGuiKey_RightCtrl;
220 | case GLFW_KEY_RIGHT_ALT: return ImGuiKey_RightAlt;
221 | case GLFW_KEY_RIGHT_SUPER: return ImGuiKey_RightSuper;
222 | case GLFW_KEY_MENU: return ImGuiKey_Menu;
223 | case GLFW_KEY_0: return ImGuiKey_0;
224 | case GLFW_KEY_1: return ImGuiKey_1;
225 | case GLFW_KEY_2: return ImGuiKey_2;
226 | case GLFW_KEY_3: return ImGuiKey_3;
227 | case GLFW_KEY_4: return ImGuiKey_4;
228 | case GLFW_KEY_5: return ImGuiKey_5;
229 | case GLFW_KEY_6: return ImGuiKey_6;
230 | case GLFW_KEY_7: return ImGuiKey_7;
231 | case GLFW_KEY_8: return ImGuiKey_8;
232 | case GLFW_KEY_9: return ImGuiKey_9;
233 | case GLFW_KEY_A: return ImGuiKey_A;
234 | case GLFW_KEY_B: return ImGuiKey_B;
235 | case GLFW_KEY_C: return ImGuiKey_C;
236 | case GLFW_KEY_D: return ImGuiKey_D;
237 | case GLFW_KEY_E: return ImGuiKey_E;
238 | case GLFW_KEY_F: return ImGuiKey_F;
239 | case GLFW_KEY_G: return ImGuiKey_G;
240 | case GLFW_KEY_H: return ImGuiKey_H;
241 | case GLFW_KEY_I: return ImGuiKey_I;
242 | case GLFW_KEY_J: return ImGuiKey_J;
243 | case GLFW_KEY_K: return ImGuiKey_K;
244 | case GLFW_KEY_L: return ImGuiKey_L;
245 | case GLFW_KEY_M: return ImGuiKey_M;
246 | case GLFW_KEY_N: return ImGuiKey_N;
247 | case GLFW_KEY_O: return ImGuiKey_O;
248 | case GLFW_KEY_P: return ImGuiKey_P;
249 | case GLFW_KEY_Q: return ImGuiKey_Q;
250 | case GLFW_KEY_R: return ImGuiKey_R;
251 | case GLFW_KEY_S: return ImGuiKey_S;
252 | case GLFW_KEY_T: return ImGuiKey_T;
253 | case GLFW_KEY_U: return ImGuiKey_U;
254 | case GLFW_KEY_V: return ImGuiKey_V;
255 | case GLFW_KEY_W: return ImGuiKey_W;
256 | case GLFW_KEY_X: return ImGuiKey_X;
257 | case GLFW_KEY_Y: return ImGuiKey_Y;
258 | case GLFW_KEY_Z: return ImGuiKey_Z;
259 | case GLFW_KEY_F1: return ImGuiKey_F1;
260 | case GLFW_KEY_F2: return ImGuiKey_F2;
261 | case GLFW_KEY_F3: return ImGuiKey_F3;
262 | case GLFW_KEY_F4: return ImGuiKey_F4;
263 | case GLFW_KEY_F5: return ImGuiKey_F5;
264 | case GLFW_KEY_F6: return ImGuiKey_F6;
265 | case GLFW_KEY_F7: return ImGuiKey_F7;
266 | case GLFW_KEY_F8: return ImGuiKey_F8;
267 | case GLFW_KEY_F9: return ImGuiKey_F9;
268 | case GLFW_KEY_F10: return ImGuiKey_F10;
269 | case GLFW_KEY_F11: return ImGuiKey_F11;
270 | case GLFW_KEY_F12: return ImGuiKey_F12;
271 | default: return ImGuiKey_None;
272 | }
273 | }
274 |
275 | // X11 does not include current pressed/released modifier key in 'mods' flags submitted by GLFW
276 | // See https://github.com/ocornut/imgui/issues/6034 and https://github.com/glfw/glfw/issues/1630
277 | static void ImGui_ImplGlfw_UpdateKeyModifiers(GLFWwindow* window)
278 | {
279 | ImGuiIO& io = ImGui::GetIO();
280 | io.AddKeyEvent(ImGuiMod_Ctrl, (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS));
281 | io.AddKeyEvent(ImGuiMod_Shift, (glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS));
282 | io.AddKeyEvent(ImGuiMod_Alt, (glfwGetKey(window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS));
283 | io.AddKeyEvent(ImGuiMod_Super, (glfwGetKey(window, GLFW_KEY_LEFT_SUPER) == GLFW_PRESS) || (glfwGetKey(window, GLFW_KEY_RIGHT_SUPER) == GLFW_PRESS));
284 | }
285 |
286 | static bool ImGui_ImplGlfw_ShouldChainCallback(GLFWwindow* window)
287 | {
288 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
289 | return bd->CallbacksChainForAllWindows ? true : (window == bd->Window);
290 | }
291 |
292 | void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
293 | {
294 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
295 | if (bd->PrevUserCallbackMousebutton != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
296 | bd->PrevUserCallbackMousebutton(window, button, action, mods);
297 |
298 | ImGui_ImplGlfw_UpdateKeyModifiers(window);
299 |
300 | ImGuiIO& io = ImGui::GetIO();
301 | if (button >= 0 && button < ImGuiMouseButton_COUNT)
302 | io.AddMouseButtonEvent(button, action == GLFW_PRESS);
303 | }
304 |
305 | void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
306 | {
307 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
308 | if (bd->PrevUserCallbackScroll != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
309 | bd->PrevUserCallbackScroll(window, xoffset, yoffset);
310 |
311 | #ifdef __EMSCRIPTEN__
312 | // Ignore GLFW events: will be processed in ImGui_ImplEmscripten_WheelCallback().
313 | return;
314 | #endif
315 |
316 | ImGuiIO& io = ImGui::GetIO();
317 | io.AddMouseWheelEvent((float)xoffset, (float)yoffset);
318 | }
319 |
320 | static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode)
321 | {
322 | #if GLFW_HAS_GETKEYNAME && !defined(__EMSCRIPTEN__)
323 | // GLFW 3.1+ attempts to "untranslate" keys, which goes the opposite of what every other framework does, making using lettered shortcuts difficult.
324 | // (It had reasons to do so: namely GLFW is/was more likely to be used for WASD-type game controls rather than lettered shortcuts, but IHMO the 3.1 change could have been done differently)
325 | // See https://github.com/glfw/glfw/issues/1502 for details.
326 | // Adding a workaround to undo this (so our keys are translated->untranslated->translated, likely a lossy process).
327 | // This won't cover edge cases but this is at least going to cover common cases.
328 | if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_EQUAL)
329 | return key;
330 | GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr);
331 | const char* key_name = glfwGetKeyName(key, scancode);
332 | glfwSetErrorCallback(prev_error_callback);
333 | #if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908)
334 | (void)glfwGetError(nullptr);
335 | #endif
336 | if (key_name && key_name[0] != 0 && key_name[1] == 0)
337 | {
338 | const char char_names[] = "`-=[]\\,;\'./";
339 | const int char_keys[] = { GLFW_KEY_GRAVE_ACCENT, GLFW_KEY_MINUS, GLFW_KEY_EQUAL, GLFW_KEY_LEFT_BRACKET, GLFW_KEY_RIGHT_BRACKET, GLFW_KEY_BACKSLASH, GLFW_KEY_COMMA, GLFW_KEY_SEMICOLON, GLFW_KEY_APOSTROPHE, GLFW_KEY_PERIOD, GLFW_KEY_SLASH, 0 };
340 | IM_ASSERT(IM_ARRAYSIZE(char_names) == IM_ARRAYSIZE(char_keys));
341 | if (key_name[0] >= '0' && key_name[0] <= '9') { key = GLFW_KEY_0 + (key_name[0] - '0'); }
342 | else if (key_name[0] >= 'A' && key_name[0] <= 'Z') { key = GLFW_KEY_A + (key_name[0] - 'A'); }
343 | else if (key_name[0] >= 'a' && key_name[0] <= 'z') { key = GLFW_KEY_A + (key_name[0] - 'a'); }
344 | else if (const char* p = strchr(char_names, key_name[0])) { key = char_keys[p - char_names]; }
345 | }
346 | // if (action == GLFW_PRESS) printf("key %d scancode %d name '%s'\n", key, scancode, key_name);
347 | #else
348 | IM_UNUSED(scancode);
349 | #endif
350 | return key;
351 | }
352 |
353 | void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int keycode, int scancode, int action, int mods)
354 | {
355 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
356 | if (bd->PrevUserCallbackKey != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
357 | bd->PrevUserCallbackKey(window, keycode, scancode, action, mods);
358 |
359 | if (action != GLFW_PRESS && action != GLFW_RELEASE)
360 | return;
361 |
362 | ImGui_ImplGlfw_UpdateKeyModifiers(window);
363 |
364 | keycode = ImGui_ImplGlfw_TranslateUntranslatedKey(keycode, scancode);
365 |
366 | ImGuiIO& io = ImGui::GetIO();
367 | ImGuiKey imgui_key = ImGui_ImplGlfw_KeyToImGuiKey(keycode);
368 | io.AddKeyEvent(imgui_key, (action == GLFW_PRESS));
369 | io.SetKeyEventNativeData(imgui_key, keycode, scancode); // To support legacy indexing (<1.87 user code)
370 | }
371 |
372 | void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
373 | {
374 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
375 | if (bd->PrevUserCallbackWindowFocus != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
376 | bd->PrevUserCallbackWindowFocus(window, focused);
377 |
378 | ImGuiIO& io = ImGui::GetIO();
379 | io.AddFocusEvent(focused != 0);
380 | }
381 |
382 | void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
383 | {
384 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
385 | if (bd->PrevUserCallbackCursorPos != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
386 | bd->PrevUserCallbackCursorPos(window, x, y);
387 | if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
388 | return;
389 |
390 | ImGuiIO& io = ImGui::GetIO();
391 | io.AddMousePosEvent((float)x, (float)y);
392 | bd->LastValidMousePos = ImVec2((float)x, (float)y);
393 | }
394 |
395 | // Workaround: X11 seems to send spurious Leave/Enter events which would make us lose our position,
396 | // so we back it up and restore on Leave/Enter (see https://github.com/ocornut/imgui/issues/4984)
397 | void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
398 | {
399 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
400 | if (bd->PrevUserCallbackCursorEnter != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
401 | bd->PrevUserCallbackCursorEnter(window, entered);
402 | if (glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
403 | return;
404 |
405 | ImGuiIO& io = ImGui::GetIO();
406 | if (entered)
407 | {
408 | bd->MouseWindow = window;
409 | io.AddMousePosEvent(bd->LastValidMousePos.x, bd->LastValidMousePos.y);
410 | }
411 | else if (!entered && bd->MouseWindow == window)
412 | {
413 | bd->LastValidMousePos = io.MousePos;
414 | bd->MouseWindow = nullptr;
415 | io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
416 | }
417 | }
418 |
419 | void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
420 | {
421 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
422 | if (bd->PrevUserCallbackChar != nullptr && ImGui_ImplGlfw_ShouldChainCallback(window))
423 | bd->PrevUserCallbackChar(window, c);
424 |
425 | ImGuiIO& io = ImGui::GetIO();
426 | io.AddInputCharacter(c);
427 | }
428 |
429 | void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor*, int)
430 | {
431 | // Unused in 'master' branch but 'docking' branch will use this, so we declare it ahead of it so if you have to install callbacks you can install this one too.
432 | }
433 |
434 | #ifdef __EMSCRIPTEN__
435 | static EM_BOOL ImGui_ImplEmscripten_WheelCallback(int, const EmscriptenWheelEvent* ev, void*)
436 | {
437 | // Mimic Emscripten_HandleWheel() in SDL.
438 | // Corresponding equivalent in GLFW JS emulation layer has incorrect quantizing preventing small values. See #6096
439 | float multiplier = 0.0f;
440 | if (ev->deltaMode == DOM_DELTA_PIXEL) { multiplier = 1.0f / 100.0f; } // 100 pixels make up a step.
441 | else if (ev->deltaMode == DOM_DELTA_LINE) { multiplier = 1.0f / 3.0f; } // 3 lines make up a step.
442 | else if (ev->deltaMode == DOM_DELTA_PAGE) { multiplier = 80.0f; } // A page makes up 80 steps.
443 | float wheel_x = ev->deltaX * -multiplier;
444 | float wheel_y = ev->deltaY * -multiplier;
445 | ImGuiIO& io = ImGui::GetIO();
446 | io.AddMouseWheelEvent(wheel_x, wheel_y);
447 | //IMGUI_DEBUG_LOG("[Emsc] mode %d dx: %.2f, dy: %.2f, dz: %.2f --> feed %.2f %.2f\n", (int)ev->deltaMode, ev->deltaX, ev->deltaY, ev->deltaZ, wheel_x, wheel_y);
448 | return EM_TRUE;
449 | }
450 | #endif
451 |
452 | #ifdef _WIN32
453 | // GLFW doesn't allow to distinguish Mouse vs TouchScreen vs Pen.
454 | // Add support for Win32 (based on imgui_impl_win32), because we rely on _TouchScreen info to trickle inputs differently.
455 | static ImGuiMouseSource GetMouseSourceFromMessageExtraInfo()
456 | {
457 | LPARAM extra_info = ::GetMessageExtraInfo();
458 | if ((extra_info & 0xFFFFFF80) == 0xFF515700)
459 | return ImGuiMouseSource_Pen;
460 | if ((extra_info & 0xFFFFFF80) == 0xFF515780)
461 | return ImGuiMouseSource_TouchScreen;
462 | return ImGuiMouseSource_Mouse;
463 | }
464 | static LRESULT CALLBACK ImGui_ImplGlfw_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
465 | {
466 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
467 | switch (msg)
468 | {
469 | case WM_MOUSEMOVE: case WM_NCMOUSEMOVE:
470 | case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: case WM_LBUTTONUP:
471 | case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: case WM_RBUTTONUP:
472 | case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: case WM_MBUTTONUP:
473 | case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: case WM_XBUTTONUP:
474 | ImGui::GetIO().AddMouseSourceEvent(GetMouseSourceFromMessageExtraInfo());
475 | break;
476 | }
477 | return ::CallWindowProc(bd->GlfwWndProc, hWnd, msg, wParam, lParam);
478 | }
479 | #endif
480 |
481 | void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
482 | {
483 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
484 | IM_ASSERT(bd->InstalledCallbacks == false && "Callbacks already installed!");
485 | IM_ASSERT(bd->Window == window);
486 |
487 | bd->PrevUserCallbackWindowFocus = glfwSetWindowFocusCallback(window, ImGui_ImplGlfw_WindowFocusCallback);
488 | bd->PrevUserCallbackCursorEnter = glfwSetCursorEnterCallback(window, ImGui_ImplGlfw_CursorEnterCallback);
489 | bd->PrevUserCallbackCursorPos = glfwSetCursorPosCallback(window, ImGui_ImplGlfw_CursorPosCallback);
490 | bd->PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
491 | bd->PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
492 | bd->PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
493 | bd->PrevUserCallbackChar = glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
494 | bd->PrevUserCallbackMonitor = glfwSetMonitorCallback(ImGui_ImplGlfw_MonitorCallback);
495 | bd->InstalledCallbacks = true;
496 | }
497 |
498 | void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window)
499 | {
500 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
501 | IM_ASSERT(bd->InstalledCallbacks == true && "Callbacks not installed!");
502 | IM_ASSERT(bd->Window == window);
503 |
504 | glfwSetWindowFocusCallback(window, bd->PrevUserCallbackWindowFocus);
505 | glfwSetCursorEnterCallback(window, bd->PrevUserCallbackCursorEnter);
506 | glfwSetCursorPosCallback(window, bd->PrevUserCallbackCursorPos);
507 | glfwSetMouseButtonCallback(window, bd->PrevUserCallbackMousebutton);
508 | glfwSetScrollCallback(window, bd->PrevUserCallbackScroll);
509 | glfwSetKeyCallback(window, bd->PrevUserCallbackKey);
510 | glfwSetCharCallback(window, bd->PrevUserCallbackChar);
511 | glfwSetMonitorCallback(bd->PrevUserCallbackMonitor);
512 | bd->InstalledCallbacks = false;
513 | bd->PrevUserCallbackWindowFocus = nullptr;
514 | bd->PrevUserCallbackCursorEnter = nullptr;
515 | bd->PrevUserCallbackCursorPos = nullptr;
516 | bd->PrevUserCallbackMousebutton = nullptr;
517 | bd->PrevUserCallbackScroll = nullptr;
518 | bd->PrevUserCallbackKey = nullptr;
519 | bd->PrevUserCallbackChar = nullptr;
520 | bd->PrevUserCallbackMonitor = nullptr;
521 | }
522 |
523 | // Set to 'true' to enable chaining installed callbacks for all windows (including secondary viewports created by backends or by user.
524 | // This is 'false' by default meaning we only chain callbacks for the main viewport.
525 | // We cannot set this to 'true' by default because user callbacks code may be not testing the 'window' parameter of their callback.
526 | // If you set this to 'true' your user callback code will need to make sure you are testing the 'window' parameter.
527 | void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows)
528 | {
529 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
530 | bd->CallbacksChainForAllWindows = chain_for_all_windows;
531 | }
532 |
533 | static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, GlfwClientApi client_api)
534 | {
535 | ImGuiIO& io = ImGui::GetIO();
536 | IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!");
537 | //printf("GLFW_VERSION: %d.%d.%d (%d)", GLFW_VERSION_MAJOR, GLFW_VERSION_MINOR, GLFW_VERSION_REVISION, GLFW_VERSION_COMBINED);
538 |
539 | // Setup backend capabilities flags
540 | ImGui_ImplGlfw_Data* bd = IM_NEW(ImGui_ImplGlfw_Data)();
541 | io.BackendPlatformUserData = (void*)bd;
542 | io.BackendPlatformName = "imgui_impl_glfw";
543 | io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors; // We can honor GetMouseCursor() values (optional)
544 | io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests (optional, rarely used)
545 |
546 | bd->Window = window;
547 | bd->Time = 0.0;
548 |
549 | io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
550 | io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
551 | io.ClipboardUserData = bd->Window;
552 |
553 | // Create mouse cursors
554 | // (By design, on X11 cursors are user configurable and some cursors may be missing. When a cursor doesn't exist,
555 | // GLFW will emit an error which will often be printed by the app, so we temporarily disable error reporting.
556 | // Missing cursors will return nullptr and our _UpdateMouseCursor() function will use the Arrow cursor instead.)
557 | GLFWerrorfun prev_error_callback = glfwSetErrorCallback(nullptr);
558 | bd->MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
559 | bd->MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
560 | bd->MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR);
561 | bd->MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR);
562 | bd->MouseCursors[ImGuiMouseCursor_Hand] = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
563 | #if GLFW_HAS_NEW_CURSORS
564 | bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_RESIZE_ALL_CURSOR);
565 | bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_RESIZE_NESW_CURSOR);
566 | bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_RESIZE_NWSE_CURSOR);
567 | bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_NOT_ALLOWED_CURSOR);
568 | #else
569 | bd->MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
570 | bd->MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
571 | bd->MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
572 | bd->MouseCursors[ImGuiMouseCursor_NotAllowed] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
573 | #endif
574 | glfwSetErrorCallback(prev_error_callback);
575 | #if GLFW_HAS_GETERROR && !defined(__EMSCRIPTEN__) // Eat errors (see #5908)
576 | (void)glfwGetError(nullptr);
577 | #endif
578 |
579 | // Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
580 | if (install_callbacks)
581 | ImGui_ImplGlfw_InstallCallbacks(window);
582 | // Register Emscripten Wheel callback to workaround issue in Emscripten GLFW Emulation (#6096)
583 | // We intentionally do not check 'if (install_callbacks)' here, as some users may set it to false and call GLFW callback themselves.
584 | // FIXME: May break chaining in case user registered their own Emscripten callback?
585 | #ifdef __EMSCRIPTEN__
586 | emscripten_set_wheel_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, nullptr, false, ImGui_ImplEmscripten_WheelCallback);
587 | #endif
588 |
589 | // Set platform dependent data in viewport
590 | ImGuiViewport* main_viewport = ImGui::GetMainViewport();
591 | #ifdef _WIN32
592 | main_viewport->PlatformHandleRaw = glfwGetWin32Window(bd->Window);
593 | #elif defined(__APPLE__)
594 | main_viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(bd->Window);
595 | #else
596 | IM_UNUSED(main_viewport);
597 | #endif
598 |
599 | // Windows: register a WndProc hook so we can intercept some messages.
600 | #ifdef _WIN32
601 | bd->GlfwWndProc = (WNDPROC)::GetWindowLongPtr((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC);
602 | IM_ASSERT(bd->GlfwWndProc != nullptr);
603 | ::SetWindowLongPtr((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)ImGui_ImplGlfw_WndProc);
604 | #endif
605 |
606 | bd->ClientApi = client_api;
607 | return true;
608 | }
609 |
610 | bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks)
611 | {
612 | return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_OpenGL);
613 | }
614 |
615 | bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks)
616 | {
617 | return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_Vulkan);
618 | }
619 |
620 | bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks)
621 | {
622 | return ImGui_ImplGlfw_Init(window, install_callbacks, GlfwClientApi_Unknown);
623 | }
624 |
625 | void ImGui_ImplGlfw_Shutdown()
626 | {
627 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
628 | IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?");
629 | ImGuiIO& io = ImGui::GetIO();
630 |
631 | if (bd->InstalledCallbacks)
632 | ImGui_ImplGlfw_RestoreCallbacks(bd->Window);
633 |
634 | for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_COUNT; cursor_n++)
635 | glfwDestroyCursor(bd->MouseCursors[cursor_n]);
636 |
637 | // Windows: register a WndProc hook so we can intercept some messages.
638 | #ifdef _WIN32
639 | ImGuiViewport* main_viewport = ImGui::GetMainViewport();
640 | ::SetWindowLongPtr((HWND)main_viewport->PlatformHandleRaw, GWLP_WNDPROC, (LONG_PTR)bd->GlfwWndProc);
641 | bd->GlfwWndProc = nullptr;
642 | #endif
643 |
644 | io.BackendPlatformName = nullptr;
645 | io.BackendPlatformUserData = nullptr;
646 | io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasSetMousePos | ImGuiBackendFlags_HasGamepad);
647 | IM_DELETE(bd);
648 | }
649 |
650 | static void ImGui_ImplGlfw_UpdateMouseData()
651 | {
652 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
653 | ImGuiIO& io = ImGui::GetIO();
654 |
655 | if (glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
656 | {
657 | io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
658 | return;
659 | }
660 |
661 | // (those braces are here to reduce diff with multi-viewports support in 'docking' branch)
662 | {
663 | GLFWwindow* window = bd->Window;
664 |
665 | #ifdef __EMSCRIPTEN__
666 | const bool is_window_focused = true;
667 | #else
668 | const bool is_window_focused = glfwGetWindowAttrib(window, GLFW_FOCUSED) != 0;
669 | #endif
670 | if (is_window_focused)
671 | {
672 | // (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
673 | if (io.WantSetMousePos)
674 | glfwSetCursorPos(window, (double)io.MousePos.x, (double)io.MousePos.y);
675 |
676 | // (Optional) Fallback to provide mouse position when focused (ImGui_ImplGlfw_CursorPosCallback already provides this when hovered or captured)
677 | if (bd->MouseWindow == nullptr)
678 | {
679 | double mouse_x, mouse_y;
680 | glfwGetCursorPos(window, &mouse_x, &mouse_y);
681 | bd->LastValidMousePos = ImVec2((float)mouse_x, (float)mouse_y);
682 | io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
683 | }
684 | }
685 | }
686 | }
687 |
688 | static void ImGui_ImplGlfw_UpdateMouseCursor()
689 | {
690 | ImGuiIO& io = ImGui::GetIO();
691 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
692 | if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) || glfwGetInputMode(bd->Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
693 | return;
694 |
695 | ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
696 | // (those braces are here to reduce diff with multi-viewports support in 'docking' branch)
697 | {
698 | GLFWwindow* window = bd->Window;
699 | if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
700 | {
701 | // Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
702 | glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
703 | }
704 | else
705 | {
706 | // Show OS mouse cursor
707 | // FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
708 | glfwSetCursor(window, bd->MouseCursors[imgui_cursor] ? bd->MouseCursors[imgui_cursor] : bd->MouseCursors[ImGuiMouseCursor_Arrow]);
709 | glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
710 | }
711 | }
712 | }
713 |
714 | // Update gamepad inputs
715 | static inline float Saturate(float v) { return v < 0.0f ? 0.0f : v > 1.0f ? 1.0f : v; }
716 | static void ImGui_ImplGlfw_UpdateGamepads()
717 | {
718 | ImGuiIO& io = ImGui::GetIO();
719 | if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0) // FIXME: Technically feeding gamepad shouldn't depend on this now that they are regular inputs.
720 | return;
721 |
722 | io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
723 | #if GLFW_HAS_GAMEPAD_API && !defined(__EMSCRIPTEN__)
724 | GLFWgamepadstate gamepad;
725 | if (!glfwGetGamepadState(GLFW_JOYSTICK_1, &gamepad))
726 | return;
727 | #define MAP_BUTTON(KEY_NO, BUTTON_NO, _UNUSED) do { io.AddKeyEvent(KEY_NO, gamepad.buttons[BUTTON_NO] != 0); } while (0)
728 | #define MAP_ANALOG(KEY_NO, AXIS_NO, _UNUSED, V0, V1) do { float v = gamepad.axes[AXIS_NO]; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
729 | #else
730 | int axes_count = 0, buttons_count = 0;
731 | const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_1, &axes_count);
732 | const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_1, &buttons_count);
733 | if (axes_count == 0 || buttons_count == 0)
734 | return;
735 | #define MAP_BUTTON(KEY_NO, _UNUSED, BUTTON_NO) do { io.AddKeyEvent(KEY_NO, (buttons_count > BUTTON_NO && buttons[BUTTON_NO] == GLFW_PRESS)); } while (0)
736 | #define MAP_ANALOG(KEY_NO, _UNUSED, AXIS_NO, V0, V1) do { float v = (axes_count > AXIS_NO) ? axes[AXIS_NO] : V0; v = (v - V0) / (V1 - V0); io.AddKeyAnalogEvent(KEY_NO, v > 0.10f, Saturate(v)); } while (0)
737 | #endif
738 | io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
739 | MAP_BUTTON(ImGuiKey_GamepadStart, GLFW_GAMEPAD_BUTTON_START, 7);
740 | MAP_BUTTON(ImGuiKey_GamepadBack, GLFW_GAMEPAD_BUTTON_BACK, 6);
741 | MAP_BUTTON(ImGuiKey_GamepadFaceLeft, GLFW_GAMEPAD_BUTTON_X, 2); // Xbox X, PS Square
742 | MAP_BUTTON(ImGuiKey_GamepadFaceRight, GLFW_GAMEPAD_BUTTON_B, 1); // Xbox B, PS Circle
743 | MAP_BUTTON(ImGuiKey_GamepadFaceUp, GLFW_GAMEPAD_BUTTON_Y, 3); // Xbox Y, PS Triangle
744 | MAP_BUTTON(ImGuiKey_GamepadFaceDown, GLFW_GAMEPAD_BUTTON_A, 0); // Xbox A, PS Cross
745 | MAP_BUTTON(ImGuiKey_GamepadDpadLeft, GLFW_GAMEPAD_BUTTON_DPAD_LEFT, 13);
746 | MAP_BUTTON(ImGuiKey_GamepadDpadRight, GLFW_GAMEPAD_BUTTON_DPAD_RIGHT, 11);
747 | MAP_BUTTON(ImGuiKey_GamepadDpadUp, GLFW_GAMEPAD_BUTTON_DPAD_UP, 10);
748 | MAP_BUTTON(ImGuiKey_GamepadDpadDown, GLFW_GAMEPAD_BUTTON_DPAD_DOWN, 12);
749 | MAP_BUTTON(ImGuiKey_GamepadL1, GLFW_GAMEPAD_BUTTON_LEFT_BUMPER, 4);
750 | MAP_BUTTON(ImGuiKey_GamepadR1, GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER, 5);
751 | MAP_ANALOG(ImGuiKey_GamepadL2, GLFW_GAMEPAD_AXIS_LEFT_TRIGGER, 4, -0.75f, +1.0f);
752 | MAP_ANALOG(ImGuiKey_GamepadR2, GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER, 5, -0.75f, +1.0f);
753 | MAP_BUTTON(ImGuiKey_GamepadL3, GLFW_GAMEPAD_BUTTON_LEFT_THUMB, 8);
754 | MAP_BUTTON(ImGuiKey_GamepadR3, GLFW_GAMEPAD_BUTTON_RIGHT_THUMB, 9);
755 | MAP_ANALOG(ImGuiKey_GamepadLStickLeft, GLFW_GAMEPAD_AXIS_LEFT_X, 0, -0.25f, -1.0f);
756 | MAP_ANALOG(ImGuiKey_GamepadLStickRight, GLFW_GAMEPAD_AXIS_LEFT_X, 0, +0.25f, +1.0f);
757 | MAP_ANALOG(ImGuiKey_GamepadLStickUp, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, -0.25f, -1.0f);
758 | MAP_ANALOG(ImGuiKey_GamepadLStickDown, GLFW_GAMEPAD_AXIS_LEFT_Y, 1, +0.25f, +1.0f);
759 | MAP_ANALOG(ImGuiKey_GamepadRStickLeft, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, -0.25f, -1.0f);
760 | MAP_ANALOG(ImGuiKey_GamepadRStickRight, GLFW_GAMEPAD_AXIS_RIGHT_X, 2, +0.25f, +1.0f);
761 | MAP_ANALOG(ImGuiKey_GamepadRStickUp, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, -0.25f, -1.0f);
762 | MAP_ANALOG(ImGuiKey_GamepadRStickDown, GLFW_GAMEPAD_AXIS_RIGHT_Y, 3, +0.25f, +1.0f);
763 | #undef MAP_BUTTON
764 | #undef MAP_ANALOG
765 | }
766 |
767 | void ImGui_ImplGlfw_NewFrame()
768 | {
769 | ImGuiIO& io = ImGui::GetIO();
770 | ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
771 | IM_ASSERT(bd != nullptr && "Did you call ImGui_ImplGlfw_InitForXXX()?");
772 |
773 | // Setup display size (every frame to accommodate for window resizing)
774 | int w, h;
775 | int display_w, display_h;
776 | glfwGetWindowSize(bd->Window, &w, &h);
777 | glfwGetFramebufferSize(bd->Window, &display_w, &display_h);
778 | io.DisplaySize = ImVec2((float)w, (float)h);
779 | if (w > 0 && h > 0)
780 | io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);
781 |
782 | // Setup time step
783 | double current_time = glfwGetTime();
784 | io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
785 | bd->Time = current_time;
786 |
787 | ImGui_ImplGlfw_UpdateMouseData();
788 | ImGui_ImplGlfw_UpdateMouseCursor();
789 |
790 | // Update game controllers (if enabled and available)
791 | ImGui_ImplGlfw_UpdateGamepads();
792 | }
793 |
794 | #if defined(__clang__)
795 | #pragma clang diagnostic pop
796 | #endif
797 |
--------------------------------------------------------------------------------
/showcase/imgui/backends/imgui_impl_glfw.h:
--------------------------------------------------------------------------------
1 | // dear imgui: Platform Backend for GLFW
2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..)
3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
4 |
5 | // Implemented features:
6 | // [X] Platform: Clipboard support.
7 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only).
8 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
9 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
10 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+).
11 |
12 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
13 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
14 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
15 | // Read online: https://github.com/ocornut/imgui/tree/master/docs
16 |
17 | #pragma once
18 | #include "imgui.h" // IMGUI_IMPL_API
19 |
20 | struct GLFWwindow;
21 | struct GLFWmonitor;
22 |
23 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks);
24 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks);
25 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks);
26 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown();
27 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
28 |
29 | // GLFW callbacks install
30 | // - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any.
31 | // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks.
32 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window);
33 | IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window);
34 |
35 | // GFLW callbacks options:
36 | // - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user)
37 | IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows);
38 |
39 | // GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks)
40 | IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84
41 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84
42 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87
43 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
44 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
45 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
46 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
47 | IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event);
48 |
--------------------------------------------------------------------------------
/showcase/imgui/backends/imgui_impl_opengl3.h:
--------------------------------------------------------------------------------
1 | // dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline
2 | // - Desktop GL: 2.x 3.x 4.x
3 | // - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0)
4 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
5 |
6 | // Implemented features:
7 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID!
8 | // [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only).
9 |
10 | // About WebGL/ES:
11 | // - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES.
12 | // - This is done automatically on iOS, Android and Emscripten targets.
13 | // - For other targets, the define needs to be visible from the imgui_impl_opengl3.cpp compilation unit. If unsure, define globally or in imconfig.h.
14 |
15 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
16 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
17 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
18 | // Read online: https://github.com/ocornut/imgui/tree/master/docs
19 |
20 | // About GLSL version:
21 | // The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string.
22 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es"
23 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp.
24 |
25 | #pragma once
26 | #include "imgui.h" // IMGUI_IMPL_API
27 |
28 | // Backend API
29 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr);
30 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown();
31 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame();
32 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data);
33 |
34 | // (Optional) Called by Init/NewFrame/Shutdown
35 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture();
36 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture();
37 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects();
38 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects();
39 |
40 | // Specific OpenGL ES versions
41 | //#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten
42 | //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android
43 |
44 | // You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line.
45 | #if !defined(IMGUI_IMPL_OPENGL_ES2) \
46 | && !defined(IMGUI_IMPL_OPENGL_ES3)
47 |
48 | // Try to detect GLES on matching platforms
49 | #if defined(__APPLE__)
50 | #include
51 | #endif
52 | #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__))
53 | #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es"
54 | #elif defined(__EMSCRIPTEN__) || defined(__amigaos4__)
55 | #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100"
56 | #else
57 | // Otherwise imgui_impl_opengl3_loader.h will be used.
58 | #endif
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/showcase/imgui/backends/imgui_impl_opengl3_loader.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // About imgui_impl_opengl3_loader.h:
3 | //
4 | // We embed our own OpenGL loader to not require user to provide their own or to have to use ours,
5 | // which proved to be endless problems for users.
6 | // Our loader is custom-generated, based on gl3w but automatically filtered to only include
7 | // enums/functions that we use in our imgui_impl_opengl3.cpp source file in order to be small.
8 | //
9 | // YOU SHOULD NOT NEED TO INCLUDE/USE THIS DIRECTLY. THIS IS USED BY imgui_impl_opengl3.cpp ONLY.
10 | // THE REST OF YOUR APP SHOULD USE A DIFFERENT GL LOADER: ANY GL LOADER OF YOUR CHOICE.
11 | //
12 | // IF YOU GET BUILD ERRORS IN THIS FILE (commonly macro redefinitions or function redefinitions):
13 | // IT LIKELY MEANS THAT YOU ARE BUILDING 'imgui_impl_opengl3.cpp' OR INCUDING 'imgui_impl_opengl3_loader.h'
14 | // IN THE SAME COMPILATION UNIT AS ONE OF YOUR FILE WHICH IS USING A THIRD-PARTY OPENGL LOADER.
15 | // (e.g. COULD HAPPEN IF YOU ARE DOING A UNITY/JUMBO BUILD, OR INCLUDING .CPP FILES FROM OTHERS)
16 | // YOU SHOULD NOT BUILD BOTH IN THE SAME COMPILATION UNIT.
17 | // BUT IF YOU REALLY WANT TO, you can '#define IMGUI_IMPL_OPENGL_LOADER_CUSTOM' and imgui_impl_opengl3.cpp
18 | // WILL NOT BE USING OUR LOADER, AND INSTEAD EXPECT ANOTHER/YOUR LOADER TO BE AVAILABLE IN THE COMPILATION UNIT.
19 | //
20 | // Regenerate with:
21 | // python gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
22 | //
23 | // More info:
24 | // https://github.com/dearimgui/gl3w_stripped
25 | // https://github.com/ocornut/imgui/issues/4445
26 | //-----------------------------------------------------------------------------
27 |
28 | /*
29 | * This file was generated with gl3w_gen.py, part of imgl3w
30 | * (hosted at https://github.com/dearimgui/gl3w_stripped)
31 | *
32 | * This is free and unencumbered software released into the public domain.
33 | *
34 | * Anyone is free to copy, modify, publish, use, compile, sell, or
35 | * distribute this software, either in source code form or as a compiled
36 | * binary, for any purpose, commercial or non-commercial, and by any
37 | * means.
38 | *
39 | * In jurisdictions that recognize copyright laws, the author or authors
40 | * of this software dedicate any and all copyright interest in the
41 | * software to the public domain. We make this dedication for the benefit
42 | * of the public at large and to the detriment of our heirs and
43 | * successors. We intend this dedication to be an overt act of
44 | * relinquishment in perpetuity of all present and future rights to this
45 | * software under copyright law.
46 | *
47 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
50 | * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
51 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
52 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
53 | * OTHER DEALINGS IN THE SOFTWARE.
54 | */
55 |
56 | #ifndef __gl3w_h_
57 | #define __gl3w_h_
58 |
59 | // Adapted from KHR/khrplatform.h to avoid including entire file.
60 | #ifndef __khrplatform_h_
61 | typedef float khronos_float_t;
62 | typedef signed char khronos_int8_t;
63 | typedef unsigned char khronos_uint8_t;
64 | typedef signed short int khronos_int16_t;
65 | typedef unsigned short int khronos_uint16_t;
66 | #ifdef _WIN64
67 | typedef signed long long int khronos_intptr_t;
68 | typedef signed long long int khronos_ssize_t;
69 | #else
70 | typedef signed long int khronos_intptr_t;
71 | typedef signed long int khronos_ssize_t;
72 | #endif
73 |
74 | #if defined(_MSC_VER) && !defined(__clang__)
75 | typedef signed __int64 khronos_int64_t;
76 | typedef unsigned __int64 khronos_uint64_t;
77 | #elif (defined(__clang__) || defined(__GNUC__)) && (__cplusplus < 201100)
78 | #include
79 | typedef int64_t khronos_int64_t;
80 | typedef uint64_t khronos_uint64_t;
81 | #else
82 | typedef signed long long khronos_int64_t;
83 | typedef unsigned long long khronos_uint64_t;
84 | #endif
85 | #endif // __khrplatform_h_
86 |
87 | #ifndef __gl_glcorearb_h_
88 | #define __gl_glcorearb_h_ 1
89 | #ifdef __cplusplus
90 | extern "C" {
91 | #endif
92 | /*
93 | ** Copyright 2013-2020 The Khronos Group Inc.
94 | ** SPDX-License-Identifier: MIT
95 | **
96 | ** This header is generated from the Khronos OpenGL / OpenGL ES XML
97 | ** API Registry. The current version of the Registry, generator scripts
98 | ** used to make the header, and the header can be found at
99 | ** https://github.com/KhronosGroup/OpenGL-Registry
100 | */
101 | #if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__)
102 | #ifndef WIN32_LEAN_AND_MEAN
103 | #define WIN32_LEAN_AND_MEAN 1
104 | #endif
105 | #include
106 | #endif
107 | #ifndef APIENTRY
108 | #define APIENTRY
109 | #endif
110 | #ifndef APIENTRYP
111 | #define APIENTRYP APIENTRY *
112 | #endif
113 | #ifndef GLAPI
114 | #define GLAPI extern
115 | #endif
116 | /* glcorearb.h is for use with OpenGL core profile implementations.
117 | ** It should should be placed in the same directory as gl.h and
118 | ** included as .
119 | **
120 | ** glcorearb.h includes only APIs in the latest OpenGL core profile
121 | ** implementation together with APIs in newer ARB extensions which
122 | ** can be supported by the core profile. It does not, and never will
123 | ** include functionality removed from the core profile, such as
124 | ** fixed-function vertex and fragment processing.
125 | **
126 | ** Do not #include both and either of or
127 | ** in the same source file.
128 | */
129 | /* Generated C header for:
130 | * API: gl
131 | * Profile: core
132 | * Versions considered: .*
133 | * Versions emitted: .*
134 | * Default extensions included: glcore
135 | * Additional extensions included: _nomatch_^
136 | * Extensions removed: _nomatch_^
137 | */
138 | #ifndef GL_VERSION_1_0
139 | typedef void GLvoid;
140 | typedef unsigned int GLenum;
141 |
142 | typedef khronos_float_t GLfloat;
143 | typedef int GLint;
144 | typedef int GLsizei;
145 | typedef unsigned int GLbitfield;
146 | typedef double GLdouble;
147 | typedef unsigned int GLuint;
148 | typedef unsigned char GLboolean;
149 | typedef khronos_uint8_t GLubyte;
150 | #define GL_COLOR_BUFFER_BIT 0x00004000
151 | #define GL_FALSE 0
152 | #define GL_TRUE 1
153 | #define GL_TRIANGLES 0x0004
154 | #define GL_ONE 1
155 | #define GL_SRC_ALPHA 0x0302
156 | #define GL_ONE_MINUS_SRC_ALPHA 0x0303
157 | #define GL_FRONT 0x0404
158 | #define GL_BACK 0x0405
159 | #define GL_FRONT_AND_BACK 0x0408
160 | #define GL_POLYGON_MODE 0x0B40
161 | #define GL_CULL_FACE 0x0B44
162 | #define GL_DEPTH_TEST 0x0B71
163 | #define GL_STENCIL_TEST 0x0B90
164 | #define GL_VIEWPORT 0x0BA2
165 | #define GL_BLEND 0x0BE2
166 | #define GL_SCISSOR_BOX 0x0C10
167 | #define GL_SCISSOR_TEST 0x0C11
168 | #define GL_UNPACK_ROW_LENGTH 0x0CF2
169 | #define GL_PACK_ALIGNMENT 0x0D05
170 | #define GL_TEXTURE_2D 0x0DE1
171 | #define GL_UNSIGNED_BYTE 0x1401
172 | #define GL_UNSIGNED_SHORT 0x1403
173 | #define GL_UNSIGNED_INT 0x1405
174 | #define GL_FLOAT 0x1406
175 | #define GL_RGBA 0x1908
176 | #define GL_FILL 0x1B02
177 | #define GL_VENDOR 0x1F00
178 | #define GL_RENDERER 0x1F01
179 | #define GL_VERSION 0x1F02
180 | #define GL_EXTENSIONS 0x1F03
181 | #define GL_LINEAR 0x2601
182 | #define GL_TEXTURE_MAG_FILTER 0x2800
183 | #define GL_TEXTURE_MIN_FILTER 0x2801
184 | typedef void (APIENTRYP PFNGLPOLYGONMODEPROC) (GLenum face, GLenum mode);
185 | typedef void (APIENTRYP PFNGLSCISSORPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
186 | typedef void (APIENTRYP PFNGLTEXPARAMETERIPROC) (GLenum target, GLenum pname, GLint param);
187 | typedef void (APIENTRYP PFNGLTEXIMAGE2DPROC) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
188 | typedef void (APIENTRYP PFNGLCLEARPROC) (GLbitfield mask);
189 | typedef void (APIENTRYP PFNGLCLEARCOLORPROC) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
190 | typedef void (APIENTRYP PFNGLDISABLEPROC) (GLenum cap);
191 | typedef void (APIENTRYP PFNGLENABLEPROC) (GLenum cap);
192 | typedef void (APIENTRYP PFNGLFLUSHPROC) (void);
193 | typedef void (APIENTRYP PFNGLPIXELSTOREIPROC) (GLenum pname, GLint param);
194 | typedef void (APIENTRYP PFNGLREADPIXELSPROC) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
195 | typedef GLenum (APIENTRYP PFNGLGETERRORPROC) (void);
196 | typedef void (APIENTRYP PFNGLGETINTEGERVPROC) (GLenum pname, GLint *data);
197 | typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGPROC) (GLenum name);
198 | typedef GLboolean (APIENTRYP PFNGLISENABLEDPROC) (GLenum cap);
199 | typedef void (APIENTRYP PFNGLVIEWPORTPROC) (GLint x, GLint y, GLsizei width, GLsizei height);
200 | #ifdef GL_GLEXT_PROTOTYPES
201 | GLAPI void APIENTRY glPolygonMode (GLenum face, GLenum mode);
202 | GLAPI void APIENTRY glScissor (GLint x, GLint y, GLsizei width, GLsizei height);
203 | GLAPI void APIENTRY glTexParameteri (GLenum target, GLenum pname, GLint param);
204 | GLAPI void APIENTRY glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels);
205 | GLAPI void APIENTRY glClear (GLbitfield mask);
206 | GLAPI void APIENTRY glClearColor (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
207 | GLAPI void APIENTRY glDisable (GLenum cap);
208 | GLAPI void APIENTRY glEnable (GLenum cap);
209 | GLAPI void APIENTRY glFlush (void);
210 | GLAPI void APIENTRY glPixelStorei (GLenum pname, GLint param);
211 | GLAPI void APIENTRY glReadPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, void *pixels);
212 | GLAPI GLenum APIENTRY glGetError (void);
213 | GLAPI void APIENTRY glGetIntegerv (GLenum pname, GLint *data);
214 | GLAPI const GLubyte *APIENTRY glGetString (GLenum name);
215 | GLAPI GLboolean APIENTRY glIsEnabled (GLenum cap);
216 | GLAPI void APIENTRY glViewport (GLint x, GLint y, GLsizei width, GLsizei height);
217 | #endif
218 | #endif /* GL_VERSION_1_0 */
219 | #ifndef GL_VERSION_1_1
220 | typedef khronos_float_t GLclampf;
221 | typedef double GLclampd;
222 | #define GL_TEXTURE_BINDING_2D 0x8069
223 | typedef void (APIENTRYP PFNGLDRAWELEMENTSPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices);
224 | typedef void (APIENTRYP PFNGLBINDTEXTUREPROC) (GLenum target, GLuint texture);
225 | typedef void (APIENTRYP PFNGLDELETETEXTURESPROC) (GLsizei n, const GLuint *textures);
226 | typedef void (APIENTRYP PFNGLGENTEXTURESPROC) (GLsizei n, GLuint *textures);
227 | #ifdef GL_GLEXT_PROTOTYPES
228 | GLAPI void APIENTRY glDrawElements (GLenum mode, GLsizei count, GLenum type, const void *indices);
229 | GLAPI void APIENTRY glBindTexture (GLenum target, GLuint texture);
230 | GLAPI void APIENTRY glDeleteTextures (GLsizei n, const GLuint *textures);
231 | GLAPI void APIENTRY glGenTextures (GLsizei n, GLuint *textures);
232 | #endif
233 | #endif /* GL_VERSION_1_1 */
234 | #ifndef GL_VERSION_1_3
235 | #define GL_TEXTURE0 0x84C0
236 | #define GL_ACTIVE_TEXTURE 0x84E0
237 | typedef void (APIENTRYP PFNGLACTIVETEXTUREPROC) (GLenum texture);
238 | #ifdef GL_GLEXT_PROTOTYPES
239 | GLAPI void APIENTRY glActiveTexture (GLenum texture);
240 | #endif
241 | #endif /* GL_VERSION_1_3 */
242 | #ifndef GL_VERSION_1_4
243 | #define GL_BLEND_DST_RGB 0x80C8
244 | #define GL_BLEND_SRC_RGB 0x80C9
245 | #define GL_BLEND_DST_ALPHA 0x80CA
246 | #define GL_BLEND_SRC_ALPHA 0x80CB
247 | #define GL_FUNC_ADD 0x8006
248 | typedef void (APIENTRYP PFNGLBLENDFUNCSEPARATEPROC) (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
249 | typedef void (APIENTRYP PFNGLBLENDEQUATIONPROC) (GLenum mode);
250 | #ifdef GL_GLEXT_PROTOTYPES
251 | GLAPI void APIENTRY glBlendFuncSeparate (GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha);
252 | GLAPI void APIENTRY glBlendEquation (GLenum mode);
253 | #endif
254 | #endif /* GL_VERSION_1_4 */
255 | #ifndef GL_VERSION_1_5
256 | typedef khronos_ssize_t GLsizeiptr;
257 | typedef khronos_intptr_t GLintptr;
258 | #define GL_ARRAY_BUFFER 0x8892
259 | #define GL_ELEMENT_ARRAY_BUFFER 0x8893
260 | #define GL_ARRAY_BUFFER_BINDING 0x8894
261 | #define GL_ELEMENT_ARRAY_BUFFER_BINDING 0x8895
262 | #define GL_STREAM_DRAW 0x88E0
263 | typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint buffer);
264 | typedef void (APIENTRYP PFNGLDELETEBUFFERSPROC) (GLsizei n, const GLuint *buffers);
265 | typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
266 | typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
267 | typedef void (APIENTRYP PFNGLBUFFERSUBDATAPROC) (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
268 | #ifdef GL_GLEXT_PROTOTYPES
269 | GLAPI void APIENTRY glBindBuffer (GLenum target, GLuint buffer);
270 | GLAPI void APIENTRY glDeleteBuffers (GLsizei n, const GLuint *buffers);
271 | GLAPI void APIENTRY glGenBuffers (GLsizei n, GLuint *buffers);
272 | GLAPI void APIENTRY glBufferData (GLenum target, GLsizeiptr size, const void *data, GLenum usage);
273 | GLAPI void APIENTRY glBufferSubData (GLenum target, GLintptr offset, GLsizeiptr size, const void *data);
274 | #endif
275 | #endif /* GL_VERSION_1_5 */
276 | #ifndef GL_VERSION_2_0
277 | typedef char GLchar;
278 | typedef khronos_int16_t GLshort;
279 | typedef khronos_int8_t GLbyte;
280 | typedef khronos_uint16_t GLushort;
281 | #define GL_BLEND_EQUATION_RGB 0x8009
282 | #define GL_VERTEX_ATTRIB_ARRAY_ENABLED 0x8622
283 | #define GL_VERTEX_ATTRIB_ARRAY_SIZE 0x8623
284 | #define GL_VERTEX_ATTRIB_ARRAY_STRIDE 0x8624
285 | #define GL_VERTEX_ATTRIB_ARRAY_TYPE 0x8625
286 | #define GL_VERTEX_ATTRIB_ARRAY_POINTER 0x8645
287 | #define GL_BLEND_EQUATION_ALPHA 0x883D
288 | #define GL_VERTEX_ATTRIB_ARRAY_NORMALIZED 0x886A
289 | #define GL_FRAGMENT_SHADER 0x8B30
290 | #define GL_VERTEX_SHADER 0x8B31
291 | #define GL_COMPILE_STATUS 0x8B81
292 | #define GL_LINK_STATUS 0x8B82
293 | #define GL_INFO_LOG_LENGTH 0x8B84
294 | #define GL_CURRENT_PROGRAM 0x8B8D
295 | #define GL_UPPER_LEFT 0x8CA2
296 | typedef void (APIENTRYP PFNGLBLENDEQUATIONSEPARATEPROC) (GLenum modeRGB, GLenum modeAlpha);
297 | typedef void (APIENTRYP PFNGLATTACHSHADERPROC) (GLuint program, GLuint shader);
298 | typedef void (APIENTRYP PFNGLCOMPILESHADERPROC) (GLuint shader);
299 | typedef GLuint (APIENTRYP PFNGLCREATEPROGRAMPROC) (void);
300 | typedef GLuint (APIENTRYP PFNGLCREATESHADERPROC) (GLenum type);
301 | typedef void (APIENTRYP PFNGLDELETEPROGRAMPROC) (GLuint program);
302 | typedef void (APIENTRYP PFNGLDELETESHADERPROC) (GLuint shader);
303 | typedef void (APIENTRYP PFNGLDETACHSHADERPROC) (GLuint program, GLuint shader);
304 | typedef void (APIENTRYP PFNGLDISABLEVERTEXATTRIBARRAYPROC) (GLuint index);
305 | typedef void (APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index);
306 | typedef GLint (APIENTRYP PFNGLGETATTRIBLOCATIONPROC) (GLuint program, const GLchar *name);
307 | typedef void (APIENTRYP PFNGLGETPROGRAMIVPROC) (GLuint program, GLenum pname, GLint *params);
308 | typedef void (APIENTRYP PFNGLGETPROGRAMINFOLOGPROC) (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
309 | typedef void (APIENTRYP PFNGLGETSHADERIVPROC) (GLuint shader, GLenum pname, GLint *params);
310 | typedef void (APIENTRYP PFNGLGETSHADERINFOLOGPROC) (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
311 | typedef GLint (APIENTRYP PFNGLGETUNIFORMLOCATIONPROC) (GLuint program, const GLchar *name);
312 | typedef void (APIENTRYP PFNGLGETVERTEXATTRIBIVPROC) (GLuint index, GLenum pname, GLint *params);
313 | typedef void (APIENTRYP PFNGLGETVERTEXATTRIBPOINTERVPROC) (GLuint index, GLenum pname, void **pointer);
314 | typedef GLboolean (APIENTRYP PFNGLISPROGRAMPROC) (GLuint program);
315 | typedef void (APIENTRYP PFNGLLINKPROGRAMPROC) (GLuint program);
316 | typedef void (APIENTRYP PFNGLSHADERSOURCEPROC) (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
317 | typedef void (APIENTRYP PFNGLUSEPROGRAMPROC) (GLuint program);
318 | typedef void (APIENTRYP PFNGLUNIFORM1IPROC) (GLint location, GLint v0);
319 | typedef void (APIENTRYP PFNGLUNIFORMMATRIX4FVPROC) (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
320 | typedef void (APIENTRYP PFNGLVERTEXATTRIBPOINTERPROC) (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
321 | #ifdef GL_GLEXT_PROTOTYPES
322 | GLAPI void APIENTRY glBlendEquationSeparate (GLenum modeRGB, GLenum modeAlpha);
323 | GLAPI void APIENTRY glAttachShader (GLuint program, GLuint shader);
324 | GLAPI void APIENTRY glCompileShader (GLuint shader);
325 | GLAPI GLuint APIENTRY glCreateProgram (void);
326 | GLAPI GLuint APIENTRY glCreateShader (GLenum type);
327 | GLAPI void APIENTRY glDeleteProgram (GLuint program);
328 | GLAPI void APIENTRY glDeleteShader (GLuint shader);
329 | GLAPI void APIENTRY glDetachShader (GLuint program, GLuint shader);
330 | GLAPI void APIENTRY glDisableVertexAttribArray (GLuint index);
331 | GLAPI void APIENTRY glEnableVertexAttribArray (GLuint index);
332 | GLAPI GLint APIENTRY glGetAttribLocation (GLuint program, const GLchar *name);
333 | GLAPI void APIENTRY glGetProgramiv (GLuint program, GLenum pname, GLint *params);
334 | GLAPI void APIENTRY glGetProgramInfoLog (GLuint program, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
335 | GLAPI void APIENTRY glGetShaderiv (GLuint shader, GLenum pname, GLint *params);
336 | GLAPI void APIENTRY glGetShaderInfoLog (GLuint shader, GLsizei bufSize, GLsizei *length, GLchar *infoLog);
337 | GLAPI GLint APIENTRY glGetUniformLocation (GLuint program, const GLchar *name);
338 | GLAPI void APIENTRY glGetVertexAttribiv (GLuint index, GLenum pname, GLint *params);
339 | GLAPI void APIENTRY glGetVertexAttribPointerv (GLuint index, GLenum pname, void **pointer);
340 | GLAPI GLboolean APIENTRY glIsProgram (GLuint program);
341 | GLAPI void APIENTRY glLinkProgram (GLuint program);
342 | GLAPI void APIENTRY glShaderSource (GLuint shader, GLsizei count, const GLchar *const*string, const GLint *length);
343 | GLAPI void APIENTRY glUseProgram (GLuint program);
344 | GLAPI void APIENTRY glUniform1i (GLint location, GLint v0);
345 | GLAPI void APIENTRY glUniformMatrix4fv (GLint location, GLsizei count, GLboolean transpose, const GLfloat *value);
346 | GLAPI void APIENTRY glVertexAttribPointer (GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
347 | #endif
348 | #endif /* GL_VERSION_2_0 */
349 | #ifndef GL_VERSION_3_0
350 | typedef khronos_uint16_t GLhalf;
351 | #define GL_MAJOR_VERSION 0x821B
352 | #define GL_MINOR_VERSION 0x821C
353 | #define GL_NUM_EXTENSIONS 0x821D
354 | #define GL_FRAMEBUFFER_SRGB 0x8DB9
355 | #define GL_VERTEX_ARRAY_BINDING 0x85B5
356 | typedef void (APIENTRYP PFNGLGETBOOLEANI_VPROC) (GLenum target, GLuint index, GLboolean *data);
357 | typedef void (APIENTRYP PFNGLGETINTEGERI_VPROC) (GLenum target, GLuint index, GLint *data);
358 | typedef const GLubyte *(APIENTRYP PFNGLGETSTRINGIPROC) (GLenum name, GLuint index);
359 | typedef void (APIENTRYP PFNGLBINDVERTEXARRAYPROC) (GLuint array);
360 | typedef void (APIENTRYP PFNGLDELETEVERTEXARRAYSPROC) (GLsizei n, const GLuint *arrays);
361 | typedef void (APIENTRYP PFNGLGENVERTEXARRAYSPROC) (GLsizei n, GLuint *arrays);
362 | #ifdef GL_GLEXT_PROTOTYPES
363 | GLAPI const GLubyte *APIENTRY glGetStringi (GLenum name, GLuint index);
364 | GLAPI void APIENTRY glBindVertexArray (GLuint array);
365 | GLAPI void APIENTRY glDeleteVertexArrays (GLsizei n, const GLuint *arrays);
366 | GLAPI void APIENTRY glGenVertexArrays (GLsizei n, GLuint *arrays);
367 | #endif
368 | #endif /* GL_VERSION_3_0 */
369 | #ifndef GL_VERSION_3_1
370 | #define GL_VERSION_3_1 1
371 | #define GL_PRIMITIVE_RESTART 0x8F9D
372 | #endif /* GL_VERSION_3_1 */
373 | #ifndef GL_VERSION_3_2
374 | #define GL_VERSION_3_2 1
375 | typedef struct __GLsync *GLsync;
376 | typedef khronos_uint64_t GLuint64;
377 | typedef khronos_int64_t GLint64;
378 | #define GL_CONTEXT_COMPATIBILITY_PROFILE_BIT 0x00000002
379 | #define GL_CONTEXT_PROFILE_MASK 0x9126
380 | typedef void (APIENTRYP PFNGLDRAWELEMENTSBASEVERTEXPROC) (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
381 | typedef void (APIENTRYP PFNGLGETINTEGER64I_VPROC) (GLenum target, GLuint index, GLint64 *data);
382 | #ifdef GL_GLEXT_PROTOTYPES
383 | GLAPI void APIENTRY glDrawElementsBaseVertex (GLenum mode, GLsizei count, GLenum type, const void *indices, GLint basevertex);
384 | #endif
385 | #endif /* GL_VERSION_3_2 */
386 | #ifndef GL_VERSION_3_3
387 | #define GL_VERSION_3_3 1
388 | #define GL_SAMPLER_BINDING 0x8919
389 | typedef void (APIENTRYP PFNGLBINDSAMPLERPROC) (GLuint unit, GLuint sampler);
390 | #ifdef GL_GLEXT_PROTOTYPES
391 | GLAPI void APIENTRY glBindSampler (GLuint unit, GLuint sampler);
392 | #endif
393 | #endif /* GL_VERSION_3_3 */
394 | #ifndef GL_VERSION_4_1
395 | typedef void (APIENTRYP PFNGLGETFLOATI_VPROC) (GLenum target, GLuint index, GLfloat *data);
396 | typedef void (APIENTRYP PFNGLGETDOUBLEI_VPROC) (GLenum target, GLuint index, GLdouble *data);
397 | #endif /* GL_VERSION_4_1 */
398 | #ifndef GL_VERSION_4_3
399 | typedef void (APIENTRY *GLDEBUGPROC)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
400 | #endif /* GL_VERSION_4_3 */
401 | #ifndef GL_VERSION_4_5
402 | #define GL_CLIP_ORIGIN 0x935C
403 | typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint *param);
404 | typedef void (APIENTRYP PFNGLGETTRANSFORMFEEDBACKI64_VPROC) (GLuint xfb, GLenum pname, GLuint index, GLint64 *param);
405 | #endif /* GL_VERSION_4_5 */
406 | #ifndef GL_ARB_bindless_texture
407 | typedef khronos_uint64_t GLuint64EXT;
408 | #endif /* GL_ARB_bindless_texture */
409 | #ifndef GL_ARB_cl_event
410 | struct _cl_context;
411 | struct _cl_event;
412 | #endif /* GL_ARB_cl_event */
413 | #ifndef GL_ARB_clip_control
414 | #define GL_ARB_clip_control 1
415 | #endif /* GL_ARB_clip_control */
416 | #ifndef GL_ARB_debug_output
417 | typedef void (APIENTRY *GLDEBUGPROCARB)(GLenum source,GLenum type,GLuint id,GLenum severity,GLsizei length,const GLchar *message,const void *userParam);
418 | #endif /* GL_ARB_debug_output */
419 | #ifndef GL_EXT_EGL_image_storage
420 | typedef void *GLeglImageOES;
421 | #endif /* GL_EXT_EGL_image_storage */
422 | #ifndef GL_EXT_direct_state_access
423 | typedef void (APIENTRYP PFNGLGETFLOATI_VEXTPROC) (GLenum pname, GLuint index, GLfloat *params);
424 | typedef void (APIENTRYP PFNGLGETDOUBLEI_VEXTPROC) (GLenum pname, GLuint index, GLdouble *params);
425 | typedef void (APIENTRYP PFNGLGETPOINTERI_VEXTPROC) (GLenum pname, GLuint index, void **params);
426 | typedef void (APIENTRYP PFNGLGETVERTEXARRAYINTEGERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, GLint *param);
427 | typedef void (APIENTRYP PFNGLGETVERTEXARRAYPOINTERI_VEXTPROC) (GLuint vaobj, GLuint index, GLenum pname, void **param);
428 | #endif /* GL_EXT_direct_state_access */
429 | #ifndef GL_NV_draw_vulkan_image
430 | typedef void (APIENTRY *GLVULKANPROCNV)(void);
431 | #endif /* GL_NV_draw_vulkan_image */
432 | #ifndef GL_NV_gpu_shader5
433 | typedef khronos_int64_t GLint64EXT;
434 | #endif /* GL_NV_gpu_shader5 */
435 | #ifndef GL_NV_vertex_buffer_unified_memory
436 | typedef void (APIENTRYP PFNGLGETINTEGERUI64I_VNVPROC) (GLenum value, GLuint index, GLuint64EXT *result);
437 | #endif /* GL_NV_vertex_buffer_unified_memory */
438 | #ifdef __cplusplus
439 | }
440 | #endif
441 | #endif
442 |
443 | #ifndef GL3W_API
444 | #define GL3W_API
445 | #endif
446 |
447 | #ifndef __gl_h_
448 | #define __gl_h_
449 | #endif
450 |
451 | #ifdef __cplusplus
452 | extern "C" {
453 | #endif
454 |
455 | #define GL3W_OK 0
456 | #define GL3W_ERROR_INIT -1
457 | #define GL3W_ERROR_LIBRARY_OPEN -2
458 | #define GL3W_ERROR_OPENGL_VERSION -3
459 |
460 | typedef void (*GL3WglProc)(void);
461 | typedef GL3WglProc (*GL3WGetProcAddressProc)(const char *proc);
462 |
463 | /* gl3w api */
464 | GL3W_API int imgl3wInit(void);
465 | GL3W_API int imgl3wInit2(GL3WGetProcAddressProc proc);
466 | GL3W_API int imgl3wIsSupported(int major, int minor);
467 | GL3W_API GL3WglProc imgl3wGetProcAddress(const char *proc);
468 |
469 | /* gl3w internal state */
470 | union GL3WProcs {
471 | GL3WglProc ptr[59];
472 | struct {
473 | PFNGLACTIVETEXTUREPROC ActiveTexture;
474 | PFNGLATTACHSHADERPROC AttachShader;
475 | PFNGLBINDBUFFERPROC BindBuffer;
476 | PFNGLBINDSAMPLERPROC BindSampler;
477 | PFNGLBINDTEXTUREPROC BindTexture;
478 | PFNGLBINDVERTEXARRAYPROC BindVertexArray;
479 | PFNGLBLENDEQUATIONPROC BlendEquation;
480 | PFNGLBLENDEQUATIONSEPARATEPROC BlendEquationSeparate;
481 | PFNGLBLENDFUNCSEPARATEPROC BlendFuncSeparate;
482 | PFNGLBUFFERDATAPROC BufferData;
483 | PFNGLBUFFERSUBDATAPROC BufferSubData;
484 | PFNGLCLEARPROC Clear;
485 | PFNGLCLEARCOLORPROC ClearColor;
486 | PFNGLCOMPILESHADERPROC CompileShader;
487 | PFNGLCREATEPROGRAMPROC CreateProgram;
488 | PFNGLCREATESHADERPROC CreateShader;
489 | PFNGLDELETEBUFFERSPROC DeleteBuffers;
490 | PFNGLDELETEPROGRAMPROC DeleteProgram;
491 | PFNGLDELETESHADERPROC DeleteShader;
492 | PFNGLDELETETEXTURESPROC DeleteTextures;
493 | PFNGLDELETEVERTEXARRAYSPROC DeleteVertexArrays;
494 | PFNGLDETACHSHADERPROC DetachShader;
495 | PFNGLDISABLEPROC Disable;
496 | PFNGLDISABLEVERTEXATTRIBARRAYPROC DisableVertexAttribArray;
497 | PFNGLDRAWELEMENTSPROC DrawElements;
498 | PFNGLDRAWELEMENTSBASEVERTEXPROC DrawElementsBaseVertex;
499 | PFNGLENABLEPROC Enable;
500 | PFNGLENABLEVERTEXATTRIBARRAYPROC EnableVertexAttribArray;
501 | PFNGLFLUSHPROC Flush;
502 | PFNGLGENBUFFERSPROC GenBuffers;
503 | PFNGLGENTEXTURESPROC GenTextures;
504 | PFNGLGENVERTEXARRAYSPROC GenVertexArrays;
505 | PFNGLGETATTRIBLOCATIONPROC GetAttribLocation;
506 | PFNGLGETERRORPROC GetError;
507 | PFNGLGETINTEGERVPROC GetIntegerv;
508 | PFNGLGETPROGRAMINFOLOGPROC GetProgramInfoLog;
509 | PFNGLGETPROGRAMIVPROC GetProgramiv;
510 | PFNGLGETSHADERINFOLOGPROC GetShaderInfoLog;
511 | PFNGLGETSHADERIVPROC GetShaderiv;
512 | PFNGLGETSTRINGPROC GetString;
513 | PFNGLGETSTRINGIPROC GetStringi;
514 | PFNGLGETUNIFORMLOCATIONPROC GetUniformLocation;
515 | PFNGLGETVERTEXATTRIBPOINTERVPROC GetVertexAttribPointerv;
516 | PFNGLGETVERTEXATTRIBIVPROC GetVertexAttribiv;
517 | PFNGLISENABLEDPROC IsEnabled;
518 | PFNGLISPROGRAMPROC IsProgram;
519 | PFNGLLINKPROGRAMPROC LinkProgram;
520 | PFNGLPIXELSTOREIPROC PixelStorei;
521 | PFNGLPOLYGONMODEPROC PolygonMode;
522 | PFNGLREADPIXELSPROC ReadPixels;
523 | PFNGLSCISSORPROC Scissor;
524 | PFNGLSHADERSOURCEPROC ShaderSource;
525 | PFNGLTEXIMAGE2DPROC TexImage2D;
526 | PFNGLTEXPARAMETERIPROC TexParameteri;
527 | PFNGLUNIFORM1IPROC Uniform1i;
528 | PFNGLUNIFORMMATRIX4FVPROC UniformMatrix4fv;
529 | PFNGLUSEPROGRAMPROC UseProgram;
530 | PFNGLVERTEXATTRIBPOINTERPROC VertexAttribPointer;
531 | PFNGLVIEWPORTPROC Viewport;
532 | } gl;
533 | };
534 |
535 | GL3W_API extern union GL3WProcs imgl3wProcs;
536 |
537 | /* OpenGL functions */
538 | #define glActiveTexture imgl3wProcs.gl.ActiveTexture
539 | #define glAttachShader imgl3wProcs.gl.AttachShader
540 | #define glBindBuffer imgl3wProcs.gl.BindBuffer
541 | #define glBindSampler imgl3wProcs.gl.BindSampler
542 | #define glBindTexture imgl3wProcs.gl.BindTexture
543 | #define glBindVertexArray imgl3wProcs.gl.BindVertexArray
544 | #define glBlendEquation imgl3wProcs.gl.BlendEquation
545 | #define glBlendEquationSeparate imgl3wProcs.gl.BlendEquationSeparate
546 | #define glBlendFuncSeparate imgl3wProcs.gl.BlendFuncSeparate
547 | #define glBufferData imgl3wProcs.gl.BufferData
548 | #define glBufferSubData imgl3wProcs.gl.BufferSubData
549 | #define glClear imgl3wProcs.gl.Clear
550 | #define glClearColor imgl3wProcs.gl.ClearColor
551 | #define glCompileShader imgl3wProcs.gl.CompileShader
552 | #define glCreateProgram imgl3wProcs.gl.CreateProgram
553 | #define glCreateShader imgl3wProcs.gl.CreateShader
554 | #define glDeleteBuffers imgl3wProcs.gl.DeleteBuffers
555 | #define glDeleteProgram imgl3wProcs.gl.DeleteProgram
556 | #define glDeleteShader imgl3wProcs.gl.DeleteShader
557 | #define glDeleteTextures imgl3wProcs.gl.DeleteTextures
558 | #define glDeleteVertexArrays imgl3wProcs.gl.DeleteVertexArrays
559 | #define glDetachShader imgl3wProcs.gl.DetachShader
560 | #define glDisable imgl3wProcs.gl.Disable
561 | #define glDisableVertexAttribArray imgl3wProcs.gl.DisableVertexAttribArray
562 | #define glDrawElements imgl3wProcs.gl.DrawElements
563 | #define glDrawElementsBaseVertex imgl3wProcs.gl.DrawElementsBaseVertex
564 | #define glEnable imgl3wProcs.gl.Enable
565 | #define glEnableVertexAttribArray imgl3wProcs.gl.EnableVertexAttribArray
566 | #define glFlush imgl3wProcs.gl.Flush
567 | #define glGenBuffers imgl3wProcs.gl.GenBuffers
568 | #define glGenTextures imgl3wProcs.gl.GenTextures
569 | #define glGenVertexArrays imgl3wProcs.gl.GenVertexArrays
570 | #define glGetAttribLocation imgl3wProcs.gl.GetAttribLocation
571 | #define glGetError imgl3wProcs.gl.GetError
572 | #define glGetIntegerv imgl3wProcs.gl.GetIntegerv
573 | #define glGetProgramInfoLog imgl3wProcs.gl.GetProgramInfoLog
574 | #define glGetProgramiv imgl3wProcs.gl.GetProgramiv
575 | #define glGetShaderInfoLog imgl3wProcs.gl.GetShaderInfoLog
576 | #define glGetShaderiv imgl3wProcs.gl.GetShaderiv
577 | #define glGetString imgl3wProcs.gl.GetString
578 | #define glGetStringi imgl3wProcs.gl.GetStringi
579 | #define glGetUniformLocation imgl3wProcs.gl.GetUniformLocation
580 | #define glGetVertexAttribPointerv imgl3wProcs.gl.GetVertexAttribPointerv
581 | #define glGetVertexAttribiv imgl3wProcs.gl.GetVertexAttribiv
582 | #define glIsEnabled imgl3wProcs.gl.IsEnabled
583 | #define glIsProgram imgl3wProcs.gl.IsProgram
584 | #define glLinkProgram imgl3wProcs.gl.LinkProgram
585 | #define glPixelStorei imgl3wProcs.gl.PixelStorei
586 | #define glPolygonMode imgl3wProcs.gl.PolygonMode
587 | #define glReadPixels imgl3wProcs.gl.ReadPixels
588 | #define glScissor imgl3wProcs.gl.Scissor
589 | #define glShaderSource imgl3wProcs.gl.ShaderSource
590 | #define glTexImage2D imgl3wProcs.gl.TexImage2D
591 | #define glTexParameteri imgl3wProcs.gl.TexParameteri
592 | #define glUniform1i imgl3wProcs.gl.Uniform1i
593 | #define glUniformMatrix4fv imgl3wProcs.gl.UniformMatrix4fv
594 | #define glUseProgram imgl3wProcs.gl.UseProgram
595 | #define glVertexAttribPointer imgl3wProcs.gl.VertexAttribPointer
596 | #define glViewport imgl3wProcs.gl.Viewport
597 |
598 | #ifdef __cplusplus
599 | }
600 | #endif
601 |
602 | #endif
603 |
604 | #ifdef IMGL3W_IMPL
605 | #ifdef __cplusplus
606 | extern "C" {
607 | #endif
608 |
609 | #include
610 |
611 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
612 |
613 | #if defined(_WIN32)
614 | #ifndef WIN32_LEAN_AND_MEAN
615 | #define WIN32_LEAN_AND_MEAN 1
616 | #endif
617 | #include
618 |
619 | static HMODULE libgl;
620 | typedef PROC(__stdcall* GL3WglGetProcAddr)(LPCSTR);
621 | static GL3WglGetProcAddr wgl_get_proc_address;
622 |
623 | static int open_libgl(void)
624 | {
625 | libgl = LoadLibraryA("opengl32.dll");
626 | if (!libgl)
627 | return GL3W_ERROR_LIBRARY_OPEN;
628 | wgl_get_proc_address = (GL3WglGetProcAddr)GetProcAddress(libgl, "wglGetProcAddress");
629 | return GL3W_OK;
630 | }
631 |
632 | static void close_libgl(void) { FreeLibrary(libgl); }
633 | static GL3WglProc get_proc(const char *proc)
634 | {
635 | GL3WglProc res;
636 | res = (GL3WglProc)wgl_get_proc_address(proc);
637 | if (!res)
638 | res = (GL3WglProc)GetProcAddress(libgl, proc);
639 | return res;
640 | }
641 | #elif defined(__APPLE__)
642 | #include
643 |
644 | static void *libgl;
645 | static int open_libgl(void)
646 | {
647 | libgl = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL);
648 | if (!libgl)
649 | return GL3W_ERROR_LIBRARY_OPEN;
650 | return GL3W_OK;
651 | }
652 |
653 | static void close_libgl(void) { dlclose(libgl); }
654 |
655 | static GL3WglProc get_proc(const char *proc)
656 | {
657 | GL3WglProc res;
658 | *(void **)(&res) = dlsym(libgl, proc);
659 | return res;
660 | }
661 | #else
662 | #include
663 |
664 | static void *libgl;
665 | static GL3WglProc (*glx_get_proc_address)(const GLubyte *);
666 |
667 | static int open_libgl(void)
668 | {
669 | libgl = dlopen("libGL.so.1", RTLD_LAZY | RTLD_LOCAL);
670 | if (!libgl)
671 | return GL3W_ERROR_LIBRARY_OPEN;
672 | *(void **)(&glx_get_proc_address) = dlsym(libgl, "glXGetProcAddressARB");
673 | return GL3W_OK;
674 | }
675 |
676 | static void close_libgl(void) { dlclose(libgl); }
677 |
678 | static GL3WglProc get_proc(const char *proc)
679 | {
680 | GL3WglProc res;
681 | res = glx_get_proc_address((const GLubyte *)proc);
682 | if (!res)
683 | *(void **)(&res) = dlsym(libgl, proc);
684 | return res;
685 | }
686 | #endif
687 |
688 | static struct { int major, minor; } version;
689 |
690 | static int parse_version(void)
691 | {
692 | if (!glGetIntegerv)
693 | return GL3W_ERROR_INIT;
694 | glGetIntegerv(GL_MAJOR_VERSION, &version.major);
695 | glGetIntegerv(GL_MINOR_VERSION, &version.minor);
696 | if (version.major == 0 && version.minor == 0)
697 | {
698 | // Query GL_VERSION in desktop GL 2.x, the string will start with "."
699 | if (const char* gl_version = (const char*)glGetString(GL_VERSION))
700 | sscanf(gl_version, "%d.%d", &version.major, &version.minor);
701 | }
702 | if (version.major < 2)
703 | return GL3W_ERROR_OPENGL_VERSION;
704 | return GL3W_OK;
705 | }
706 |
707 | static void load_procs(GL3WGetProcAddressProc proc);
708 |
709 | int imgl3wInit(void)
710 | {
711 | int res = open_libgl();
712 | if (res)
713 | return res;
714 | atexit(close_libgl);
715 | return imgl3wInit2(get_proc);
716 | }
717 |
718 | int imgl3wInit2(GL3WGetProcAddressProc proc)
719 | {
720 | load_procs(proc);
721 | return parse_version();
722 | }
723 |
724 | int imgl3wIsSupported(int major, int minor)
725 | {
726 | if (major < 2)
727 | return 0;
728 | if (version.major == major)
729 | return version.minor >= minor;
730 | return version.major >= major;
731 | }
732 |
733 | GL3WglProc imgl3wGetProcAddress(const char *proc) { return get_proc(proc); }
734 |
735 | static const char *proc_names[] = {
736 | "glActiveTexture",
737 | "glAttachShader",
738 | "glBindBuffer",
739 | "glBindSampler",
740 | "glBindTexture",
741 | "glBindVertexArray",
742 | "glBlendEquation",
743 | "glBlendEquationSeparate",
744 | "glBlendFuncSeparate",
745 | "glBufferData",
746 | "glBufferSubData",
747 | "glClear",
748 | "glClearColor",
749 | "glCompileShader",
750 | "glCreateProgram",
751 | "glCreateShader",
752 | "glDeleteBuffers",
753 | "glDeleteProgram",
754 | "glDeleteShader",
755 | "glDeleteTextures",
756 | "glDeleteVertexArrays",
757 | "glDetachShader",
758 | "glDisable",
759 | "glDisableVertexAttribArray",
760 | "glDrawElements",
761 | "glDrawElementsBaseVertex",
762 | "glEnable",
763 | "glEnableVertexAttribArray",
764 | "glFlush",
765 | "glGenBuffers",
766 | "glGenTextures",
767 | "glGenVertexArrays",
768 | "glGetAttribLocation",
769 | "glGetError",
770 | "glGetIntegerv",
771 | "glGetProgramInfoLog",
772 | "glGetProgramiv",
773 | "glGetShaderInfoLog",
774 | "glGetShaderiv",
775 | "glGetString",
776 | "glGetStringi",
777 | "glGetUniformLocation",
778 | "glGetVertexAttribPointerv",
779 | "glGetVertexAttribiv",
780 | "glIsEnabled",
781 | "glIsProgram",
782 | "glLinkProgram",
783 | "glPixelStorei",
784 | "glPolygonMode",
785 | "glReadPixels",
786 | "glScissor",
787 | "glShaderSource",
788 | "glTexImage2D",
789 | "glTexParameteri",
790 | "glUniform1i",
791 | "glUniformMatrix4fv",
792 | "glUseProgram",
793 | "glVertexAttribPointer",
794 | "glViewport",
795 | };
796 |
797 | GL3W_API union GL3WProcs imgl3wProcs;
798 |
799 | static void load_procs(GL3WGetProcAddressProc proc)
800 | {
801 | size_t i;
802 | for (i = 0; i < ARRAY_SIZE(proc_names); i++)
803 | imgl3wProcs.ptr[i] = proc(proc_names[i]);
804 | }
805 |
806 | #ifdef __cplusplus
807 | }
808 | #endif
809 | #endif
810 |
--------------------------------------------------------------------------------
/showcase/imgui/freetype/imgui_freetype.cpp:
--------------------------------------------------------------------------------
1 | // dear imgui: FreeType font builder (used as a replacement for the stb_truetype builder)
2 | // (code)
3 |
4 | // Get the latest version at https://github.com/ocornut/imgui/tree/master/misc/freetype
5 | // Original code by @vuhdo (Aleksei Skriabin). Improvements by @mikesart. Maintained since 2019 by @ocornut.
6 |
7 | // CHANGELOG
8 | // (minor and older changes stripped away, please see git history for details)
9 | // 2023/01/04: fixed a packing issue which in some occurrences would prevent large amount of glyphs from being packed correctly.
10 | // 2021/08/23: fixed crash when FT_Render_Glyph() fails to render a glyph and returns NULL.
11 | // 2021/03/05: added ImGuiFreeTypeBuilderFlags_Bitmap to load bitmap glyphs.
12 | // 2021/03/02: set 'atlas->TexPixelsUseColors = true' to help some backends with deciding of a prefered texture format.
13 | // 2021/01/28: added support for color-layered glyphs via ImGuiFreeTypeBuilderFlags_LoadColor (require Freetype 2.10+).
14 | // 2021/01/26: simplified integration by using '#define IMGUI_ENABLE_FREETYPE'.
15 | // renamed ImGuiFreeType::XXX flags to ImGuiFreeTypeBuilderFlags_XXX for consistency with other API. removed ImGuiFreeType::BuildFontAtlas().
16 | // 2020/06/04: fix for rare case where FT_Get_Char_Index() succeed but FT_Load_Glyph() fails.
17 | // 2019/02/09: added RasterizerFlags::Monochrome flag to disable font anti-aliasing (combine with ::MonoHinting for best results!)
18 | // 2019/01/15: added support for imgui allocators + added FreeType only override function SetAllocatorFunctions().
19 | // 2019/01/10: re-factored to match big update in STB builder. fixed texture height waste. fixed redundant glyphs when merging. support for glyph padding.
20 | // 2018/06/08: added support for ImFontConfig::GlyphMinAdvanceX, GlyphMaxAdvanceX.
21 | // 2018/02/04: moved to main imgui repository (away from http://www.github.com/ocornut/imgui_club)
22 | // 2018/01/22: fix for addition of ImFontAtlas::TexUvscale member.
23 | // 2017/10/22: minor inconsequential change to match change in master (removed an unnecessary statement).
24 | // 2017/09/26: fixes for imgui internal changes.
25 | // 2017/08/26: cleanup, optimizations, support for ImFontConfig::RasterizerFlags, ImFontConfig::RasterizerMultiply.
26 | // 2017/08/16: imported from https://github.com/Vuhdo/imgui_freetype into http://www.github.com/ocornut/imgui_club, updated for latest changes in ImFontAtlas, minor tweaks.
27 |
28 | // About Gamma Correct Blending:
29 | // - FreeType assumes blending in linear space rather than gamma space.
30 | // - See https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Render_Glyph
31 | // - For correct results you need to be using sRGB and convert to linear space in the pixel shader output.
32 | // - The default dear imgui styles will be impacted by this change (alpha values will need tweaking).
33 |
34 | // FIXME: cfg.OversampleH, OversampleV are not supported (but perhaps not so necessary with this rasterizer).
35 | #pragma comment(lib, "freetype.lib")
36 |
37 | #include "imgui_freetype.h"
38 | #include "../imgui_internal.h" // ImMin,ImMax,ImFontAtlasBuild*,
39 | #include
40 | #include
41 |
42 | #include FT_FREETYPE_H //
43 | #include FT_MODULE_H //
44 | #include FT_GLYPH_H //
45 | #include FT_SYNTHESIS_H //
46 |
47 | #ifdef _MSC_VER
48 | #pragma warning (push)
49 | #pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
50 | #pragma warning (disable: 26812) // [Static Analyzer] The enum type 'xxx' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).
51 | #endif
52 |
53 | #ifdef __GNUC__
54 | #pragma GCC diagnostic push
55 | #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind
56 | #pragma GCC diagnostic ignored "-Wunused-function" // warning: 'xxxx' defined but not used
57 | #pragma GCC diagnostic ignored "-Wsubobject-linkage" // warning: 'xxxx' has a field 'xxxx' whose type uses the anonymous namespace
58 | #endif
59 |
60 | //-------------------------------------------------------------------------
61 | // Data
62 | //-------------------------------------------------------------------------
63 |
64 | // Default memory allocators
65 | static void* ImGuiFreeTypeDefaultAllocFunc(size_t size, void* user_data) { IM_UNUSED(user_data); return IM_ALLOC(size); }
66 | static void ImGuiFreeTypeDefaultFreeFunc(void* ptr, void* user_data) { IM_UNUSED(user_data); IM_FREE(ptr); }
67 |
68 | // Current memory allocators
69 | static void* (*GImGuiFreeTypeAllocFunc)(size_t size, void* user_data) = ImGuiFreeTypeDefaultAllocFunc;
70 | static void (*GImGuiFreeTypeFreeFunc)(void* ptr, void* user_data) = ImGuiFreeTypeDefaultFreeFunc;
71 | static void* GImGuiFreeTypeAllocatorUserData = nullptr;
72 |
73 | //-------------------------------------------------------------------------
74 | // Code
75 | //-------------------------------------------------------------------------
76 |
77 | namespace
78 | {
79 | // Glyph metrics:
80 | // --------------
81 | //
82 | // xmin xmax
83 | // | |
84 | // |<-------- width -------->|
85 | // | |
86 | // | +-------------------------+----------------- ymax
87 | // | | ggggggggg ggggg | ^ ^
88 | // | | g:::::::::ggg::::g | | |
89 | // | | g:::::::::::::::::g | | |
90 | // | | g::::::ggggg::::::gg | | |
91 | // | | g:::::g g:::::g | | |
92 | // offsetX -|-------->| g:::::g g:::::g | offsetY |
93 | // | | g:::::g g:::::g | | |
94 | // | | g::::::g g:::::g | | |
95 | // | | g:::::::ggggg:::::g | | |
96 | // | | g::::::::::::::::g | | height
97 | // | | gg::::::::::::::g | | |
98 | // baseline ---*---------|---- gggggggg::::::g-----*-------- |
99 | // / | | g:::::g | |
100 | // origin | | gggggg g:::::g | |
101 | // | | g:::::gg gg:::::g | |
102 | // | | g::::::ggg:::::::g | |
103 | // | | gg:::::::::::::g | |
104 | // | | ggg::::::ggg | |
105 | // | | gggggg | v
106 | // | +-------------------------+----------------- ymin
107 | // | |
108 | // |------------- advanceX ----------->|
109 |
110 | // A structure that describe a glyph.
111 | struct GlyphInfo
112 | {
113 | int Width; // Glyph's width in pixels.
114 | int Height; // Glyph's height in pixels.
115 | FT_Int OffsetX; // The distance from the origin ("pen position") to the left of the glyph.
116 | FT_Int OffsetY; // The distance from the origin to the top of the glyph. This is usually a value < 0.
117 | float AdvanceX; // The distance from the origin to the origin of the next glyph. This is usually a value > 0.
118 | bool IsColored; // The glyph is colored
119 | };
120 |
121 | // Font parameters and metrics.
122 | struct FontInfo
123 | {
124 | uint32_t PixelHeight; // Size this font was generated with.
125 | float Ascender; // The pixel extents above the baseline in pixels (typically positive).
126 | float Descender; // The extents below the baseline in pixels (typically negative).
127 | float LineSpacing; // The baseline-to-baseline distance. Note that it usually is larger than the sum of the ascender and descender taken as absolute values. There is also no guarantee that no glyphs extend above or below subsequent baselines when using this distance. Think of it as a value the designer of the font finds appropriate.
128 | float LineGap; // The spacing in pixels between one row's descent and the next row's ascent.
129 | float MaxAdvanceWidth; // This field gives the maximum horizontal cursor advance for all glyphs in the font.
130 | };
131 |
132 | // FreeType glyph rasterizer.
133 | // NB: No ctor/dtor, explicitly call Init()/Shutdown()
134 | struct FreeTypeFont
135 | {
136 | bool InitFont(FT_Library ft_library, const ImFontConfig& cfg, unsigned int extra_user_flags); // Initialize from an external data buffer. Doesn't copy data, and you must ensure it stays valid up to this object lifetime.
137 | void CloseFont();
138 | void SetPixelHeight(int pixel_height); // Change font pixel size. All following calls to RasterizeGlyph() will use this size
139 | const FT_Glyph_Metrics* LoadGlyph(uint32_t in_codepoint);
140 | const FT_Bitmap* RenderGlyphAndGetInfo(GlyphInfo* out_glyph_info);
141 | void BlitGlyph(const FT_Bitmap* ft_bitmap, uint32_t* dst, uint32_t dst_pitch, unsigned char* multiply_table = nullptr);
142 | ~FreeTypeFont() { CloseFont(); }
143 |
144 | // [Internals]
145 | FontInfo Info; // Font descriptor of the current font.
146 | FT_Face Face;
147 | unsigned int UserFlags; // = ImFontConfig::RasterizerFlags
148 | FT_Int32 LoadFlags;
149 | FT_Render_Mode RenderMode;
150 | };
151 |
152 | // From SDL_ttf: Handy routines for converting from fixed point
153 | #define FT_CEIL(X) (((X + 63) & -64) / 64)
154 |
155 | bool FreeTypeFont::InitFont(FT_Library ft_library, const ImFontConfig& cfg, unsigned int extra_font_builder_flags)
156 | {
157 | FT_Error error = FT_New_Memory_Face(ft_library, (uint8_t*)cfg.FontData, (uint32_t)cfg.FontDataSize, (uint32_t)cfg.FontNo, &Face);
158 | if (error != 0)
159 | return false;
160 | error = FT_Select_Charmap(Face, FT_ENCODING_UNICODE);
161 | if (error != 0)
162 | return false;
163 |
164 | // Convert to FreeType flags (NB: Bold and Oblique are processed separately)
165 | UserFlags = cfg.FontBuilderFlags | extra_font_builder_flags;
166 |
167 | LoadFlags = 0;
168 | if ((UserFlags & ImGuiFreeTypeBuilderFlags_Bitmap) == 0)
169 | LoadFlags |= FT_LOAD_NO_BITMAP;
170 |
171 | if (UserFlags & ImGuiFreeTypeBuilderFlags_NoHinting)
172 | LoadFlags |= FT_LOAD_NO_HINTING;
173 | if (UserFlags & ImGuiFreeTypeBuilderFlags_NoAutoHint)
174 | LoadFlags |= FT_LOAD_NO_AUTOHINT;
175 | if (UserFlags & ImGuiFreeTypeBuilderFlags_ForceAutoHint)
176 | LoadFlags |= FT_LOAD_FORCE_AUTOHINT;
177 | if (UserFlags & ImGuiFreeTypeBuilderFlags_LightHinting)
178 | LoadFlags |= FT_LOAD_TARGET_LIGHT;
179 | else if (UserFlags & ImGuiFreeTypeBuilderFlags_MonoHinting)
180 | LoadFlags |= FT_LOAD_TARGET_MONO;
181 | else
182 | LoadFlags |= FT_LOAD_TARGET_NORMAL;
183 |
184 | if (UserFlags & ImGuiFreeTypeBuilderFlags_Monochrome)
185 | RenderMode = FT_RENDER_MODE_MONO;
186 | else
187 | RenderMode = FT_RENDER_MODE_NORMAL;
188 |
189 | if (UserFlags & ImGuiFreeTypeBuilderFlags_LoadColor)
190 | LoadFlags |= FT_LOAD_COLOR;
191 |
192 | memset(&Info, 0, sizeof(Info));
193 | SetPixelHeight((uint32_t)cfg.SizePixels);
194 |
195 | return true;
196 | }
197 |
198 | void FreeTypeFont::CloseFont()
199 | {
200 | if (Face)
201 | {
202 | FT_Done_Face(Face);
203 | Face = nullptr;
204 | }
205 | }
206 |
207 | void FreeTypeFont::SetPixelHeight(int pixel_height)
208 | {
209 | // Vuhdo: I'm not sure how to deal with font sizes properly. As far as I understand, currently ImGui assumes that the 'pixel_height'
210 | // is a maximum height of an any given glyph, i.e. it's the sum of font's ascender and descender. Seems strange to me.
211 | // NB: FT_Set_Pixel_Sizes() doesn't seem to get us the same result.
212 | FT_Size_RequestRec req;
213 | req.type = (UserFlags & ImGuiFreeTypeBuilderFlags_Bitmap) ? FT_SIZE_REQUEST_TYPE_NOMINAL : FT_SIZE_REQUEST_TYPE_REAL_DIM;
214 | req.width = 0;
215 | req.height = (uint32_t)pixel_height * 64;
216 | req.horiResolution = 0;
217 | req.vertResolution = 0;
218 | FT_Request_Size(Face, &req);
219 |
220 | // Update font info
221 | FT_Size_Metrics metrics = Face->size->metrics;
222 | Info.PixelHeight = (uint32_t)pixel_height;
223 | Info.Ascender = (float)FT_CEIL(metrics.ascender);
224 | Info.Descender = (float)FT_CEIL(metrics.descender);
225 | Info.LineSpacing = (float)FT_CEIL(metrics.height);
226 | Info.LineGap = (float)FT_CEIL(metrics.height - metrics.ascender + metrics.descender);
227 | Info.MaxAdvanceWidth = (float)FT_CEIL(metrics.max_advance);
228 | }
229 |
230 | const FT_Glyph_Metrics* FreeTypeFont::LoadGlyph(uint32_t codepoint)
231 | {
232 | uint32_t glyph_index = FT_Get_Char_Index(Face, codepoint);
233 | if (glyph_index == 0)
234 | return nullptr;
235 |
236 | // If this crash for you: FreeType 2.11.0 has a crash bug on some bitmap/colored fonts.
237 | // - https://gitlab.freedesktop.org/freetype/freetype/-/issues/1076
238 | // - https://github.com/ocornut/imgui/issues/4567
239 | // - https://github.com/ocornut/imgui/issues/4566
240 | // You can use FreeType 2.10, or the patched version of 2.11.0 in VcPkg, or probably any upcoming FreeType version.
241 | FT_Error error = FT_Load_Glyph(Face, glyph_index, LoadFlags);
242 | if (error)
243 | return nullptr;
244 |
245 | // Need an outline for this to work
246 | FT_GlyphSlot slot = Face->glyph;
247 | IM_ASSERT(slot->format == FT_GLYPH_FORMAT_OUTLINE || slot->format == FT_GLYPH_FORMAT_BITMAP);
248 |
249 | // Apply convenience transform (this is not picking from real "Bold"/"Italic" fonts! Merely applying FreeType helper transform. Oblique == Slanting)
250 | if (UserFlags & ImGuiFreeTypeBuilderFlags_Bold)
251 | FT_GlyphSlot_Embolden(slot);
252 | if (UserFlags & ImGuiFreeTypeBuilderFlags_Oblique)
253 | {
254 | FT_GlyphSlot_Oblique(slot);
255 | //FT_BBox bbox;
256 | //FT_Outline_Get_BBox(&slot->outline, &bbox);
257 | //slot->metrics.width = bbox.xMax - bbox.xMin;
258 | //slot->metrics.height = bbox.yMax - bbox.yMin;
259 | }
260 |
261 | return &slot->metrics;
262 | }
263 |
264 | const FT_Bitmap* FreeTypeFont::RenderGlyphAndGetInfo(GlyphInfo* out_glyph_info)
265 | {
266 | FT_GlyphSlot slot = Face->glyph;
267 | FT_Error error = FT_Render_Glyph(slot, RenderMode);
268 | if (error != 0)
269 | return nullptr;
270 |
271 | FT_Bitmap* ft_bitmap = &Face->glyph->bitmap;
272 | out_glyph_info->Width = (int)ft_bitmap->width;
273 | out_glyph_info->Height = (int)ft_bitmap->rows;
274 | out_glyph_info->OffsetX = Face->glyph->bitmap_left;
275 | out_glyph_info->OffsetY = -Face->glyph->bitmap_top;
276 | out_glyph_info->AdvanceX = (float)FT_CEIL(slot->advance.x);
277 | out_glyph_info->IsColored = (ft_bitmap->pixel_mode == FT_PIXEL_MODE_BGRA);
278 |
279 | return ft_bitmap;
280 | }
281 |
282 | void FreeTypeFont::BlitGlyph(const FT_Bitmap* ft_bitmap, uint32_t* dst, uint32_t dst_pitch, unsigned char* multiply_table)
283 | {
284 | IM_ASSERT(ft_bitmap != nullptr);
285 | const uint32_t w = ft_bitmap->width;
286 | const uint32_t h = ft_bitmap->rows;
287 | const uint8_t* src = ft_bitmap->buffer;
288 | const uint32_t src_pitch = ft_bitmap->pitch;
289 |
290 | switch (ft_bitmap->pixel_mode)
291 | {
292 | case FT_PIXEL_MODE_GRAY: // Grayscale image, 1 byte per pixel.
293 | {
294 | if (multiply_table == nullptr)
295 | {
296 | for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
297 | for (uint32_t x = 0; x < w; x++)
298 | dst[x] = IM_COL32(255, 255, 255, src[x]);
299 | }
300 | else
301 | {
302 | for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
303 | for (uint32_t x = 0; x < w; x++)
304 | dst[x] = IM_COL32(255, 255, 255, multiply_table[src[x]]);
305 | }
306 | break;
307 | }
308 | case FT_PIXEL_MODE_MONO: // Monochrome image, 1 bit per pixel. The bits in each byte are ordered from MSB to LSB.
309 | {
310 | uint8_t color0 = multiply_table ? multiply_table[0] : 0;
311 | uint8_t color1 = multiply_table ? multiply_table[255] : 255;
312 | for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
313 | {
314 | uint8_t bits = 0;
315 | const uint8_t* bits_ptr = src;
316 | for (uint32_t x = 0; x < w; x++, bits <<= 1)
317 | {
318 | if ((x & 7) == 0)
319 | bits = *bits_ptr++;
320 | dst[x] = IM_COL32(255, 255, 255, (bits & 0x80) ? color1 : color0);
321 | }
322 | }
323 | break;
324 | }
325 | case FT_PIXEL_MODE_BGRA:
326 | {
327 | // FIXME: Converting pre-multiplied alpha to straight. Doesn't smell good.
328 | #define DE_MULTIPLY(color, alpha) (ImU32)(255.0f * (float)color / (float)alpha + 0.5f)
329 | if (multiply_table == nullptr)
330 | {
331 | for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
332 | for (uint32_t x = 0; x < w; x++)
333 | {
334 | uint8_t r = src[x * 4 + 2], g = src[x * 4 + 1], b = src[x * 4], a = src[x * 4 + 3];
335 | dst[x] = IM_COL32(DE_MULTIPLY(r, a), DE_MULTIPLY(g, a), DE_MULTIPLY(b, a), a);
336 | }
337 | }
338 | else
339 | {
340 | for (uint32_t y = 0; y < h; y++, src += src_pitch, dst += dst_pitch)
341 | {
342 | for (uint32_t x = 0; x < w; x++)
343 | {
344 | uint8_t r = src[x * 4 + 2], g = src[x * 4 + 1], b = src[x * 4], a = src[x * 4 + 3];
345 | dst[x] = IM_COL32(multiply_table[DE_MULTIPLY(r, a)], multiply_table[DE_MULTIPLY(g, a)], multiply_table[DE_MULTIPLY(b, a)], multiply_table[a]);
346 | }
347 | }
348 | }
349 | #undef DE_MULTIPLY
350 | break;
351 | }
352 | default:
353 | IM_ASSERT(0 && "FreeTypeFont::BlitGlyph(): Unknown bitmap pixel mode!");
354 | }
355 | }
356 | } // namespace
357 |
358 | #ifndef STB_RECT_PACK_IMPLEMENTATION // in case the user already have an implementation in the _same_ compilation unit (e.g. unity builds)
359 | #ifndef IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
360 | #define STBRP_ASSERT(x) do { IM_ASSERT(x); } while (0)
361 | #define STBRP_STATIC
362 | #define STB_RECT_PACK_IMPLEMENTATION
363 | #endif
364 | #ifdef IMGUI_STB_RECT_PACK_FILENAME
365 | #include IMGUI_STB_RECT_PACK_FILENAME
366 | #else
367 | #include "../imstb_rectpack.h"
368 | #endif
369 | #endif
370 |
371 | struct ImFontBuildSrcGlyphFT
372 | {
373 | GlyphInfo Info;
374 | uint32_t Codepoint;
375 | unsigned int* BitmapData; // Point within one of the dst_tmp_bitmap_buffers[] array
376 |
377 | ImFontBuildSrcGlyphFT() { memset((void*)this, 0, sizeof(*this)); }
378 | };
379 |
380 | struct ImFontBuildSrcDataFT
381 | {
382 | FreeTypeFont Font;
383 | stbrp_rect* Rects; // Rectangle to pack. We first fill in their size and the packer will give us their position.
384 | const ImWchar* SrcRanges; // Ranges as requested by user (user is allowed to request too much, e.g. 0x0020..0xFFFF)
385 | int DstIndex; // Index into atlas->Fonts[] and dst_tmp_array[]
386 | int GlyphsHighest; // Highest requested codepoint
387 | int GlyphsCount; // Glyph count (excluding missing glyphs and glyphs already set by an earlier source font)
388 | ImBitVector GlyphsSet; // Glyph bit map (random access, 1-bit per codepoint. This will be a maximum of 8KB)
389 | ImVector GlyphsList;
390 | };
391 |
392 | // Temporary data for one destination ImFont* (multiple source fonts can be merged into one destination ImFont)
393 | struct ImFontBuildDstDataFT
394 | {
395 | int SrcCount; // Number of source fonts targeting this destination font.
396 | int GlyphsHighest;
397 | int GlyphsCount;
398 | ImBitVector GlyphsSet; // This is used to resolve collision when multiple sources are merged into a same destination font.
399 | };
400 |
401 | bool ImFontAtlasBuildWithFreeTypeEx(FT_Library ft_library, ImFontAtlas* atlas, unsigned int extra_flags)
402 | {
403 | IM_ASSERT(atlas->ConfigData.Size > 0);
404 |
405 | ImFontAtlasBuildInit(atlas);
406 |
407 | // Clear atlas
408 | atlas->TexID = (ImTextureID)nullptr;
409 | atlas->TexWidth = atlas->TexHeight = 0;
410 | atlas->TexUvScale = ImVec2(0.0f, 0.0f);
411 | atlas->TexUvWhitePixel = ImVec2(0.0f, 0.0f);
412 | atlas->ClearTexData();
413 |
414 | // Temporary storage for building
415 | bool src_load_color = false;
416 | ImVector src_tmp_array;
417 | ImVector dst_tmp_array;
418 | src_tmp_array.resize(atlas->ConfigData.Size);
419 | dst_tmp_array.resize(atlas->Fonts.Size);
420 | memset((void*)src_tmp_array.Data, 0, (size_t)src_tmp_array.size_in_bytes());
421 | memset((void*)dst_tmp_array.Data, 0, (size_t)dst_tmp_array.size_in_bytes());
422 |
423 | // 1. Initialize font loading structure, check font data validity
424 | for (int src_i = 0; src_i < atlas->ConfigData.Size; src_i++)
425 | {
426 | ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
427 | ImFontConfig& cfg = atlas->ConfigData[src_i];
428 | FreeTypeFont& font_face = src_tmp.Font;
429 | IM_ASSERT(cfg.DstFont && (!cfg.DstFont->IsLoaded() || cfg.DstFont->ContainerAtlas == atlas));
430 |
431 | // Find index from cfg.DstFont (we allow the user to set cfg.DstFont. Also it makes casual debugging nicer than when storing indices)
432 | src_tmp.DstIndex = -1;
433 | for (int output_i = 0; output_i < atlas->Fonts.Size && src_tmp.DstIndex == -1; output_i++)
434 | if (cfg.DstFont == atlas->Fonts[output_i])
435 | src_tmp.DstIndex = output_i;
436 | IM_ASSERT(src_tmp.DstIndex != -1); // cfg.DstFont not pointing within atlas->Fonts[] array?
437 | if (src_tmp.DstIndex == -1)
438 | return false;
439 |
440 | // Load font
441 | if (!font_face.InitFont(ft_library, cfg, extra_flags))
442 | return false;
443 |
444 | // Measure highest codepoints
445 | src_load_color |= (cfg.FontBuilderFlags & ImGuiFreeTypeBuilderFlags_LoadColor) != 0;
446 | ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
447 | src_tmp.SrcRanges = cfg.GlyphRanges ? cfg.GlyphRanges : atlas->GetGlyphRangesDefault();
448 | for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
449 | {
450 | // Check for valid range. This may also help detect *some* dangling pointers, because a common
451 | // user error is to setup ImFontConfig::GlyphRanges with a pointer to data that isn't persistent.
452 | IM_ASSERT(src_range[0] <= src_range[1]);
453 | src_tmp.GlyphsHighest = ImMax(src_tmp.GlyphsHighest, (int)src_range[1]);
454 | }
455 | dst_tmp.SrcCount++;
456 | dst_tmp.GlyphsHighest = ImMax(dst_tmp.GlyphsHighest, src_tmp.GlyphsHighest);
457 | }
458 |
459 | // 2. For every requested codepoint, check for their presence in the font data, and handle redundancy or overlaps between source fonts to avoid unused glyphs.
460 | int total_glyphs_count = 0;
461 | for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
462 | {
463 | ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
464 | ImFontBuildDstDataFT& dst_tmp = dst_tmp_array[src_tmp.DstIndex];
465 | src_tmp.GlyphsSet.Create(src_tmp.GlyphsHighest + 1);
466 | if (dst_tmp.GlyphsSet.Storage.empty())
467 | dst_tmp.GlyphsSet.Create(dst_tmp.GlyphsHighest + 1);
468 |
469 | for (const ImWchar* src_range = src_tmp.SrcRanges; src_range[0] && src_range[1]; src_range += 2)
470 | for (int codepoint = src_range[0]; codepoint <= (int)src_range[1]; codepoint++)
471 | {
472 | if (dst_tmp.GlyphsSet.TestBit(codepoint)) // Don't overwrite existing glyphs. We could make this an option (e.g. MergeOverwrite)
473 | continue;
474 | uint32_t glyph_index = FT_Get_Char_Index(src_tmp.Font.Face, codepoint); // It is actually in the font? (FIXME-OPT: We are not storing the glyph_index..)
475 | if (glyph_index == 0)
476 | continue;
477 |
478 | // Add to avail set/counters
479 | src_tmp.GlyphsCount++;
480 | dst_tmp.GlyphsCount++;
481 | src_tmp.GlyphsSet.SetBit(codepoint);
482 | dst_tmp.GlyphsSet.SetBit(codepoint);
483 | total_glyphs_count++;
484 | }
485 | }
486 |
487 | // 3. Unpack our bit map into a flat list (we now have all the Unicode points that we know are requested _and_ available _and_ not overlapping another)
488 | for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
489 | {
490 | ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
491 | src_tmp.GlyphsList.reserve(src_tmp.GlyphsCount);
492 |
493 | IM_ASSERT(sizeof(src_tmp.GlyphsSet.Storage.Data[0]) == sizeof(ImU32));
494 | const ImU32* it_begin = src_tmp.GlyphsSet.Storage.begin();
495 | const ImU32* it_end = src_tmp.GlyphsSet.Storage.end();
496 | for (const ImU32* it = it_begin; it < it_end; it++)
497 | if (ImU32 entries_32 = *it)
498 | for (ImU32 bit_n = 0; bit_n < 32; bit_n++)
499 | if (entries_32 & ((ImU32)1 << bit_n))
500 | {
501 | ImFontBuildSrcGlyphFT src_glyph;
502 | src_glyph.Codepoint = (ImWchar)(((it - it_begin) << 5) + bit_n);
503 | //src_glyph.GlyphIndex = 0; // FIXME-OPT: We had this info in the previous step and lost it..
504 | src_tmp.GlyphsList.push_back(src_glyph);
505 | }
506 | src_tmp.GlyphsSet.Clear();
507 | IM_ASSERT(src_tmp.GlyphsList.Size == src_tmp.GlyphsCount);
508 | }
509 | for (int dst_i = 0; dst_i < dst_tmp_array.Size; dst_i++)
510 | dst_tmp_array[dst_i].GlyphsSet.Clear();
511 | dst_tmp_array.clear();
512 |
513 | // Allocate packing character data and flag packed characters buffer as non-packed (x0=y0=x1=y1=0)
514 | // (We technically don't need to zero-clear buf_rects, but let's do it for the sake of sanity)
515 | ImVector buf_rects;
516 | buf_rects.resize(total_glyphs_count);
517 | memset(buf_rects.Data, 0, (size_t)buf_rects.size_in_bytes());
518 |
519 | // Allocate temporary rasterization data buffers.
520 | // We could not find a way to retrieve accurate glyph size without rendering them.
521 | // (e.g. slot->metrics->width not always matching bitmap->width, especially considering the Oblique transform)
522 | // We allocate in chunks of 256 KB to not waste too much extra memory ahead. Hopefully users of FreeType won't mind the temporary allocations.
523 | const int BITMAP_BUFFERS_CHUNK_SIZE = 256 * 1024;
524 | int buf_bitmap_current_used_bytes = 0;
525 | ImVector buf_bitmap_buffers;
526 | buf_bitmap_buffers.push_back((unsigned char*)IM_ALLOC(BITMAP_BUFFERS_CHUNK_SIZE));
527 |
528 | // 4. Gather glyphs sizes so we can pack them in our virtual canvas.
529 | // 8. Render/rasterize font characters into the texture
530 | int total_surface = 0;
531 | int buf_rects_out_n = 0;
532 | for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
533 | {
534 | ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
535 | ImFontConfig& cfg = atlas->ConfigData[src_i];
536 | if (src_tmp.GlyphsCount == 0)
537 | continue;
538 |
539 | src_tmp.Rects = &buf_rects[buf_rects_out_n];
540 | buf_rects_out_n += src_tmp.GlyphsCount;
541 |
542 | // Compute multiply table if requested
543 | const bool multiply_enabled = (cfg.RasterizerMultiply != 1.0f);
544 | unsigned char multiply_table[256];
545 | if (multiply_enabled)
546 | ImFontAtlasBuildMultiplyCalcLookupTable(multiply_table, cfg.RasterizerMultiply);
547 |
548 | // Gather the sizes of all rectangles we will need to pack
549 | const int padding = atlas->TexGlyphPadding;
550 | for (int glyph_i = 0; glyph_i < src_tmp.GlyphsList.Size; glyph_i++)
551 | {
552 | ImFontBuildSrcGlyphFT& src_glyph = src_tmp.GlyphsList[glyph_i];
553 |
554 | const FT_Glyph_Metrics* metrics = src_tmp.Font.LoadGlyph(src_glyph.Codepoint);
555 | if (metrics == nullptr)
556 | continue;
557 |
558 | // Render glyph into a bitmap (currently held by FreeType)
559 | const FT_Bitmap* ft_bitmap = src_tmp.Font.RenderGlyphAndGetInfo(&src_glyph.Info);
560 | if (ft_bitmap == nullptr)
561 | continue;
562 |
563 | // Allocate new temporary chunk if needed
564 | const int bitmap_size_in_bytes = src_glyph.Info.Width * src_glyph.Info.Height * 4;
565 | if (buf_bitmap_current_used_bytes + bitmap_size_in_bytes > BITMAP_BUFFERS_CHUNK_SIZE)
566 | {
567 | buf_bitmap_current_used_bytes = 0;
568 | buf_bitmap_buffers.push_back((unsigned char*)IM_ALLOC(BITMAP_BUFFERS_CHUNK_SIZE));
569 | }
570 | IM_ASSERT(buf_bitmap_current_used_bytes + bitmap_size_in_bytes <= BITMAP_BUFFERS_CHUNK_SIZE); // We could probably allocate custom-sized buffer instead.
571 |
572 | // Blit rasterized pixels to our temporary buffer and keep a pointer to it.
573 | src_glyph.BitmapData = (unsigned int*)(buf_bitmap_buffers.back() + buf_bitmap_current_used_bytes);
574 | buf_bitmap_current_used_bytes += bitmap_size_in_bytes;
575 | src_tmp.Font.BlitGlyph(ft_bitmap, src_glyph.BitmapData, src_glyph.Info.Width, multiply_enabled ? multiply_table : nullptr);
576 |
577 | src_tmp.Rects[glyph_i].w = (stbrp_coord)(src_glyph.Info.Width + padding);
578 | src_tmp.Rects[glyph_i].h = (stbrp_coord)(src_glyph.Info.Height + padding);
579 | total_surface += src_tmp.Rects[glyph_i].w * src_tmp.Rects[glyph_i].h;
580 | }
581 | }
582 |
583 | // We need a width for the skyline algorithm, any width!
584 | // The exact width doesn't really matter much, but some API/GPU have texture size limitations and increasing width can decrease height.
585 | // User can override TexDesiredWidth and TexGlyphPadding if they wish, otherwise we use a simple heuristic to select the width based on expected surface.
586 | const int surface_sqrt = (int)ImSqrt((float)total_surface) + 1;
587 | atlas->TexHeight = 0;
588 | if (atlas->TexDesiredWidth > 0)
589 | atlas->TexWidth = atlas->TexDesiredWidth;
590 | else
591 | atlas->TexWidth = (surface_sqrt >= 4096 * 0.7f) ? 4096 : (surface_sqrt >= 2048 * 0.7f) ? 2048 : (surface_sqrt >= 1024 * 0.7f) ? 1024 : 512;
592 |
593 | // 5. Start packing
594 | // Pack our extra data rectangles first, so it will be on the upper-left corner of our texture (UV will have small values).
595 | const int TEX_HEIGHT_MAX = 1024 * 32;
596 | const int num_nodes_for_packing_algorithm = atlas->TexWidth - atlas->TexGlyphPadding;
597 | ImVector pack_nodes;
598 | pack_nodes.resize(num_nodes_for_packing_algorithm);
599 | stbrp_context pack_context;
600 | stbrp_init_target(&pack_context, atlas->TexWidth - atlas->TexGlyphPadding, TEX_HEIGHT_MAX - atlas->TexGlyphPadding, pack_nodes.Data, pack_nodes.Size);
601 | ImFontAtlasBuildPackCustomRects(atlas, &pack_context);
602 |
603 | // 6. Pack each source font. No rendering yet, we are working with rectangles in an infinitely tall texture at this point.
604 | for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
605 | {
606 | ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
607 | if (src_tmp.GlyphsCount == 0)
608 | continue;
609 |
610 | stbrp_pack_rects(&pack_context, src_tmp.Rects, src_tmp.GlyphsCount);
611 |
612 | // Extend texture height and mark missing glyphs as non-packed so we won't render them.
613 | // FIXME: We are not handling packing failure here (would happen if we got off TEX_HEIGHT_MAX or if a single if larger than TexWidth?)
614 | for (int glyph_i = 0; glyph_i < src_tmp.GlyphsCount; glyph_i++)
615 | if (src_tmp.Rects[glyph_i].was_packed)
616 | atlas->TexHeight = ImMax(atlas->TexHeight, src_tmp.Rects[glyph_i].y + src_tmp.Rects[glyph_i].h);
617 | }
618 |
619 | // 7. Allocate texture
620 | atlas->TexHeight = (atlas->Flags & ImFontAtlasFlags_NoPowerOfTwoHeight) ? (atlas->TexHeight + 1) : ImUpperPowerOfTwo(atlas->TexHeight);
621 | atlas->TexUvScale = ImVec2(1.0f / atlas->TexWidth, 1.0f / atlas->TexHeight);
622 | if (src_load_color)
623 | {
624 | size_t tex_size = (size_t)atlas->TexWidth * atlas->TexHeight * 4;
625 | atlas->TexPixelsRGBA32 = (unsigned int*)IM_ALLOC(tex_size);
626 | memset(atlas->TexPixelsRGBA32, 0, tex_size);
627 | }
628 | else
629 | {
630 | size_t tex_size = (size_t)atlas->TexWidth * atlas->TexHeight * 1;
631 | atlas->TexPixelsAlpha8 = (unsigned char*)IM_ALLOC(tex_size);
632 | memset(atlas->TexPixelsAlpha8, 0, tex_size);
633 | }
634 |
635 | // 8. Copy rasterized font characters back into the main texture
636 | // 9. Setup ImFont and glyphs for runtime
637 | bool tex_use_colors = false;
638 | for (int src_i = 0; src_i < src_tmp_array.Size; src_i++)
639 | {
640 | ImFontBuildSrcDataFT& src_tmp = src_tmp_array[src_i];
641 | if (src_tmp.GlyphsCount == 0)
642 | continue;
643 |
644 | // When merging fonts with MergeMode=true:
645 | // - We can have multiple input fonts writing into a same destination font.
646 | // - dst_font->ConfigData is != from cfg which is our source configuration.
647 | ImFontConfig& cfg = atlas->ConfigData[src_i];
648 | ImFont* dst_font = cfg.DstFont;
649 |
650 | const float ascent = src_tmp.Font.Info.Ascender;
651 | const float descent = src_tmp.Font.Info.Descender;
652 | ImFontAtlasBuildSetupFont(atlas, dst_font, &cfg, ascent, descent);
653 | const float font_off_x = cfg.GlyphOffset.x;
654 | const float font_off_y = cfg.GlyphOffset.y + IM_ROUND(dst_font->Ascent);
655 |
656 | const int padding = atlas->TexGlyphPadding;
657 | for (int glyph_i = 0; glyph_i < src_tmp.GlyphsCount; glyph_i++)
658 | {
659 | ImFontBuildSrcGlyphFT& src_glyph = src_tmp.GlyphsList[glyph_i];
660 | stbrp_rect& pack_rect = src_tmp.Rects[glyph_i];
661 | IM_ASSERT(pack_rect.was_packed);
662 | if (pack_rect.w == 0 && pack_rect.h == 0)
663 | continue;
664 |
665 | GlyphInfo& info = src_glyph.Info;
666 | IM_ASSERT(info.Width + padding <= pack_rect.w);
667 | IM_ASSERT(info.Height + padding <= pack_rect.h);
668 | const int tx = pack_rect.x + padding;
669 | const int ty = pack_rect.y + padding;
670 |
671 | // Register glyph
672 | float x0 = info.OffsetX + font_off_x;
673 | float y0 = info.OffsetY + font_off_y;
674 | float x1 = x0 + info.Width;
675 | float y1 = y0 + info.Height;
676 | float u0 = (tx) / (float)atlas->TexWidth;
677 | float v0 = (ty) / (float)atlas->TexHeight;
678 | float u1 = (tx + info.Width) / (float)atlas->TexWidth;
679 | float v1 = (ty + info.Height) / (float)atlas->TexHeight;
680 | dst_font->AddGlyph(&cfg, (ImWchar)src_glyph.Codepoint, x0, y0, x1, y1, u0, v0, u1, v1, info.AdvanceX);
681 |
682 | ImFontGlyph* dst_glyph = &dst_font->Glyphs.back();
683 | IM_ASSERT(dst_glyph->Codepoint == src_glyph.Codepoint);
684 | if (src_glyph.Info.IsColored)
685 | dst_glyph->Colored = tex_use_colors = true;
686 |
687 | // Blit from temporary buffer to final texture
688 | size_t blit_src_stride = (size_t)src_glyph.Info.Width;
689 | size_t blit_dst_stride = (size_t)atlas->TexWidth;
690 | unsigned int* blit_src = src_glyph.BitmapData;
691 | if (atlas->TexPixelsAlpha8 != nullptr)
692 | {
693 | unsigned char* blit_dst = atlas->TexPixelsAlpha8 + (ty * blit_dst_stride) + tx;
694 | for (int y = 0; y < info.Height; y++, blit_dst += blit_dst_stride, blit_src += blit_src_stride)
695 | for (int x = 0; x < info.Width; x++)
696 | blit_dst[x] = (unsigned char)((blit_src[x] >> IM_COL32_A_SHIFT) & 0xFF);
697 | }
698 | else
699 | {
700 | unsigned int* blit_dst = atlas->TexPixelsRGBA32 + (ty * blit_dst_stride) + tx;
701 | for (int y = 0; y < info.Height; y++, blit_dst += blit_dst_stride, blit_src += blit_src_stride)
702 | for (int x = 0; x < info.Width; x++)
703 | blit_dst[x] = blit_src[x];
704 | }
705 | }
706 |
707 | src_tmp.Rects = nullptr;
708 | }
709 | atlas->TexPixelsUseColors = tex_use_colors;
710 |
711 | // Cleanup
712 | for (int buf_i = 0; buf_i < buf_bitmap_buffers.Size; buf_i++)
713 | IM_FREE(buf_bitmap_buffers[buf_i]);
714 | src_tmp_array.clear_destruct();
715 |
716 | ImFontAtlasBuildFinish(atlas);
717 |
718 | return true;
719 | }
720 |
721 | // FreeType memory allocation callbacks
722 | static void* FreeType_Alloc(FT_Memory /*memory*/, long size)
723 | {
724 | return GImGuiFreeTypeAllocFunc((size_t)size, GImGuiFreeTypeAllocatorUserData);
725 | }
726 |
727 | static void FreeType_Free(FT_Memory /*memory*/, void* block)
728 | {
729 | GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData);
730 | }
731 |
732 | static void* FreeType_Realloc(FT_Memory /*memory*/, long cur_size, long new_size, void* block)
733 | {
734 | // Implement realloc() as we don't ask user to provide it.
735 | if (block == nullptr)
736 | return GImGuiFreeTypeAllocFunc((size_t)new_size, GImGuiFreeTypeAllocatorUserData);
737 |
738 | if (new_size == 0)
739 | {
740 | GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData);
741 | return nullptr;
742 | }
743 |
744 | if (new_size > cur_size)
745 | {
746 | void* new_block = GImGuiFreeTypeAllocFunc((size_t)new_size, GImGuiFreeTypeAllocatorUserData);
747 | memcpy(new_block, block, (size_t)cur_size);
748 | GImGuiFreeTypeFreeFunc(block, GImGuiFreeTypeAllocatorUserData);
749 | return new_block;
750 | }
751 |
752 | return block;
753 | }
754 |
755 | static bool ImFontAtlasBuildWithFreeType(ImFontAtlas* atlas)
756 | {
757 | // FreeType memory management: https://www.freetype.org/freetype2/docs/design/design-4.html
758 | FT_MemoryRec_ memory_rec = {};
759 | memory_rec.user = nullptr;
760 | memory_rec.alloc = &FreeType_Alloc;
761 | memory_rec.free = &FreeType_Free;
762 | memory_rec.realloc = &FreeType_Realloc;
763 |
764 | // https://www.freetype.org/freetype2/docs/reference/ft2-module_management.html#FT_New_Library
765 | FT_Library ft_library;
766 | FT_Error error = FT_New_Library(&memory_rec, &ft_library);
767 | if (error != 0)
768 | return false;
769 |
770 | // If you don't call FT_Add_Default_Modules() the rest of code may work, but FreeType won't use our custom allocator.
771 | FT_Add_Default_Modules(ft_library);
772 |
773 | bool ret = ImFontAtlasBuildWithFreeTypeEx(ft_library, atlas, atlas->FontBuilderFlags);
774 | FT_Done_Library(ft_library);
775 |
776 | return ret;
777 | }
778 |
779 | const ImFontBuilderIO* ImGuiFreeType::GetBuilderForFreeType()
780 | {
781 | static ImFontBuilderIO io;
782 | io.FontBuilder_Build = ImFontAtlasBuildWithFreeType;
783 | return &io;
784 | }
785 |
786 | void ImGuiFreeType::SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data)
787 | {
788 | GImGuiFreeTypeAllocFunc = alloc_func;
789 | GImGuiFreeTypeFreeFunc = free_func;
790 | GImGuiFreeTypeAllocatorUserData = user_data;
791 | }
792 |
793 | #ifdef __GNUC__
794 | #pragma GCC diagnostic pop
795 | #endif
796 |
797 | #ifdef _MSC_VER
798 | #pragma warning (pop)
799 | #endif
800 |
--------------------------------------------------------------------------------
/showcase/imgui/freetype/imgui_freetype.h:
--------------------------------------------------------------------------------
1 | // dear imgui: FreeType font builder (used as a replacement for the stb_truetype builder)
2 | // (headers)
3 |
4 | #pragma once
5 |
6 | #include "../imgui.h" // IMGUI_API
7 |
8 | // Forward declarations
9 | struct ImFontAtlas;
10 | struct ImFontBuilderIO;
11 |
12 | // Hinting greatly impacts visuals (and glyph sizes).
13 | // - By default, hinting is enabled and the font's native hinter is preferred over the auto-hinter.
14 | // - When disabled, FreeType generates blurrier glyphs, more or less matches the stb_truetype.h
15 | // - The Default hinting mode usually looks good, but may distort glyphs in an unusual way.
16 | // - The Light hinting mode generates fuzzier glyphs but better matches Microsoft's rasterizer.
17 | // You can set those flags globaly in ImFontAtlas::FontBuilderFlags
18 | // You can set those flags on a per font basis in ImFontConfig::FontBuilderFlags
19 | enum ImGuiFreeTypeBuilderFlags
20 | {
21 | ImGuiFreeTypeBuilderFlags_NoHinting = 1 << 0, // Disable hinting. This generally generates 'blurrier' bitmap glyphs when the glyph are rendered in any of the anti-aliased modes.
22 | ImGuiFreeTypeBuilderFlags_NoAutoHint = 1 << 1, // Disable auto-hinter.
23 | ImGuiFreeTypeBuilderFlags_ForceAutoHint = 1 << 2, // Indicates that the auto-hinter is preferred over the font's native hinter.
24 | ImGuiFreeTypeBuilderFlags_LightHinting = 1 << 3, // A lighter hinting algorithm for gray-level modes. Many generated glyphs are fuzzier but better resemble their original shape. This is achieved by snapping glyphs to the pixel grid only vertically (Y-axis), as is done by Microsoft's ClearType and Adobe's proprietary font renderer. This preserves inter-glyph spacing in horizontal text.
25 | ImGuiFreeTypeBuilderFlags_MonoHinting = 1 << 4, // Strong hinting algorithm that should only be used for monochrome output.
26 | ImGuiFreeTypeBuilderFlags_Bold = 1 << 5, // Styling: Should we artificially embolden the font?
27 | ImGuiFreeTypeBuilderFlags_Oblique = 1 << 6, // Styling: Should we slant the font, emulating italic style?
28 | ImGuiFreeTypeBuilderFlags_Monochrome = 1 << 7, // Disable anti-aliasing. Combine this with MonoHinting for best results!
29 | ImGuiFreeTypeBuilderFlags_LoadColor = 1 << 8, // Enable FreeType color-layered glyphs
30 | ImGuiFreeTypeBuilderFlags_Bitmap = 1 << 9 // Enable FreeType bitmap glyphs
31 | };
32 |
33 | namespace ImGuiFreeType
34 | {
35 | // This is automatically assigned when using '#define IMGUI_ENABLE_FREETYPE'.
36 | // If you need to dynamically select between multiple builders:
37 | // - you can manually assign this builder with 'atlas->FontBuilderIO = ImGuiFreeType::GetBuilderForFreeType()'
38 | // - prefer deep-copying this into your own ImFontBuilderIO instance if you use hot-reloading that messes up static data.
39 | IMGUI_API const ImFontBuilderIO* GetBuilderForFreeType();
40 |
41 | // Override allocators. By default ImGuiFreeType will use IM_ALLOC()/IM_FREE()
42 | // However, as FreeType does lots of allocations we provide a way for the user to redirect it to a separate memory heap if desired.
43 | IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void (*free_func)(void* ptr, void* user_data), void* user_data = nullptr);
44 |
45 | // Obsolete names (will be removed soon)
46 | // Prefer using '#define IMGUI_ENABLE_FREETYPE'
47 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
48 | static inline bool BuildFontAtlas(ImFontAtlas* atlas, unsigned int flags = 0) { atlas->FontBuilderIO = GetBuilderForFreeType(); atlas->FontBuilderFlags = flags; return atlas->Build(); }
49 | #endif
50 | }
51 |
--------------------------------------------------------------------------------
/showcase/imgui/imconfig.h:
--------------------------------------------------------------------------------
1 | //-----------------------------------------------------------------------------
2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI
3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
5 | //-----------------------------------------------------------------------------
6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it)
7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template.
8 | //-----------------------------------------------------------------------------
9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp
10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures.
11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
12 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
13 | //-----------------------------------------------------------------------------
14 |
15 | #pragma once
16 |
17 | //---- Define assertion handler. Defaults to calling assert().
18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement.
19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts
21 |
22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows
23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions()
25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details.
26 | //#define IMGUI_API __declspec( dllexport )
27 | //#define IMGUI_API __declspec( dllimport )
28 |
29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS
31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions.
32 |
33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools.
34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp.
35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty.
36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty.
37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88).
38 |
39 | //---- Don't implement some functions to reduce linkage requirements.
40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a)
41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW)
42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a)
43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime).
44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default).
45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available
51 |
52 | //---- Include imgui_user.h at the end of imgui.h as a convenience
53 | //#define IMGUI_INCLUDE_IMGUI_USER_H
54 |
55 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
56 | //#define IMGUI_USE_BGRA_PACKED_COLOR
57 |
58 | //---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
59 | //#define IMGUI_USE_WCHAR32
60 |
61 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
62 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files.
63 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
64 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
65 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled
66 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
67 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION
68 |
69 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined)
70 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h.
71 | //#define IMGUI_USE_STB_SPRINTF
72 |
73 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui)
74 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided).
75 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'.
76 | #define IMGUI_ENABLE_FREETYPE
77 |
78 | //---- Use stb_truetype to build and rasterize the font atlas (default)
79 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend.
80 | //#define IMGUI_ENABLE_STB_TRUETYPE
81 |
82 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
83 | // This will be inlined as part of ImVec2 and ImVec4 class declarations.
84 | /*
85 | #define IM_VEC2_CLASS_EXTRA \
86 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \
87 | operator MyVec2() const { return MyVec2(x,y); }
88 |
89 | #define IM_VEC4_CLASS_EXTRA \
90 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \
91 | operator MyVec4() const { return MyVec4(x,y,z,w); }
92 | */
93 | //---- ...Or use Dear ImGui's own very basic math operators.
94 | //#define IMGUI_DEFINE_MATH_OPERATORS
95 |
96 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices.
97 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices).
98 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer.
99 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
100 | //#define ImDrawIdx unsigned int
101 |
102 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly)
103 | //struct ImDrawList;
104 | //struct ImDrawCmd;
105 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data);
106 | //#define ImDrawCallback MyImDrawCallback
107 |
108 | //---- Debug Tools: Macro to break in Debugger
109 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.)
110 | //#define IM_DEBUG_BREAK IM_ASSERT(0)
111 | //#define IM_DEBUG_BREAK __debugbreak()
112 |
113 | //---- Debug Tools: Enable slower asserts
114 | //#define IMGUI_DEBUG_PARANOID
115 |
116 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
117 | /*
118 | namespace ImGui
119 | {
120 | void MyFunction(const char* name, const MyMatrix44& v);
121 | }
122 | */
123 |
--------------------------------------------------------------------------------
/showcase/imgui/imstb_rectpack.h:
--------------------------------------------------------------------------------
1 | // [DEAR IMGUI]
2 | // This is a slightly modified version of stb_rect_pack.h 1.01.
3 | // Grep for [DEAR IMGUI] to find the changes.
4 | //
5 | // stb_rect_pack.h - v1.01 - public domain - rectangle packing
6 | // Sean Barrett 2014
7 | //
8 | // Useful for e.g. packing rectangular textures into an atlas.
9 | // Does not do rotation.
10 | //
11 | // Before #including,
12 | //
13 | // #define STB_RECT_PACK_IMPLEMENTATION
14 | //
15 | // in the file that you want to have the implementation.
16 | //
17 | // Not necessarily the awesomest packing method, but better than
18 | // the totally naive one in stb_truetype (which is primarily what
19 | // this is meant to replace).
20 | //
21 | // Has only had a few tests run, may have issues.
22 | //
23 | // More docs to come.
24 | //
25 | // No memory allocations; uses qsort() and assert() from stdlib.
26 | // Can override those by defining STBRP_SORT and STBRP_ASSERT.
27 | //
28 | // This library currently uses the Skyline Bottom-Left algorithm.
29 | //
30 | // Please note: better rectangle packers are welcome! Please
31 | // implement them to the same API, but with a different init
32 | // function.
33 | //
34 | // Credits
35 | //
36 | // Library
37 | // Sean Barrett
38 | // Minor features
39 | // Martins Mozeiko
40 | // github:IntellectualKitty
41 | //
42 | // Bugfixes / warning fixes
43 | // Jeremy Jaussaud
44 | // Fabian Giesen
45 | //
46 | // Version history:
47 | //
48 | // 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
49 | // 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
50 | // 0.99 (2019-02-07) warning fixes
51 | // 0.11 (2017-03-03) return packing success/fail result
52 | // 0.10 (2016-10-25) remove cast-away-const to avoid warnings
53 | // 0.09 (2016-08-27) fix compiler warnings
54 | // 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
55 | // 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
56 | // 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
57 | // 0.05: added STBRP_ASSERT to allow replacing assert
58 | // 0.04: fixed minor bug in STBRP_LARGE_RECTS support
59 | // 0.01: initial release
60 | //
61 | // LICENSE
62 | //
63 | // See end of file for license information.
64 |
65 | //////////////////////////////////////////////////////////////////////////////
66 | //
67 | // INCLUDE SECTION
68 | //
69 |
70 | #ifndef STB_INCLUDE_STB_RECT_PACK_H
71 | #define STB_INCLUDE_STB_RECT_PACK_H
72 |
73 | #define STB_RECT_PACK_VERSION 1
74 |
75 | #ifdef STBRP_STATIC
76 | #define STBRP_DEF static
77 | #else
78 | #define STBRP_DEF extern
79 | #endif
80 |
81 | #ifdef __cplusplus
82 | extern "C" {
83 | #endif
84 |
85 | typedef struct stbrp_context stbrp_context;
86 | typedef struct stbrp_node stbrp_node;
87 | typedef struct stbrp_rect stbrp_rect;
88 |
89 | typedef int stbrp_coord;
90 |
91 | #define STBRP__MAXVAL 0x7fffffff
92 | // Mostly for internal use, but this is the maximum supported coordinate value.
93 |
94 | STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
95 | // Assign packed locations to rectangles. The rectangles are of type
96 | // 'stbrp_rect' defined below, stored in the array 'rects', and there
97 | // are 'num_rects' many of them.
98 | //
99 | // Rectangles which are successfully packed have the 'was_packed' flag
100 | // set to a non-zero value and 'x' and 'y' store the minimum location
101 | // on each axis (i.e. bottom-left in cartesian coordinates, top-left
102 | // if you imagine y increasing downwards). Rectangles which do not fit
103 | // have the 'was_packed' flag set to 0.
104 | //
105 | // You should not try to access the 'rects' array from another thread
106 | // while this function is running, as the function temporarily reorders
107 | // the array while it executes.
108 | //
109 | // To pack into another rectangle, you need to call stbrp_init_target
110 | // again. To continue packing into the same rectangle, you can call
111 | // this function again. Calling this multiple times with multiple rect
112 | // arrays will probably produce worse packing results than calling it
113 | // a single time with the full rectangle array, but the option is
114 | // available.
115 | //
116 | // The function returns 1 if all of the rectangles were successfully
117 | // packed and 0 otherwise.
118 |
119 | struct stbrp_rect
120 | {
121 | // reserved for your use:
122 | int id;
123 |
124 | // input:
125 | stbrp_coord w, h;
126 |
127 | // output:
128 | stbrp_coord x, y;
129 | int was_packed; // non-zero if valid packing
130 |
131 | }; // 16 bytes, nominally
132 |
133 |
134 | STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
135 | // Initialize a rectangle packer to:
136 | // pack a rectangle that is 'width' by 'height' in dimensions
137 | // using temporary storage provided by the array 'nodes', which is 'num_nodes' long
138 | //
139 | // You must call this function every time you start packing into a new target.
140 | //
141 | // There is no "shutdown" function. The 'nodes' memory must stay valid for
142 | // the following stbrp_pack_rects() call (or calls), but can be freed after
143 | // the call (or calls) finish.
144 | //
145 | // Note: to guarantee best results, either:
146 | // 1. make sure 'num_nodes' >= 'width'
147 | // or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
148 | //
149 | // If you don't do either of the above things, widths will be quantized to multiples
150 | // of small integers to guarantee the algorithm doesn't run out of temporary storage.
151 | //
152 | // If you do #2, then the non-quantized algorithm will be used, but the algorithm
153 | // may run out of temporary storage and be unable to pack some rectangles.
154 |
155 | STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
156 | // Optionally call this function after init but before doing any packing to
157 | // change the handling of the out-of-temp-memory scenario, described above.
158 | // If you call init again, this will be reset to the default (false).
159 |
160 |
161 | STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
162 | // Optionally select which packing heuristic the library should use. Different
163 | // heuristics will produce better/worse results for different data sets.
164 | // If you call init again, this will be reset to the default.
165 |
166 | enum
167 | {
168 | STBRP_HEURISTIC_Skyline_default=0,
169 | STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
170 | STBRP_HEURISTIC_Skyline_BF_sortHeight
171 | };
172 |
173 |
174 | //////////////////////////////////////////////////////////////////////////////
175 | //
176 | // the details of the following structures don't matter to you, but they must
177 | // be visible so you can handle the memory allocations for them
178 |
179 | struct stbrp_node
180 | {
181 | stbrp_coord x,y;
182 | stbrp_node *next;
183 | };
184 |
185 | struct stbrp_context
186 | {
187 | int width;
188 | int height;
189 | int align;
190 | int init_mode;
191 | int heuristic;
192 | int num_nodes;
193 | stbrp_node *active_head;
194 | stbrp_node *free_head;
195 | stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
196 | };
197 |
198 | #ifdef __cplusplus
199 | }
200 | #endif
201 |
202 | #endif
203 |
204 | //////////////////////////////////////////////////////////////////////////////
205 | //
206 | // IMPLEMENTATION SECTION
207 | //
208 |
209 | #ifdef STB_RECT_PACK_IMPLEMENTATION
210 | #ifndef STBRP_SORT
211 | #include
212 | #define STBRP_SORT qsort
213 | #endif
214 |
215 | #ifndef STBRP_ASSERT
216 | #include
217 | #define STBRP_ASSERT assert
218 | #endif
219 |
220 | #ifdef _MSC_VER
221 | #define STBRP__NOTUSED(v) (void)(v)
222 | #define STBRP__CDECL __cdecl
223 | #else
224 | #define STBRP__NOTUSED(v) (void)sizeof(v)
225 | #define STBRP__CDECL
226 | #endif
227 |
228 | enum
229 | {
230 | STBRP__INIT_skyline = 1
231 | };
232 |
233 | STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
234 | {
235 | switch (context->init_mode) {
236 | case STBRP__INIT_skyline:
237 | STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
238 | context->heuristic = heuristic;
239 | break;
240 | default:
241 | STBRP_ASSERT(0);
242 | }
243 | }
244 |
245 | STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
246 | {
247 | if (allow_out_of_mem)
248 | // if it's ok to run out of memory, then don't bother aligning them;
249 | // this gives better packing, but may fail due to OOM (even though
250 | // the rectangles easily fit). @TODO a smarter approach would be to only
251 | // quantize once we've hit OOM, then we could get rid of this parameter.
252 | context->align = 1;
253 | else {
254 | // if it's not ok to run out of memory, then quantize the widths
255 | // so that num_nodes is always enough nodes.
256 | //
257 | // I.e. num_nodes * align >= width
258 | // align >= width / num_nodes
259 | // align = ceil(width/num_nodes)
260 |
261 | context->align = (context->width + context->num_nodes-1) / context->num_nodes;
262 | }
263 | }
264 |
265 | STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
266 | {
267 | int i;
268 |
269 | for (i=0; i < num_nodes-1; ++i)
270 | nodes[i].next = &nodes[i+1];
271 | nodes[i].next = NULL;
272 | context->init_mode = STBRP__INIT_skyline;
273 | context->heuristic = STBRP_HEURISTIC_Skyline_default;
274 | context->free_head = &nodes[0];
275 | context->active_head = &context->extra[0];
276 | context->width = width;
277 | context->height = height;
278 | context->num_nodes = num_nodes;
279 | stbrp_setup_allow_out_of_mem(context, 0);
280 |
281 | // node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
282 | context->extra[0].x = 0;
283 | context->extra[0].y = 0;
284 | context->extra[0].next = &context->extra[1];
285 | context->extra[1].x = (stbrp_coord) width;
286 | context->extra[1].y = (1<<30);
287 | context->extra[1].next = NULL;
288 | }
289 |
290 | // find minimum y position if it starts at x1
291 | static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
292 | {
293 | stbrp_node *node = first;
294 | int x1 = x0 + width;
295 | int min_y, visited_width, waste_area;
296 |
297 | STBRP__NOTUSED(c);
298 |
299 | STBRP_ASSERT(first->x <= x0);
300 |
301 | #if 0
302 | // skip in case we're past the node
303 | while (node->next->x <= x0)
304 | ++node;
305 | #else
306 | STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
307 | #endif
308 |
309 | STBRP_ASSERT(node->x <= x0);
310 |
311 | min_y = 0;
312 | waste_area = 0;
313 | visited_width = 0;
314 | while (node->x < x1) {
315 | if (node->y > min_y) {
316 | // raise min_y higher.
317 | // we've accounted for all waste up to min_y,
318 | // but we'll now add more waste for everything we've visted
319 | waste_area += visited_width * (node->y - min_y);
320 | min_y = node->y;
321 | // the first time through, visited_width might be reduced
322 | if (node->x < x0)
323 | visited_width += node->next->x - x0;
324 | else
325 | visited_width += node->next->x - node->x;
326 | } else {
327 | // add waste area
328 | int under_width = node->next->x - node->x;
329 | if (under_width + visited_width > width)
330 | under_width = width - visited_width;
331 | waste_area += under_width * (min_y - node->y);
332 | visited_width += under_width;
333 | }
334 | node = node->next;
335 | }
336 |
337 | *pwaste = waste_area;
338 | return min_y;
339 | }
340 |
341 | typedef struct
342 | {
343 | int x,y;
344 | stbrp_node **prev_link;
345 | } stbrp__findresult;
346 |
347 | static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
348 | {
349 | int best_waste = (1<<30), best_x, best_y = (1 << 30);
350 | stbrp__findresult fr;
351 | stbrp_node **prev, *node, *tail, **best = NULL;
352 |
353 | // align to multiple of c->align
354 | width = (width + c->align - 1);
355 | width -= width % c->align;
356 | STBRP_ASSERT(width % c->align == 0);
357 |
358 | // if it can't possibly fit, bail immediately
359 | if (width > c->width || height > c->height) {
360 | fr.prev_link = NULL;
361 | fr.x = fr.y = 0;
362 | return fr;
363 | }
364 |
365 | node = c->active_head;
366 | prev = &c->active_head;
367 | while (node->x + width <= c->width) {
368 | int y,waste;
369 | y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
370 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
371 | // bottom left
372 | if (y < best_y) {
373 | best_y = y;
374 | best = prev;
375 | }
376 | } else {
377 | // best-fit
378 | if (y + height <= c->height) {
379 | // can only use it if it first vertically
380 | if (y < best_y || (y == best_y && waste < best_waste)) {
381 | best_y = y;
382 | best_waste = waste;
383 | best = prev;
384 | }
385 | }
386 | }
387 | prev = &node->next;
388 | node = node->next;
389 | }
390 |
391 | best_x = (best == NULL) ? 0 : (*best)->x;
392 |
393 | // if doing best-fit (BF), we also have to try aligning right edge to each node position
394 | //
395 | // e.g, if fitting
396 | //
397 | // ____________________
398 | // |____________________|
399 | //
400 | // into
401 | //
402 | // | |
403 | // | ____________|
404 | // |____________|
405 | //
406 | // then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
407 | //
408 | // This makes BF take about 2x the time
409 |
410 | if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
411 | tail = c->active_head;
412 | node = c->active_head;
413 | prev = &c->active_head;
414 | // find first node that's admissible
415 | while (tail->x < width)
416 | tail = tail->next;
417 | while (tail) {
418 | int xpos = tail->x - width;
419 | int y,waste;
420 | STBRP_ASSERT(xpos >= 0);
421 | // find the left position that matches this
422 | while (node->next->x <= xpos) {
423 | prev = &node->next;
424 | node = node->next;
425 | }
426 | STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
427 | y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
428 | if (y + height <= c->height) {
429 | if (y <= best_y) {
430 | if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
431 | best_x = xpos;
432 | //STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
433 | best_y = y;
434 | best_waste = waste;
435 | best = prev;
436 | }
437 | }
438 | }
439 | tail = tail->next;
440 | }
441 | }
442 |
443 | fr.prev_link = best;
444 | fr.x = best_x;
445 | fr.y = best_y;
446 | return fr;
447 | }
448 |
449 | static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
450 | {
451 | // find best position according to heuristic
452 | stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
453 | stbrp_node *node, *cur;
454 |
455 | // bail if:
456 | // 1. it failed
457 | // 2. the best node doesn't fit (we don't always check this)
458 | // 3. we're out of memory
459 | if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
460 | res.prev_link = NULL;
461 | return res;
462 | }
463 |
464 | // on success, create new node
465 | node = context->free_head;
466 | node->x = (stbrp_coord) res.x;
467 | node->y = (stbrp_coord) (res.y + height);
468 |
469 | context->free_head = node->next;
470 |
471 | // insert the new node into the right starting point, and
472 | // let 'cur' point to the remaining nodes needing to be
473 | // stiched back in
474 |
475 | cur = *res.prev_link;
476 | if (cur->x < res.x) {
477 | // preserve the existing one, so start testing with the next one
478 | stbrp_node *next = cur->next;
479 | cur->next = node;
480 | cur = next;
481 | } else {
482 | *res.prev_link = node;
483 | }
484 |
485 | // from here, traverse cur and free the nodes, until we get to one
486 | // that shouldn't be freed
487 | while (cur->next && cur->next->x <= res.x + width) {
488 | stbrp_node *next = cur->next;
489 | // move the current node to the free list
490 | cur->next = context->free_head;
491 | context->free_head = cur;
492 | cur = next;
493 | }
494 |
495 | // stitch the list back in
496 | node->next = cur;
497 |
498 | if (cur->x < res.x + width)
499 | cur->x = (stbrp_coord) (res.x + width);
500 |
501 | #ifdef _DEBUG
502 | cur = context->active_head;
503 | while (cur->x < context->width) {
504 | STBRP_ASSERT(cur->x < cur->next->x);
505 | cur = cur->next;
506 | }
507 | STBRP_ASSERT(cur->next == NULL);
508 |
509 | {
510 | int count=0;
511 | cur = context->active_head;
512 | while (cur) {
513 | cur = cur->next;
514 | ++count;
515 | }
516 | cur = context->free_head;
517 | while (cur) {
518 | cur = cur->next;
519 | ++count;
520 | }
521 | STBRP_ASSERT(count == context->num_nodes+2);
522 | }
523 | #endif
524 |
525 | return res;
526 | }
527 |
528 | static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
529 | {
530 | const stbrp_rect *p = (const stbrp_rect *) a;
531 | const stbrp_rect *q = (const stbrp_rect *) b;
532 | if (p->h > q->h)
533 | return -1;
534 | if (p->h < q->h)
535 | return 1;
536 | return (p->w > q->w) ? -1 : (p->w < q->w);
537 | }
538 |
539 | static int STBRP__CDECL rect_original_order(const void *a, const void *b)
540 | {
541 | const stbrp_rect *p = (const stbrp_rect *) a;
542 | const stbrp_rect *q = (const stbrp_rect *) b;
543 | return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
544 | }
545 |
546 | STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
547 | {
548 | int i, all_rects_packed = 1;
549 |
550 | // we use the 'was_packed' field internally to allow sorting/unsorting
551 | for (i=0; i < num_rects; ++i) {
552 | rects[i].was_packed = i;
553 | }
554 |
555 | // sort according to heuristic
556 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
557 |
558 | for (i=0; i < num_rects; ++i) {
559 | if (rects[i].w == 0 || rects[i].h == 0) {
560 | rects[i].x = rects[i].y = 0; // empty rect needs no space
561 | } else {
562 | stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
563 | if (fr.prev_link) {
564 | rects[i].x = (stbrp_coord) fr.x;
565 | rects[i].y = (stbrp_coord) fr.y;
566 | } else {
567 | rects[i].x = rects[i].y = STBRP__MAXVAL;
568 | }
569 | }
570 | }
571 |
572 | // unsort
573 | STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
574 |
575 | // set was_packed flags and all_rects_packed status
576 | for (i=0; i < num_rects; ++i) {
577 | rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
578 | if (!rects[i].was_packed)
579 | all_rects_packed = 0;
580 | }
581 |
582 | // return the all_rects_packed status
583 | return all_rects_packed;
584 | }
585 | #endif
586 |
587 | /*
588 | ------------------------------------------------------------------------------
589 | This software is available under 2 licenses -- choose whichever you prefer.
590 | ------------------------------------------------------------------------------
591 | ALTERNATIVE A - MIT License
592 | Copyright (c) 2017 Sean Barrett
593 | Permission is hereby granted, free of charge, to any person obtaining a copy of
594 | this software and associated documentation files (the "Software"), to deal in
595 | the Software without restriction, including without limitation the rights to
596 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
597 | of the Software, and to permit persons to whom the Software is furnished to do
598 | so, subject to the following conditions:
599 | The above copyright notice and this permission notice shall be included in all
600 | copies or substantial portions of the Software.
601 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
602 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
603 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
604 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
605 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
606 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
607 | SOFTWARE.
608 | ------------------------------------------------------------------------------
609 | ALTERNATIVE B - Public Domain (www.unlicense.org)
610 | This is free and unencumbered software released into the public domain.
611 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
612 | software, either in source code form or as a compiled binary, for any purpose,
613 | commercial or non-commercial, and by any means.
614 | In jurisdictions that recognize copyright laws, the author or authors of this
615 | software dedicate any and all copyright interest in the software to the public
616 | domain. We make this dedication for the benefit of the public at large and to
617 | the detriment of our heirs and successors. We intend this dedication to be an
618 | overt act of relinquishment in perpetuity of all present and future rights to
619 | this software under copyright law.
620 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
621 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
622 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
623 | AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
624 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
625 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
626 | ------------------------------------------------------------------------------
627 | */
628 |
--------------------------------------------------------------------------------
/showcase/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Nixware
7 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/showcase/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #ifdef __EMSCRIPTEN__
5 | #include
6 | #endif
7 |
8 | #define GLFW_INCLUDE_ES3
9 | #include
10 | #include
11 |
12 | #include "fonts/ubuntu_compressed.h"
13 | #include "menu/menu.h"
14 |
15 | GLFWwindow* glfw_window;
16 | int window_width;
17 | int window_height;
18 |
19 | EM_JS(int, canvas_get_width, (),
20 | {
21 | return Module.canvas.width;
22 | });
23 |
24 | EM_JS(int, canvas_get_height, (),
25 | {
26 | return Module.canvas.height;
27 | });
28 |
29 | EM_JS(void, resizeCanvas, (),
30 | {
31 | js_resizeCanvas();
32 | });
33 |
34 | void on_size_changed()
35 | {
36 | glfwSetWindowSize(glfw_window, window_width, window_height);
37 |
38 | SetCurrentContext(GetCurrentContext());
39 | }
40 |
41 | void loop()
42 | {
43 | int width = canvas_get_width();
44 | int height = canvas_get_height();
45 |
46 | if (width != window_width || height != window_height)
47 | {
48 | window_width = width;
49 | window_height = height;
50 | on_size_changed();
51 | }
52 |
53 | glfwPollEvents();
54 |
55 | ImGui_ImplOpenGL3_NewFrame();
56 | ImGui_ImplGlfw_NewFrame();
57 | NewFrame();
58 |
59 | menu::render();
60 |
61 | Render();
62 |
63 | int display_w, display_h;
64 | glfwMakeContextCurrent(glfw_window);
65 | glfwGetFramebufferSize(glfw_window, &display_w, &display_h);
66 | glViewport(0, 0, display_w, display_h);
67 | glClearColor(0.078f, 0.078f, 0.078f, 1.00f);
68 | glClear(GL_COLOR_BUFFER_BIT);
69 |
70 | ImGui_ImplOpenGL3_RenderDrawData(GetDrawData());
71 | glfwMakeContextCurrent(glfw_window);
72 | }
73 |
74 | int init_gl()
75 | {
76 | if (!glfwInit())
77 | {
78 | fprintf(stderr, "failed to initialize GLFW\n");
79 | return 1;
80 | }
81 |
82 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
83 |
84 | glfw_window = glfwCreateWindow(window_width, window_height, "nixware", NULL, NULL);
85 | if (glfw_window == NULL)
86 | {
87 | fprintf(stderr, "failed to open GLFW window.\n");
88 | glfwTerminate();
89 | return -1;
90 | }
91 |
92 | glfwMakeContextCurrent(glfw_window);
93 |
94 | return 0;
95 | }
96 |
97 | int init_imgui()
98 | {
99 | IMGUI_CHECKVERSION();
100 | CreateContext();
101 | ImGui_ImplGlfw_InitForOpenGL(glfw_window, true);
102 | ImGui_ImplOpenGL3_Init();
103 |
104 | StyleColorsDark();
105 |
106 | ImGuiIO& io = GetIO();
107 |
108 | ImFontConfig config = ImFontConfig();
109 | config.FontBuilderFlags = ImGuiFreeTypeBuilderFlags_MonoHinting;
110 |
111 | io.Fonts->AddFontFromMemoryCompressedTTF(ubuntu_compressed_data, ubuntu_compressed_size, 13, &config, io.Fonts->GetGlyphRangesCyrillic());
112 |
113 | resizeCanvas();
114 |
115 | return 0;
116 | }
117 |
118 | int init()
119 | {
120 | init_gl();
121 | init_imgui();
122 | return 0;
123 | }
124 |
125 | void quit()
126 | {
127 | glfwTerminate();
128 | }
129 |
130 | extern "C" int main(int argc, char** argv)
131 | {
132 | window_width = canvas_get_width();
133 | window_height = canvas_get_height();
134 | if (init() != 0) return 1;
135 |
136 | #ifdef __EMSCRIPTEN__
137 | emscripten_set_main_loop(loop, 0, 1);
138 | #endif
139 |
140 | quit();
141 |
142 | return 0;
143 | }
144 |
--------------------------------------------------------------------------------
/showcase/src/menu/menu.cpp:
--------------------------------------------------------------------------------
1 | #include "menu.h"
2 |
3 | void menu::render()
4 | {
5 | ImGuiIO& io = GetIO();
6 | ImGuiStyle& style = GetStyle();
7 |
8 | PushStyleColor(ImGuiCol_WindowBg, ImVec4(settings::menu::colors::window_bg[0], settings::menu::colors::window_bg[1], settings::menu::colors::window_bg[2], settings::menu::colors::window_bg[3]));
9 | PushStyleColor(ImGuiCol_PopupBg, ImVec4(settings::menu::colors::window_bg[0], settings::menu::colors::window_bg[1], settings::menu::colors::window_bg[2], settings::menu::colors::window_bg[3]));
10 | PushStyleColor(ImGuiCol_ChildBg, ImVec4(settings::menu::colors::child_bg[0], settings::menu::colors::child_bg[1], settings::menu::colors::child_bg[2], settings::menu::colors::child_bg[3]));
11 | PushStyleColor(ImGuiCol_Text, ImVec4(settings::menu::colors::text[0], settings::menu::colors::text[1], settings::menu::colors::text[2], settings::menu::colors::text[3]));
12 | PushStyleColor(ImGuiCol_TextHovered, ImVec4(settings::menu::colors::text_hovered[0], settings::menu::colors::text_hovered[1], settings::menu::colors::text_hovered[2], settings::menu::colors::text_hovered[3]));
13 | PushStyleColor(ImGuiCol_TextActive, ImVec4(settings::menu::colors::text_active[0], settings::menu::colors::text_active[1], settings::menu::colors::text_active[2], settings::menu::colors::text_active[3]));
14 | PushStyleColor(ImGuiCol_FrameBg, ImVec4(settings::menu::colors::frame_bg[0], settings::menu::colors::frame_bg[1], settings::menu::colors::frame_bg[2], settings::menu::colors::frame_bg[3]));
15 | PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(settings::menu::colors::frame_hovered_bg[0], settings::menu::colors::frame_hovered_bg[1], settings::menu::colors::frame_hovered_bg[2], settings::menu::colors::frame_hovered_bg[3]));
16 | PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(settings::menu::colors::frame_active_bg[0], settings::menu::colors::frame_active_bg[1], settings::menu::colors::frame_active_bg[2], settings::menu::colors::frame_active_bg[3]));
17 |
18 | PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(720, 355));
19 |
20 | SetNextWindowPos(ImVec2(io.DisplaySize.x / 2.f, io.DisplaySize.y / 2.f), ImGuiCond_Once, ImVec2(0.5f, 0.5f));
21 | SetNextWindowSize(ImVec2(720, 355), ImGuiCond_Once);
22 |
23 | if (!Begin("Nixware", NULL, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoTitleBar))
24 | return;
25 |
26 | BeginTabBar("Tabs");
27 |
28 | if (BeginTabItem("Aimbot"))
29 | {
30 | ImVec2 child_size = ImVec2((GetColumnWidth() - (style.ItemSpacing.x * 2)) / 3, GetWindowHeight() - (GetCursorPosY() + style.ItemInnerSpacing.y * 2));
31 |
32 | BeginChild("Globals", child_size);
33 | {
34 | Checkbox("Enable", &settings::aimbot::globals::enable); custom::hotkey("Aimbot Hotkey", &settings::aimbot::globals::hotkey);
35 | Checkbox("Silent", &settings::aimbot::globals::silent);
36 | Checkbox("Automatic fire", &settings::aimbot::globals::automatic_fire);
37 | Checkbox("Penetrate walls", &settings::aimbot::globals::penetrate_walls);
38 | SliderFloat("Fov", &settings::aimbot::globals::fov, 0.f, 180.f, "%.1f", ImGuiSliderFlags_NoInput);
39 | Combo("Hitbox", &settings::aimbot::globals::hitbox, "Head\0" "Chest\0" "Stomach\0" "Hitscan\0");
40 | Combo("Priority", &settings::aimbot::globals::priority, "Fov\0" "Distance\0" "Health\0");
41 | }
42 | EndChild();
43 |
44 | SameLine();
45 |
46 | BeginChild("Accuracy", child_size);
47 | {
48 | Checkbox("Predict spread", &settings::aimbot::accuracy::predict_spread);
49 | Checkbox("Disable recoil", &settings::aimbot::accuracy::disable_recoil);
50 | Checkbox("Disable visual recoil", &settings::aimbot::accuracy::disable_visual_recoil);
51 | SliderFloat("Backtrack", &settings::aimbot::accuracy::backtrack, 0.f, 1.f, "%.3f ms", ImGuiSliderFlags_NoInput);
52 | SliderFloat("Smooth", &settings::aimbot::accuracy::smooth, 0.f, 20.f, "%.1f", ImGuiSliderFlags_NoInput);
53 | }
54 | EndChild();
55 |
56 | SameLine();
57 |
58 | BeginChild("Visuals", child_size);
59 | {
60 | Checkbox("Fov", &settings::aimbot::visuals::fov); ColorEdit4("Fov", settings::aimbot::visuals::colors::fov, color_edit4_flags);
61 | Checkbox("Snaplines", &settings::aimbot::visuals::snaplines); ColorEdit4("Snaplines", settings::aimbot::visuals::colors::snaplines, color_edit4_flags);
62 | Checkbox("Backtrack", &settings::aimbot::visuals::backtrack::enable); ColorEdit4("Backtrack", settings::aimbot::visuals::colors::backtrack, color_edit4_flags);
63 | Combo("Material", &settings::aimbot::visuals::backtrack::material_type, "Normal\0" "Flat\0" "Wireframe\0");
64 | }
65 | EndChild();
66 |
67 | EndTabItem();
68 | }
69 |
70 | if (BeginTabItem("AntiAim"))
71 | {
72 | ImVec2 child_size = ImVec2((GetColumnWidth() - (style.ItemSpacing.x * 2)) / 3, GetWindowHeight() - (GetCursorPosY() + style.ItemInnerSpacing.y * 2));
73 |
74 | BeginChild("Globals", child_size);
75 | {
76 | Checkbox("Enable", &settings::antiaim::globals::enable); custom::hotkey("AntiAim Hotkey", &settings::antiaim::globals::hotkey);
77 | Checkbox("Fake duck", &settings::antiaim::globals::fake_duck);
78 | Checkbox("At target", &settings::antiaim::globals::at_target);
79 | Checkbox("Invert yaw", &settings::antiaim::globals::invert_yaw);
80 | Combo("Yaw", &settings::antiaim::globals::yaw, "LBY\0");
81 | Combo("Pitch", &settings::antiaim::globals::pitch, "Down\0" "Up\0");
82 | }
83 | EndChild();
84 |
85 | SameLine();
86 |
87 | BeginChild("FakeLag's", child_size);
88 | {
89 | Checkbox("Enable", &settings::antiaim::fakelags::enable);
90 | SliderInt("Count", &settings::antiaim::fakelags::count, 1, 24, "%d", ImGuiSliderFlags_NoInput); /*sv_maxusrcmdprocessticks = 24*/
91 | Combo("Method", &settings::antiaim::fakelags::method, "On Ground\0" "In Air\0" "On Move\0" "On Stand\0" "Always\0");
92 | }
93 | EndChild();
94 |
95 | SameLine();
96 |
97 | BeginChild("Visuals", child_size);
98 | {
99 | Checkbox("Fake model", &settings::antiaim::visuals::fake_model::enable); ColorEdit4("Fake model", settings::antiaim::visuals::colors::fake_model, color_edit4_flags);
100 | Combo("Material", &settings::antiaim::visuals::fake_model::material_type, "Normal\0" "Flat\0" "Wireframe\0");
101 | }
102 | EndChild();
103 |
104 | EndTabItem();
105 | }
106 |
107 | if (BeginTabItem("Visuals"))
108 | {
109 | ImVec2 child_size = ImVec2((GetColumnWidth() - (style.ItemSpacing.x * 2)) / 3, GetWindowHeight() - (GetCursorPosY() + style.ItemInnerSpacing.y * 2));
110 |
111 | BeginChild("ESP", child_size);
112 | {
113 | static int type = 0;
114 | Combo("##ESP", &type, "Player\0" "Entity\0");
115 |
116 | switch (type)
117 | {
118 | case 0:
119 | {
120 | Checkbox("Enable", &settings::visuals::players::enable);
121 | Checkbox("Dormant", &settings::visuals::players::dormant);
122 | Checkbox("Box", &settings::visuals::players::box); ColorEdit4("Box", settings::visuals::players::colors::box, color_edit4_flags);
123 | Checkbox("Name", &settings::visuals::players::name); ColorEdit4("Name", settings::visuals::players::colors::name, color_edit4_flags);
124 | Checkbox("Rp team", &settings::visuals::players::rp_team); ColorEdit4("Rp team", settings::visuals::players::colors::rp_team, color_edit4_flags);
125 | Checkbox("User group", &settings::visuals::players::user_group); ColorEdit4("User group", settings::visuals::players::colors::user_group, color_edit4_flags);
126 | Checkbox("Weapon name", &settings::visuals::players::weapon_name); ColorEdit4("Weapon name", settings::visuals::players::colors::weapon_name, color_edit4_flags);
127 | Checkbox("Distance", &settings::visuals::players::distance); ColorEdit4("Distance", settings::visuals::players::colors::distance, color_edit4_flags);
128 | SliderInt("Render distance", &settings::visuals::players::render_distance, 100, 20000, "%d m", ImGuiSliderFlags_NoInput);
129 | }
130 | break;
131 | case 1:
132 | {
133 | Checkbox("Enable", &settings::visuals::entity::enable);
134 | Checkbox("Dormant", &settings::visuals::entity::dormant);
135 | Checkbox("Box", &settings::visuals::entity::box); ColorEdit4("Box", settings::visuals::entity::colors::box, color_edit4_flags);
136 | Checkbox("Name", &settings::visuals::entity::name); ColorEdit4("Name", settings::visuals::entity::colors::name, color_edit4_flags);
137 | Checkbox("Distance", &settings::visuals::entity::distance); ColorEdit4("Distance", settings::visuals::entity::colors::distance, color_edit4_flags);
138 |
139 | if (BeginCombo("List", "..."))
140 | {
141 | for (auto item : settings::visuals::entity::list.items())
142 | {
143 | bool temp = item.value();
144 | Selectable(item.key().c_str(), &temp, ImGuiSelectableFlags_DontClosePopups);
145 | item.value() = temp;
146 | }
147 |
148 | EndCombo();
149 | }
150 |
151 | SliderInt("Render distance", &settings::visuals::entity::render_distance, 100, 20000, "%d m", ImGuiSliderFlags_NoInput);
152 | }
153 | break;
154 | }
155 | }
156 | EndChild();
157 |
158 | SameLine();
159 |
160 | BeginChild("Chams", child_size);
161 | {
162 |
163 | }
164 | EndChild();
165 |
166 | SameLine();
167 |
168 | BeginChild("World", child_size);
169 | {
170 |
171 | }
172 | EndChild();
173 |
174 | EndTabItem();
175 | }
176 |
177 | if (BeginTabItem("Misc"))
178 | {
179 | ImVec2 child_size = ImVec2((GetColumnWidth() - (style.ItemSpacing.x)) / 2, GetWindowHeight() - (GetCursorPosY() + style.ItemInnerSpacing.y * 2));
180 |
181 | BeginChild("Globals", child_size);
182 | {
183 | Checkbox("ThirdPerson", &settings::miscellaneous::globals::third_person::enable); custom::hotkey("Third person Hotkey", &settings::miscellaneous::globals::third_person::hotkey);
184 | SliderInt("ThirdPerson Distance", &settings::miscellaneous::globals::third_person::distance, 10, 200);
185 | }
186 | EndChild();
187 |
188 | SameLine();
189 |
190 | BeginChild("Movement", child_size);
191 | {
192 | Checkbox("Bunny hop", &settings::miscellaneous::movement::bhop);
193 | Checkbox("Air strafe", &settings::miscellaneous::movement::air_strafe);
194 | }
195 | EndChild();
196 |
197 | EndTabItem();
198 | }
199 |
200 | if (BeginTabItem("Lua"))
201 | {
202 | ImVec2 child_size = ImVec2((GetColumnWidth() - (style.ItemSpacing.x * 2)) / 3, GetWindowHeight() - (GetCursorPosY() + style.ItemInnerSpacing.y * 2));
203 |
204 | static int selected_item = -1;
205 | static char search_buffer[256] = "";
206 |
207 | std::vector file_list = { "autodance", "exechack :)", "hitlog", "test", "rehack" };
208 |
209 | BeginChild("Scripts", child_size);
210 | {
211 | float column_width = GetColumnWidth();
212 |
213 | PushItemWidth(column_width - 10.f);
214 | InputText("Search", search_buffer, sizeof(search_buffer));
215 |
216 | if (BeginListBox("##Files", ImVec2(0, GetWindowHeight() - (GetCursorPosY() + 10.f))))
217 | {
218 | for (int i = 0; i < file_list.size(); i++)
219 | {
220 | if (Selectable(file_list[i].c_str(), selected_item == i, 0, ImVec2(column_width, 0)))
221 | selected_item = i;
222 | }
223 |
224 | EndListBox();
225 | }
226 |
227 | PopItemWidth();
228 | }
229 | EndChild();
230 |
231 | SameLine();
232 |
233 | BeginChild("Action", child_size);
234 | {
235 | float column_width = GetColumnWidth();
236 |
237 | if (selected_item != -1 && selected_item < file_list.size())
238 | {
239 | std::string path = "C:/nixware/lua/" + file_list[selected_item] + ".lua";
240 |
241 | LabelText(file_list[selected_item].c_str());
242 | LabelText("Last update:", "18 Apr 2024 23:52");
243 |
244 | Button("Load script", ImVec2(column_width - 10.f, 35.f));
245 | }
246 | }
247 | EndChild();
248 |
249 | SameLine();
250 |
251 | BeginChild("Misc", child_size);
252 | {
253 | Checkbox("Dumper", &settings::lua::miscellaneous::dumper);
254 | }
255 | EndChild();
256 |
257 | EndTabItem();
258 | }
259 |
260 | if (BeginTabItem("Settings"))
261 | {
262 | ImVec2 child_size = ImVec2((GetColumnWidth() - (style.ItemSpacing.x * 2)) / 3, GetWindowHeight() - (GetCursorPosY() + style.ItemInnerSpacing.y * 2));
263 |
264 | BeginChild("Info", child_size);
265 | {
266 | LabelText("Last update:", __DATE__);
267 | }
268 | EndChild();
269 |
270 | SameLine();
271 |
272 | BeginChild("Menu", child_size);
273 | {
274 | LabelText("WindowBg"); ColorEdit4("WindowBg", settings::menu::colors::window_bg, color_edit4_flags);
275 | LabelText("ChildBg"); ColorEdit4("ChildBg", settings::menu::colors::child_bg, color_edit4_flags);
276 | LabelText("Text"); ColorEdit4("Text", settings::menu::colors::text, color_edit4_flags);
277 | LabelText("TextHovered"); ColorEdit4("TextHovered", settings::menu::colors::text_hovered, color_edit4_flags);
278 | LabelText("TextActive"); ColorEdit4("TextActive", settings::menu::colors::text_active, color_edit4_flags);
279 | LabelText("FrameBg"); ColorEdit4("FrameBg", settings::menu::colors::frame_bg, color_edit4_flags);
280 | LabelText("FrameHoveredBg"); ColorEdit4("FrameHoveredBg", settings::menu::colors::frame_hovered_bg, color_edit4_flags);
281 | LabelText("FrameActiveBg"); ColorEdit4("FrameActiveBg", settings::menu::colors::frame_active_bg, color_edit4_flags);
282 | Checkbox("Custom loading screen", &settings::menu::custom_loading_screen);
283 | }
284 | EndChild();
285 |
286 | SameLine();
287 |
288 | BeginChild("Configs", child_size);
289 | {
290 | float column_width = GetColumnWidth();
291 |
292 | Button("Unload cheat", ImVec2(column_width - 10.f, 35.f));
293 | }
294 | EndChild();
295 |
296 | EndTabItem();
297 | }
298 |
299 | EndTabBar();
300 | End();
301 |
302 | PopStyleColor(9);
303 | PopStyleVar();
304 | }
305 |
306 | void menu::custom::hotkey(const char* label, hotkey_t* hotkey)
307 | {
308 | ImGuiWindow* window = GetCurrentWindow();
309 | if (window->SkipItems)
310 | return;
311 |
312 | SameLine();
313 |
314 | ImGuiContext& g = *GImGui;
315 | const ImGuiStyle& style = g.Style;
316 | const ImGuiID id = window->GetID(label);
317 |
318 | const float width = GetColumnWidth();
319 | const ImVec2 pos = window->DC.CursorPos;
320 |
321 | char context_name[64] = { };
322 | ImFormatString(context_name, sizeof(context_name), "HotKeyContext%s", label);
323 |
324 | char text[64] = { };
325 | const char* hotkeyText = (hotkey->key != 0 && g.ActiveId != id) ? key_names[hotkey->key] : (g.ActiveId == id) ? "WAIT KEY" : "NONE";
326 | ImFormatString(text, sizeof(text), "[ %s ]", hotkeyText);
327 |
328 | const ImVec2 text_size = CalcTextSize(text, NULL, true);
329 |
330 | const ImRect total_bb(ImVec2(pos.x + width - (text_size.x + 10.f), pos.y - style.FramePadding.y), ImVec2(pos.x + width, pos.y + text_size.y));
331 |
332 | ItemSize(total_bb);
333 | if (!ItemAdd(total_bb, id))
334 | return;
335 |
336 | const bool hovered = ItemHoverable(total_bb, id);
337 | if (hovered)
338 | SetHoveredID(id);
339 |
340 | if (hovered && (g.IO.MouseClicked[0] || g.IO.MouseDoubleClicked[0]))
341 | {
342 | if (g.ActiveId != id)
343 | {
344 | memset(g.IO.MouseDown, 0, sizeof(g.IO.MouseDown));
345 | memset(g.IO.KeysDown, 0, sizeof(g.IO.KeysDown));
346 | hotkey->key = 0;
347 | }
348 |
349 | SetActiveID(id, window);
350 | }
351 |
352 | bool changed = false;
353 | if (int key = hotkey->key; g.ActiveId == id)
354 | {
355 | for (int n = 0; n < IM_ARRAYSIZE(g.IO.MouseDown); n++)
356 | {
357 | if (IsMouseDown(n))
358 | {
359 | switch (n)
360 | {
361 | case 0:
362 | key = 1;
363 | break;
364 | case 1:
365 | key = 2;
366 | break;
367 | case 2:
368 | key = 4;
369 | break;
370 | case 3:
371 | key = 5;
372 | break;
373 | case 4:
374 | key = 6;
375 | break;
376 | }
377 |
378 | changed = true;
379 | ClearActiveID();
380 | }
381 | }
382 |
383 | if (!changed)
384 | {
385 | for (int n = 8; n <= 165; n++)
386 | {
387 | if (IsKeyDown((ImGuiKey)n))
388 | {
389 | key = n;
390 | changed = true;
391 | ClearActiveID();
392 | }
393 | }
394 | }
395 |
396 | if (IsKeyPressed(ImGuiKey_Escape))
397 | {
398 | hotkey->key = 0;
399 | ClearActiveID();
400 | }
401 | else
402 | hotkey->key = key;
403 | }
404 |
405 | RenderText(total_bb.Min, text);
406 |
407 | PushStyleColor(ImGuiCol_PopupBg, ImVec4(0, 0, 0, 0));
408 | PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(80, 65));
409 | PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5, 5));
410 |
411 | if (BeginPopupContextItem(context_name))
412 | {
413 | SetWindowPos(ImVec2(total_bb.Min.x, total_bb.Max.y));
414 |
415 | if (Selectable("Always on", hotkey->type == hotkey_t::always_on))
416 | hotkey->type = hotkey_t::always_on;
417 |
418 | if (Selectable("Hold", hotkey->type == hotkey_t::hold))
419 | hotkey->type = hotkey_t::hold;
420 |
421 | if (Selectable("Toggle", hotkey->type == hotkey_t::toggle))
422 | hotkey->type = hotkey_t::toggle;
423 |
424 | if (Selectable("Force disable", hotkey->type == hotkey_t::force_disable))
425 | hotkey->type = hotkey_t::force_disable;
426 |
427 | End();
428 | }
429 |
430 | PopStyleColor();
431 | PopStyleVar(2);
432 | }
--------------------------------------------------------------------------------
/showcase/src/menu/menu.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | #include "../settings.h"
5 | #include "../imgui/imgui.h"
6 | #include "../imgui/imgui_internal.h"
7 | #include "../imgui/backends/imgui_impl_glfw.h"
8 | #include "../imgui/backends/imgui_impl_opengl3.h"
9 | #include "../imgui/freetype/imgui_freetype.h"
10 |
11 | using namespace ImGui;
12 |
13 | namespace menu
14 | {
15 | const ImGuiColorEditFlags color_edit4_flags = ImGuiColorEditFlags_NoBorder | ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_NoDragDrop | ImGuiColorEditFlags_AlphaPreview;
16 |
17 | void render();
18 |
19 | namespace custom
20 | {
21 | void hotkey(const char* label, hotkey_t* hotkey);
22 |
23 | const char* const key_names[] =
24 | {
25 | "UNK",
26 | "MOUSE_L",
27 | "MOUSE_R",
28 | "CANCEL",
29 | "MOUSE_3",
30 | "MOUSE_4",
31 | "MOUSE_5",
32 | "UNK",
33 | "BACK",
34 | "TAB",
35 | "UNK",
36 | "UNK",
37 | "CLEAR",
38 | "RETURN",
39 | "UNK",
40 | "UNK",
41 | "SHIFT",
42 | "CONTROL",
43 | "MENU",
44 | "PAUSE",
45 | "CAPITAL",
46 | "KANA",
47 | "UNK",
48 | "JUNJA",
49 | "FINAL",
50 | "KANJI",
51 | "UNK",
52 | "ESCAPE",
53 | "CONVERT",
54 | "NONCONVERT",
55 | "ACCEPT",
56 | "MODECHANGE",
57 | "SPACE",
58 | "PRIOR",
59 | "NEXT",
60 | "END",
61 | "HOME",
62 | "LEFT",
63 | "UP",
64 | "RIGHT",
65 | "DOWN",
66 | "SELECT",
67 | "PRINT",
68 | "EXECUTE",
69 | "SNAPSHOT",
70 | "INSERT",
71 | "DELETE",
72 | "HELP",
73 | "0",
74 | "1",
75 | "2",
76 | "3",
77 | "4",
78 | "5",
79 | "6",
80 | "7",
81 | "8",
82 | "9",
83 | "UNK",
84 | "UNK",
85 | "UNK",
86 | "UNK",
87 | "UNK",
88 | "UNK",
89 | "UNK",
90 | "A",
91 | "B",
92 | "C",
93 | "D",
94 | "E",
95 | "F",
96 | "G",
97 | "H",
98 | "I",
99 | "J",
100 | "K",
101 | "L",
102 | "M",
103 | "N",
104 | "O",
105 | "P",
106 | "Q",
107 | "R",
108 | "S",
109 | "T",
110 | "U",
111 | "V",
112 | "W",
113 | "X",
114 | "Y",
115 | "Z",
116 | "LWIN",
117 | "RWIN",
118 | "APPS",
119 | "UNK",
120 | "SLEEP",
121 | "0",
122 | "1",
123 | "2",
124 | "3",
125 | "4",
126 | "5",
127 | "6",
128 | "7",
129 | "8",
130 | "9",
131 | "MULTIPLY",
132 | "ADD",
133 | "SEPARATOR",
134 | "SUBTRACT",
135 | "DECIMAL",
136 | "DIVIDE",
137 | "F1",
138 | "F2",
139 | "F3",
140 | "F4",
141 | "F5",
142 | "F6",
143 | "F7",
144 | "F8",
145 | "F9",
146 | "F10",
147 | "F11",
148 | "F12",
149 | "F13",
150 | "F14",
151 | "F15",
152 | "F16",
153 | "F17",
154 | "F18",
155 | "F19",
156 | "F20",
157 | "F21",
158 | "F22",
159 | "F23",
160 | "F24",
161 | "UNK",
162 | "UNK",
163 | "UNK",
164 | "UNK",
165 | "UNK",
166 | "UNK",
167 | "UNK",
168 | "UNK",
169 | "NUMLOCK",
170 | "SCROLL",
171 | "OEM_NEC_EQUAL",
172 | "OEM_FJ_MASSHOU",
173 | "OEM_FJ_TOUROKU",
174 | "OEM_FJ_LOYA",
175 | "OEM_FJ_ROYA",
176 | "UNK",
177 | "UNK",
178 | "UNK",
179 | "UNK",
180 | "UNK",
181 | "UNK",
182 | "UNK",
183 | "UNK",
184 | "UNK",
185 | "LSHIFT",
186 | "RSHIFT",
187 | "LCONTROL",
188 | "RCONTROL",
189 | "LMENU",
190 | "RMENU"
191 | };
192 | }
193 | }
--------------------------------------------------------------------------------
/showcase/src/settings.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "../json/json.hpp"
3 |
4 | struct hotkey_t
5 | {
6 | int key;
7 |
8 | enum type
9 | {
10 | always_on,
11 | hold,
12 | toggle,
13 | force_disable
14 | } type = hold;
15 |
16 | private:
17 | bool toggle_state = false;
18 | };
19 |
20 | namespace settings
21 | {
22 | namespace menu
23 | {
24 | inline bool opened = false;
25 | inline bool custom_loading_screen = true;
26 |
27 | namespace colors
28 | {
29 | inline float window_bg[4] = { 0.07f, 0.07f, 0.07f, 1.f };
30 | inline float child_bg[4] = { 0.1f, 0.1f, 0.1f, 1.f };
31 | inline float text[4] = { 0.4f, 0.4f, 0.4f, 1.f };
32 | inline float text_hovered[4] = { 0.8f, 0.8f, 0.8f, 1.f };
33 | inline float text_active[4] = { 1.f, 1.f, 1.f, 1.f };
34 | inline float frame_bg[4] = { 0.2f, 0.2f, 0.2f, 1.f };
35 | inline float frame_hovered_bg[4] = { 0.4f, 0.4f, 0.4f, 1.f };
36 | inline float frame_active_bg[4] = { 1.f, 1.f, 1.f, 1.f };
37 | }
38 | }
39 |
40 | namespace aimbot
41 | {
42 | namespace globals
43 | {
44 | inline bool enable = false;
45 | inline hotkey_t hotkey;
46 | inline bool silent = false;
47 | inline bool automatic_fire = false;
48 | inline bool penetrate_walls = false;
49 | inline float fov = 0;
50 | inline int hitbox = 0;
51 | inline int priority = 0;
52 | }
53 |
54 | namespace accuracy
55 | {
56 | inline bool predict_spread = false;
57 | inline bool disable_recoil = false;
58 | inline bool disable_visual_recoil = false;
59 | inline float backtrack = 0;
60 | inline float smooth = 0.f;
61 | }
62 |
63 | namespace visuals
64 | {
65 | inline bool fov = false;
66 | inline bool snaplines = false;
67 |
68 | namespace backtrack
69 | {
70 | inline bool enable = false;
71 | inline int material_type = 0;
72 | }
73 |
74 | namespace colors
75 | {
76 | inline float fov[4] = { 1.f, 1.f, 1.f, 1.f };
77 | inline float snaplines[4] = { 1.f, 1.f, 1.f, 1.f };
78 | inline float backtrack[4] = { 1.f, 1.f, 1.f, 1.f };
79 | }
80 | }
81 | }
82 |
83 | namespace antiaim
84 | {
85 | namespace globals
86 | {
87 | inline bool enable = false;
88 | inline hotkey_t hotkey;
89 | inline int yaw = 0;
90 | inline int pitch = 0;
91 | inline bool at_target = false;
92 | inline bool invert_yaw = false;
93 | inline bool fake_duck = false;
94 | }
95 |
96 | namespace fakelags
97 | {
98 | inline bool enable = false;
99 | inline int count = 1;
100 | inline int method = 0;
101 | }
102 |
103 | namespace visuals
104 | {
105 | namespace fake_model
106 | {
107 | inline bool enable = false;
108 | inline int material_type = 0;
109 | }
110 |
111 | namespace colors
112 | {
113 | inline float fake_model[4] = { 1.f, 1.f, 1.f, 1.f };
114 | }
115 | }
116 | }
117 |
118 | namespace visuals
119 | {
120 | namespace players
121 | {
122 | inline bool enable = false;
123 | inline bool dormant = false;
124 | inline bool box = false;
125 | inline bool name = false;
126 | inline bool rp_team = false;
127 | inline bool user_group = false;
128 | inline bool weapon_name = false;
129 | inline bool distance = false;
130 | inline int render_distance = 15000;
131 |
132 | namespace colors
133 | {
134 | inline float box[4] = { 1.f, 1.f, 1.f, 1.f };
135 | inline float name[4] = { 1.f, 1.f, 1.f, 1.f };
136 | inline float rp_team[4] = { 1.f, 1.f, 1.f, 1.f };
137 | inline float user_group[4] = { 1.f, 1.f, 1.f, 1.f };
138 | inline float weapon_name[4] = { 1.f, 1.f, 1.f, 1.f };
139 | inline float distance[4] = { 1.f, 1.f, 1.f, 1.f };
140 | }
141 | }
142 |
143 | namespace entity
144 | {
145 | inline nlohmann::json list;
146 |
147 | inline bool enable = false;
148 | inline bool dormant = false;
149 | inline bool box = false;
150 | inline bool name = false;
151 | inline bool distance = false;
152 |
153 | inline int render_distance = 15000;
154 |
155 | namespace colors
156 | {
157 | inline float box[4] = { 1.f, 1.f, 1.f, 1.f };
158 | inline float name[4] = { 1.f, 1.f, 1.f, 1.f };
159 | inline float distance[4] = { 1.f, 1.f, 1.f, 1.f };
160 | }
161 | }
162 | }
163 |
164 | namespace miscellaneous
165 | {
166 | namespace globals
167 | {
168 | namespace third_person
169 | {
170 | inline bool enable = false;
171 | inline hotkey_t hotkey;
172 | inline int distance = 100;
173 | }
174 | }
175 |
176 | namespace movement
177 | {
178 | inline bool bhop = false;
179 | inline bool air_strafe = false;
180 | }
181 | }
182 |
183 | namespace lua
184 | {
185 | namespace miscellaneous
186 | {
187 | inline bool dumper = false;
188 | }
189 |
190 | }
191 | }
--------------------------------------------------------------------------------