├── .appveyor.yml ├── .gitignore ├── .travis.yml ├── Changelog.md ├── Configure.md ├── Developers.md ├── Examples.md ├── PlatformSupport.md ├── README.md ├── addon_config.mk ├── example-ImGuizmo ├── addons.make ├── error.PNG └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example-advanced ├── addons.make ├── bin │ └── data │ │ ├── of.png │ │ └── of_upside_down.png └── src │ ├── RandomTheme.cpp │ ├── RandomTheme.h │ ├── fx.inl │ ├── imdrawlist_party.cpp │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example-debug ├── addons.make └── src │ ├── imgui_windows_info.h │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example-demo ├── addons.make └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example-dockingandviewports ├── addons.make └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example-fonts ├── ProggyTiny-License.txt ├── addons.make ├── bin │ └── data │ │ ├── Roboto-Medium.ttf │ │ ├── fa-regular-400.ttf │ │ └── fa-regular-400.ttf-LICENSE.txt ├── example-fonts.qbs └── src │ ├── IconsFontAwesome5.h │ ├── ProggyTiny.cpp │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example-helpers ├── addons.make └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example-ios ├── addons.make ├── bin │ └── data │ │ ├── of.png │ │ └── of_upside_down.png └── src │ ├── InputTextButton.h │ ├── InputTextButton.mm │ ├── main.mm │ ├── ofApp.h │ └── ofApp.mm ├── example-multiwindow ├── addons.make └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── example-sharedcontext ├── addons.make ├── example-sharedContext.qbs └── src │ ├── main.cpp │ ├── myAddonClass.cpp │ ├── myAddonClass.h │ ├── ofApp.cpp │ ├── ofApp.h │ ├── privateAddonClass.cpp │ └── privateAddonClass.h ├── example-simple ├── addons.make └── src │ ├── main.cpp │ ├── ofApp.cpp │ └── ofApp.h ├── images ├── ImageButton.gif ├── Screenshot.png └── ofxImGui.gif ├── libs ├── Glfw_GLES1_Support.diff ├── Glfw_MultiContext_Support.diff ├── UpdateImGui.sh └── imgui │ ├── backends │ ├── imgui_impl_glfw.cpp │ ├── imgui_impl_glfw.h │ ├── imgui_impl_glfw_arc_support.h │ ├── imgui_impl_glfw_context_support.cpp │ ├── imgui_impl_glfw_context_support.h │ ├── imgui_impl_opengl2.cpp │ ├── imgui_impl_opengl2.h │ ├── imgui_impl_opengl3.cpp │ ├── imgui_impl_opengl3.h │ └── imgui_impl_opengl3_loader.h │ ├── docs │ ├── BACKENDS.md │ ├── CHANGELOG.txt │ └── README.md │ ├── extras │ ├── imgui_stdlib.cpp │ └── imgui_stdlib.h │ └── src │ ├── LICENSE.txt │ ├── imgui.cpp │ ├── imgui.h │ ├── imgui_demo.cpp │ ├── imgui_draw.cpp │ ├── imgui_internal.h │ ├── imgui_tables.cpp │ ├── imgui_widgets.cpp │ ├── imstb_rectpack.h │ ├── imstb_textedit.h │ └── imstb_truetype.h ├── ofxaddons_thumbnail.png ├── scripts └── ci │ └── install.sh └── src ├── BaseEngine.cpp ├── BaseEngine.h ├── BaseTheme.h ├── DefaultTheme.cpp ├── DefaultTheme.h ├── EngineGLFW.cpp ├── EngineGLFW.h ├── EngineOpenFrameworks.cpp ├── EngineOpenFrameworks.h ├── EngineOpenGLES.cpp ├── EngineOpenGLES.h ├── EngineVk.cpp ├── EngineVk.h ├── Gui.cpp ├── Gui.h ├── ImHelpers.cpp ├── ImHelpers.h ├── LinkedList.hpp ├── gles1CompatibilityHacks.h ├── glfwCompatibilityHacks.h ├── imconfig.h ├── ofxImGui.h ├── ofxImGuiConstants.h ├── ofxImGuiLoggerChannel.cpp └── ofxImGuiLoggerChannel.h /.appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.0.{build} 2 | 3 | environment: 4 | global: 5 | APPVEYOR_OS_NAME: windows 6 | matrix: 7 | #MSYS2 Building 8 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 9 | platform: x86 10 | BUILDER: MSYS2 11 | 12 | #VisualStudio Building 13 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 14 | platform: x86 15 | BUILDER : VS 16 | BITS: 32 17 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 18 | platform: x64 19 | BUILDER : VS 20 | BITS: 64 21 | 22 | configuration: Debug 23 | shallow_clone: true 24 | clone_depth: 10 25 | 26 | init: 27 | - set MSYS2_PATH=c:\msys64 28 | - set CHERE_INVOKING=1 29 | - if "%BUILDER%_%PLATFORM%"=="MSYS2_x86" set MSYSTEM=MINGW32 30 | - if "%BUILDER%_%PLATFORM%"=="MSYS2_x64" set MSYSTEM=MINGW64 31 | - '%MSYS2_PATH%\usr\bin\bash -lc "pacman --noconfirm -S --needed unzip rsync"' 32 | - if "%BUILDER%"=="VS" set PATH=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin;%PATH% 33 | 34 | install: 35 | - cd .. 36 | - git clone --depth=1 --branch=master https://github.com/openframeworks/openFrameworks 37 | - call openFrameworks\scripts\ci\addons\install.cmd 38 | 39 | build_script: 40 | - cd %OF_PATH% 41 | - scripts\ci\addons\build.cmd 42 | 43 | 44 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # This file allows testing your addon using travis CI servers to use it you'll need to 2 | # create an account in travis.org and enable your addon there. 3 | # 4 | # By default it will test linux 64bit and osx against the master and stable OF branches. 5 | # Other platforms can be enabled by uncommenting the corresponding sections. 6 | # 7 | # If any extra install is needed to use the addon it can be included in the corresponding 8 | # install script in: 9 | # 10 | # scripts/ci/$TARGET/install.sh 11 | # 12 | 13 | 14 | language: c++ 15 | compiler: gcc 16 | sudo: true 17 | matrix: 18 | include: 19 | # fully specify builds, include can't dynamically expand matrix entries 20 | # relative order of sudo and env is important so that addons: is recognized 21 | 22 | # Linux 64bit, OF master 23 | # - os: linux 24 | # dist: trusty 25 | # sudo: required 26 | # env: TARGET="linux64" OF_BRANCH="master" 27 | # addons: 28 | # apt: 29 | # sources: 30 | # - ubuntu-toolchain-r-test 31 | # packages: 32 | # - gcc-4.9 33 | # - g++-4.9 34 | # - gdb 35 | 36 | # Linux 64bit, OF stable: Not supported yet 37 | # - os: linux 38 | # dist: trusty 39 | # sudo: required 40 | # env: TARGET="linux64" OF_BRANCH="stable" 41 | # addons: 42 | # apt: 43 | # sources: 44 | # - ubuntu-toolchain-r-test 45 | # packages: 46 | # - gcc-4.9 47 | # - g++-4.9 48 | # - gdb 49 | 50 | # OSX, OF master 51 | - os: osx 52 | #osx_image: xcode8 53 | #compiler: clang 54 | env: TARGET="osx" OF_BRANCH="master" 55 | 56 | # OSX, OF stable: Not supported yet 57 | # - os: osx 58 | # osx_image: xcode8 59 | # compiler: clang 60 | # env: TARGET="osx" OF_BRANCH="stable" 61 | 62 | # Linux ARM6, OF master: Uncomment following lines to enable 63 | # - os: linux 64 | # sudo: required 65 | # dist: trusty 66 | # env: TARGET="linuxarmv6l" OF_BRANCH="master" 67 | 68 | 69 | # Linux ARM6, OF stable: Not supported yet 70 | # - os: linux 71 | # sudo: required 72 | # dist: trusty 73 | # env: TARGET="linuxarmv6l" OF_BRANCH="stable" 74 | 75 | # Linux ARM7, OF master: Uncomment following lines to enable 76 | # - os: linux 77 | # sudo: false 78 | # env: TARGET="linuxarmv7l" OF_BRANCH="master" 79 | # cache: 80 | # directories: 81 | # - ~/rpi2_toolchain 82 | # - ~/firmware-master 83 | # - ~/archlinux 84 | 85 | # Linux ARM7, OF stable: Not supported yet 86 | # - os: linux 87 | # sudo: false 88 | # env: TARGET="linuxarmv7l" OF_BRANCH="stable" 89 | # cache: 90 | # directories: 91 | # - ~/rpi2_toolchain 92 | # - ~/firmware-master 93 | # - ~/archlinux 94 | 95 | 96 | # Emscripten, OF master: Uncomment following lines to enable 97 | # - os: linux 98 | # sudo: false 99 | # env: TARGET="emscripten" OF_BRANCH="master" 100 | # addons: 101 | # apt: 102 | # sources: 103 | # - ubuntu-toolchain-r-test 104 | # packages: 105 | # - libstdc++6 106 | 107 | 108 | # Emscripten, OF stable: Not supported yet 109 | # - os: linux 110 | # sudo: false 111 | # env: TARGET="emscripten" OF_BRANCH="stable" 112 | # addons: 113 | # apt: 114 | # sources: 115 | # - ubuntu-toolchain-r-test 116 | # packages: 117 | # - libstdc++6 118 | 119 | 120 | # iOS, OF master: Not supported yet 121 | # - os: osx 122 | # osx_image: xcode8 123 | # compiler: clang 124 | # env: TARGET="ios" OF_BRANCH="master" 125 | 126 | 127 | # iOS, OF stable: Not supported yet 128 | # - os: osx 129 | # osx_image: xcode8 130 | # compiler: clang 131 | # env: TARGET="ios" OF_BRANCH="stable" 132 | 133 | 134 | # tvOS, OF master: Not supported yet 135 | # - os: osx 136 | # osx_image: xcode8 137 | # compiler: clang 138 | # env: TARGET="tvos" OF_BRANCH="master" 139 | 140 | 141 | # tvOS, OF stable: Not supported yet 142 | # - os: osx 143 | # osx_image: xcode8 144 | # compiler: clang 145 | # env: TARGET="tvos" OF_BRANCH="stable" 146 | 147 | 148 | # Android armv7, OF master: Uncomment following lines to enable 149 | # - os: linux 150 | # sudo: false 151 | # env: TARGET="android" OPT="armv7" OF_BRANCH="master" 152 | # cache: 153 | # directories: 154 | # - ~/android-ndk-r12b 155 | 156 | 157 | # Android armv7, OF stable: Not supported yet 158 | # - os: linux 159 | # sudo: false 160 | # env: TARGET="android" OPT="armv7" OF_BRANCH="stable" 161 | # cache: 162 | # directories: 163 | # - ~/android-ndk-r12b 164 | 165 | 166 | # Android x86, OF master: Uncomment following lines to enable 167 | # - os: linux 168 | # sudo: false 169 | # env: TARGET="android" OPT="x86" OF_BRANCH="master" 170 | # cache: 171 | # directories: 172 | # - ~/android-ndk-r12b 173 | 174 | 175 | # Android x86, OF stable: Not supported yet 176 | # - os: linux 177 | # sudo: false 178 | # env: TARGET="android" OPT="x86" OF_BRANCH="stable" 179 | # cache: 180 | # directories: 181 | # - ~/android-ndk-r12b 182 | 183 | 184 | # Exclude the default build that would otherwise be generated 185 | # see https://github.com/travis-ci/travis-ci/issues/1228 186 | exclude: 187 | - compiler: gcc 188 | 189 | install: 190 | - cd ~ 191 | - git clone --depth=1 --branch=$OF_BRANCH https://github.com/openframeworks/openFrameworks 192 | - cd openFrameworks 193 | - scripts/ci/addons/install.sh 194 | 195 | script: 196 | - scripts/ci/addons/build.sh 197 | 198 | git: 199 | depth: 10 200 | -------------------------------------------------------------------------------- /Changelog.md: -------------------------------------------------------------------------------- 1 | 2 | # Changelog 3 | 4 | _Note: This document is focused on ofxImGui. For detailed ImGui API changes and new features, please refer to the [ImGui changelog](https://github.com/ocornut/imgui/blob/v1.91.0-docking/docs/CHANGELOG.txt)._ 5 | _Tip: For compile-time depreciation hinting on your code, uncomment `IMGUI_DISABLE_OBSOLETE_FUNCTIONS` in `imconfig.h`. If you do this regurarly, it's quite easy to keep up with the occasional ImGui breaking API changes._ 6 | 7 | - - - - 8 | 9 | # ofxImGui 1.91.0 10 | - Lots of new documentation. 11 | - Fix issue where default font was overwritten loading a first custom font. 12 | - Newly introduced ImGui Features : multi-select, box-select, item flags, links. 13 | 14 | - - - - 15 | 16 | # ofxImGui 1.82 (develop) 17 | This is a major update for ofxImGui. Prior to this version, DearImGui was bound to openFrameworks using a "custom backend code". 18 | DearImGui has grown considerably over time, but some of the new (optional but nice) features require an advanced backend code, which is now provided by ImGui. For these features to be enabled, DearImGui now needs to be bound to the OS' windowing framework (GLFW). Luckily this is currently the same as most OpenFrameworks projects, and other popular windowing frameworks are also covered in case OpenFrameworks moves away from GLFW. 19 | 20 | ### Breaking changes 21 | - **GLFW** : If your project uses a windowing system other then GLFW, this newer ofxImGui will not work correctly. This is mainly the case for Emscriptem projects, iOS and some Rpi environments. Consider using an [older ofxImGui release](https://github.com/jvcleave/ofxImGui/tree/330e1425a88de7babd53ceb2fb93f8109b61724c), or try [this untested commit](https://github.com/jvcleave/ofxImGui/tree/05ab1311511523c63c6f22d38ee015942b9ea557) together with `OFXIMGUI_ENABLE_OF_BINDINGS` if you need ImGui 1.79 features. 22 | - **Autodraw** : This setting was already around but worked differently, which lead to confusions. It used to call `gui.draw()` when calling `gui.end()`. Now, when autodraw is enabled, ofxImGui uses a callback on `ofEvents::afterDraw()` to render the gui, drawing the gui always on top of your ofApp. This might affect the render order rendered in your pipeline. 23 | - **imgui_stdlib.h/cpp** : If you were using them in your project, please remove the files, they are now included with ofxImGui. 24 | - **ImHelpers.cpp** : If you are using them, they are not included by default via `#import "ofxImGui.h"`, you now need to include it manually (`#import "ImHelpers.h"`). 25 | - **ImGui API changes** : Refer to the ImGui changelog. 26 | 27 | As an upgrade assistant, you might want to enable `OFXIMGUI_DEBUG` while transitioning, it will provide some general warnings on mistakes. 28 | 29 | For more exhaustive information on changes, refer to [Daandelange/ofxImGui#1](https://github.com/Daandelange/ofxImGui/issues/1) and [jvcleave/ofxImGui#107](https://github.com/jvcleave/ofxImGui/issues/107). 30 | 31 | ### New Features 32 | - Load custom fonts 33 | - Set `ImGuiConfigFlags` when setting up ofxImGui. _There were some workarounds for this, but not it's possible natively._ 34 | - Share ofxImGui instances within the same ofApp. _By enabling a shared mode, any ofxImGui instance will act as a singleton so multiple instances can seamlessly let eachother know when to render._ 35 | - Multi-window support **beta**. _Any feedback is appreciated_. 36 | - Improved example projects. 37 | - Helpers : 38 | - AddGroup() can now receive treenode flags. 39 | - New: ofColor and std::string parameters 40 | - Main features introduced by the DearImGui update: 41 | - Navigation support : Control the GUI with a gamepad or a keyboard ! 42 | - Viewports : The Gui can seamlessly move out of your ofApp ! 43 | - Docking : Awesome layout engine to make your own workspaces ! 44 | - Tables : Display tables ! 45 | 46 | For more details on how to use them, please refer to the repo's readme and the examples' code. 47 | 48 | - - - - -------------------------------------------------------------------------------- /Configure.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | - - - - 4 | 5 | # Compilation options 6 | 7 | ofxImGui comes with quite a few compilation options which define how imgui is interfaced with OpenFrameworks. 8 | By setting them explicitly, you can enforce a specific way to meet your needs. 9 | 10 | An easy way to get started is to call the configuration assistant (see below) and interactively explore your options. 11 | 12 | 13 | ### GL context 14 | DearImGui needs to know your GL Context. ofxImGui tries to match your project's settings. 15 | If your projects needs to force a specific GL configuration, you can set some native imgui compilation flags to match your project settings : 16 | - `IMGUI_IMPL_OPENGL_ES2` --> Use GLES2 (or GL ES 1.1 with some hacks). 17 | - `IMGUI_IMPL_OPENGL_ES3` --> Use GLES3. 18 | - `[none of the previous ones]` --> Use OpenGL. 19 | 20 | ### Backend 21 | By default, ofxImGui uses the official ImGui GLFW backend when using `ofAppGLFWWindow`s. [More info](./PlatformSupport.md#backend-support-table). 22 | You may force to use the openframeworks backend by defining : 23 | - `OFXIMGUI_FORCE_OF_BACKEND` 24 | 25 | ### GLFW backend options 26 | You may also override some automatic macro defines (not recommended, there are drawbacks, but it might solve some very specific use cases): 27 | 28 | - `IMGUI_GLFW_INJECT_MULTICONTEXT_SUPPORT=0` to disable imgui_impl_glfw changes to support multiple context. 29 | Disables using ofxImGui within multiple `ofAppBaseWindow`s. 30 | - `INTERCEPT_GLFW_CALLBACKS=0` to use an alternative method to bind imgui to glfw events. 31 | - If `0`, ofxImGui doesn't add multi-context event routing, disabling multi-window-ofApp support. 32 | Event propagation: `GLFW -> ImGui -> OpenFrameworks`. 33 | - If `1` (default), ofxImGui binds to GLFW, allowing to route events to the correct context instances. 34 | Event propagation: `GLFW -> ofxImGui -> (ImGui + OpenFrameworks)`. 35 | 36 | ### Configuration assistant 37 | To have an insight on how your ofxImGui interfaces ImGui, you can call `gui.drawOfxImGuiDebugWindow();` together with `OFXIMGUI_DEBUG`. It contains an assistant that provides an explanation of your current configuration. It also provides some suggestions for gradually improving your configuration (to get the most out of OF+ImGui). 38 | 39 | - - - - 40 | 41 | # Update GLFW 42 | 43 | If you use the GLFW backend (enabled by default), the [GLFW version that ships with oF or your distro](./PlatformSupport.md#Glfw-version) is probably not too recent. In order to enable more native mouse cursors, and possibly other interface polishings, you can update GLFW within your oF installation. 44 | 45 | #### On Windows and MacOs 46 | **Warning**: BigSur and above used to break glfw-updates, probably the reason why OF didn't ship with more recent versions. Proceed with caution ! 47 | ````bash 48 | # Instructions for Mac/Win 49 | cd OF/scripts 50 | # Only if you don't have apothecary (OF release zip): 51 | git clone https://github.com/openframeworks/apothecary.git 52 | # Manually edit the GLFW formula `apothecary/apothecary/apothecary/formulas/glfw.sh`, change to : 53 | # - `VER=3.3-stable` (for gfwf 3.3.x) 54 | # - `VER=master` (for gfwf 3.4.x, recommended) 55 | # - `GIT_URL=https://github.com/glfw/glfw.git` 56 | # Manually delete `apothecary/apothecary/build/glfw if it exists 57 | # Update (change osx by vs/msys2/linux/linux64/linuxarmv6l/linuxarmv7l or remove `-t osx` for autoselect) 58 | ./apothecary/apothecary/apothecary -t osx -j 4 update glfw 59 | # Copy ./apothecary/glfw to OF/libs/ 60 | ./apothecary/apothecary/apothecary -t osx -j 4 copy glfw 61 | # Recompile oF (github installs only, not releases) 62 | # cd ./osx && ./compileOF.sh -j3 63 | ```` 64 | 65 | #### On Linux 66 | ````bash 67 | # Instructions for rpi distros and Linux desktops 68 | # Raspbian <= Buster don't have GLFW 3.3 in their repos, but you can try. 69 | apt update && apt upgrade libglfw3 libglfw3-dev 70 | # Show your current version 71 | apt-cache show libglfw3-dev 72 | ```` 73 | _This should also enable gamepad support on RPI with Raspbian <= Buster which ships with GLFW <= 3.2.1._ 74 | _Raspbian Note : Packages are known to be a little outdated, the easiest way is to upgrade your distro to the latest version. At the time of OF_v0.11.0, Raspbian shipped with GLFW 3.2 for example._ 75 | 76 | #### After the update 77 | Modify ofxImGui: [revert `3310` to `3300`](https://github.com/ocornut/imgui/blob/dd4ca70b0d612038edadcf37bf601c0f21206d28/backends/imgui_impl_glfw.cpp#L62) to tell imgui to use more precise cursors. 78 | 79 | - - - - 80 | 81 | -------------------------------------------------------------------------------- /Examples.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | Here's an overview of the bundled examples. 4 | 5 | ## example-demo 6 | Shows the imgui demo window, very useful for **discovering all the available widgets** and their respective ImGui API code to reproduce. 7 | 8 | ## example-simple 9 | A very **minimal example** of how to use imgui within OpenFrameworks. 10 | 11 | ## example-advanced 12 | Shows advanced use of imgui within oF, below are some covered topics : 13 | - oF sepcific image loading. 14 | - How to create helper functions (simple Dear ImGui addon). 15 | - How to use a Dear ImGui addon. 16 | - How to relate ImGui and oF coordinate systems. 17 | - It also lets you view the ImGui metrics window, useful for seeing how ImGui is interfaced with oF, it's current inner state and global inspector for debugging purposes. 18 | 19 | ## example-fonts 20 | Load custom fonts and fontawesome into ofxImGui. 21 | 22 | ## example-helpers 23 | ofxImGui helper functions for interfacing with `ofParameter`. Useful for transitioning from ofxGui. 24 | 25 | ## example-ios 26 | iOS specific with keyboard input helper. 27 | 28 | ## example-sharedcontext 29 | When several projects use ofxImGui (*an addon and your ofApp, for example*), you need to share the ofxImGui context. See also [ofxImGui integration within ofxAddons](./Developers.md#ofximgui-integration-within-ofxaddons) 30 | 31 | ## example-multiwindow 32 | How to use one ImGui instance in a multiwindow ofApp. Some bugs remain, implementation to be finished. 33 | 34 | ## example-imguizmo 35 | To be used together with [ofxImGuizmo](https://github.com/nariakiiwatani/ofxImGuizmo.git), an ofxImGui addon. 36 | -------------------------------------------------------------------------------- /PlatformSupport.md: -------------------------------------------------------------------------------- 1 | # Platform Support 2 | 3 | - - - - 4 | 5 | # Platform Compatibility 6 | ofxImGui both implements a custom oF backend (similar to Jvcleave's original implementation) and a "native imgui backend". The custom oF backend is a very simple integration of basic ImGui functionality. It's very well integrated within OF but doesn't feature lots of advanced imgui features. On the opposite, the native GLFW backend provides all ImGui features but has to intercept the Glfw callbacks set by OpenFrameworks then forward them again. 7 | 8 | For both backends, MacOs, Windows and Linux have been tested, but some more specific platforms remain to be tested; if you do so, please report back your findings. 9 | 10 | *Notes on Rpi support: Some combinations of Rpi and oF versions won't provide all GLSL versions. Anyways, it's recommended to use the full KMS driver rather then the Legacy Broadcom one (very low FPS), but they both work. Tested with Raspbian Stretch. Also, if you start your application with a minimal desktop environment (using `startx ./bin/ofApp`), the imgui viewport features do not work correctly.* 11 | 12 | - - - - 13 | 14 | # Backend support table 15 | 16 | By default, ofxImGui uses the GLFW engine when possible, which gives the best user experience, falling back to the OpenFrameworks backend which is supported on most ofApp setups but provides slightly less ImGui functionality. You can force ofxImGui to use the OpenFrameworks one by defining `OFXIMGUI_FORCE_OF_BACKEND`. 17 | 18 | One tiny disadvantage of the Glfw backend is that multiwindow-together-with-viewports support might break on ImGui updates. There are automatic update scripts, but they might not work in the future. Without the custom modifications, it will work fine but you'll have to choose between multiwindow or viewports, knowing that you can configure ImGui to never merge viewport windows with the host window. 19 | 20 | | ofxImGui backend | Viewports | Custom mouse cursors | Docking | Gamepads| GL SL | GL ES | Vulkan | Multiple ofxAppWindows | Automatic Contexts | 21 | |-----------------------|-----------|----------------------|---------|---------|-------|-------|--------|------------------------|--------------------| 22 | | EngineGLFW | [x] | [x]* | [x] | [x] | [x] | [x] | Maybe | [x]^ | [x]! | 23 | | EngineOpenFrameworks | [ ] | [ ] | [x] | [ ] | [x] | [x] | Maybe | [x]^ | [x]! | 24 | 25 | - __*__ Partial support, by default not all cursors are enabled, see [Updating GLFW](./Developpers.md#Improve-ofxImGui-s-backend-bindings). 26 | - __^__ One Context per ofAppWindow (isolated mode): No inter-communication between the GUIs (cross-docking won't work). 27 | (_EngineGLFW backend is slightly modified for supporting multiple glfw contexts_) 28 | Hopefully DearImGui will introduce something to handle «[multiple host viewports](https://github.com/ocornut/imgui/issues/3012)». 29 | Please note that using **ofxImGui in multiwindow OpenFrameworks applications** works, but keep in mind that this might break with future ImGui updates. 30 | - __!__ A singleton class ensures ensures the creation of the ImGui Context within openFrameworks. If multiple source files setup ofxImGui, the first sets up normally (as a master), the following ones as slaves, both still being able to draw to the same gui context. This can be useful when using ofxImGui from multiple ofxAddons. 31 | 32 | - - - - 33 | 34 | # GLSL support table 35 | 36 | | OS | OpenGL 2.x | OpenGL 3.x | OpenGL 4.x | GL ES 1.0 | GL ES 2 | GL ES 3 | 37 | |---------|---------------|---------------|---------------|----------------|---------------|---------------| 38 | | Windows | Yes | Yes | Yes | Unknown | Unknown | Unknown | 39 | | Mac OsX | Yes | Yes | Yes | *Unavailable* | *Unavailable* | *Unavailable* | 40 | | Linux | Yes | Yes | Yes | Yes | Yes | Should | 41 | | Rpi3 | Should | Unknown | Unknown | Yes | Yes | Yes | 42 | | Rpi4 | Unknown | Should | Should | Should | Should | Should | 43 | | iOS | *Unavailable* | *Unavailable* | *Unavailable* | Should | Should | Should | 44 | 45 | *Note: This support table does not take into account software emulated support for graphics APIs.* 46 | *Note: GL ES 1 (the fixed pipeline ES shading language) is not natively supported by the native DearImGui backend, but it works with [some dirty hacks](src/gles1CompatibilityHacks.h).* 47 | 48 | - - - - 49 | 50 | # oF & ImGui support table 51 | 52 | New ImGui versions bring changes and new API features, sometimes depreciations. 53 | Versions are tagged in the git repo. 54 | 55 | | ofxImGui version | ImGui version | Tested oF version | 56 | |------------------:|---------------|-------------------| 57 | | ofxImGui 1.91.0 | 1.91.0* | 0.11 -> 0.12.0 | 58 | | ofxImGui 1.90.0 | 1.90.0* | 0.11 -> 0.12.0 | 59 | | ofxImGui 1.89.2 | 1.89.2* | 0.11 -> 0.11.2 | 60 | | ofxImGui 1.82 | 1.82* | 0.11 -> 0.11.2 | 61 | | ofxImGui 1.79 | 1.79* | 0.11.1 | 62 | | ofxImGui 1.75 | 1.75 | 0.11.x | 63 | | ofxImGui 1.62 | 1.62 | 0.10.x | 64 | | ofxImGui 1.50 | 1.50 WIP | 0.10.x | 65 | | ofxImGui 1.49 | 1.49 | 0.10.x | 66 | | ofxImGui 1.47 | 1.47 | 0.10.x | 67 | | ofxImGui 0.90 | 1.45 WIP | 0.9.x | 68 | 69 | __*__ Uses the native ImGui backend, offering pop-out-windows (viewports), docking, gamepad control, and more. 70 | 71 | - - - - 72 | 73 | # GLFW version 74 | 75 | The GLFW backend is bound to the GLFW version provided by Openframeworks, which is mostly an old version and even contains some issues related to an embedded pre-release version. Except on Linux where GLFW is not embedded within OpenFrameworks and it depends on your distro. 76 | 77 | If you use the GLFW version embedded by OpenFrameworks, the biggest drawback is that not all cursors are available, making the GUI a little less intuitive. 78 | Also, the viewport user experience is way better with an updated GLFW. 79 | On OSX, updating GLFW will also show the (cached) window content while resizing your ofAppWindows, which is quite a nice improvement. 80 | 81 | *These support tables are an indication and might be incomplete.* 82 | 83 | | Openframeworks | GLFW | Source | 84 | |----------------|--------------|--------| 85 | | 0.11.0 | pre-3.3.0 | [Link](https://github.com/openframeworks/apothecary/blob/14c55b173c4110f05668089617b5a28ab7d110ce/apothecary/formulas/glfw.sh) | 86 | | 0.11.1 | 3.3.0-stable | [Link](https://github.com/openframeworks/apothecary/commit/68a0ec866341a8487d5c555311f3d5975bd62436) | 87 | | 0.11.2 | pre-3.3.0 | [Link](https://github.com/openframeworks/apothecary/pull/197) | 88 | | 0.11.2_master | 3.3.7 | [Link](https://github.com/openframeworks/apothecary/pull/225) | 89 | | 0.12.0 | 3.3.8 | [Link](https://github.com/openframeworks/apothecary/commit/bdc421bd28e8b433747759154f29a206d7cc9e41) | 90 | | 0.12.x | 3.4 | [Link](https://github.com/openframeworks/apothecary/commit/27b80288fc0e83ebad475b9ee94d042319bf0e3c) | 91 | 92 | ImGui restrictions by GLFW version. [Source](https://github.com/ocornut/imgui/blob/v1.91.0-docking/backends/imgui_impl_glfw.cpp#L118-L145). 93 | 94 | | **GLFW** | **Missing ImGui Features** | 95 | |-----------|------------------------------| 96 | | 3.1 | Keyboard input bugs, no window focusing, no window ordering + all below | 97 | | 3.2 | Uses old gamepad API + all below | 98 | | pre-3.3.0 | No resizing cursors, no deny cursor, window hovered, window alpha, multi-monitor-dpi + all below | 99 | | 3.3.0 | No monitor workarea, no mouse pass-trough + all below | 100 | | 3.3.8 | None | 101 | | 3.4 | None | 102 | 103 | oF 0.12.0 now bundles GLFW 3.3.8 which is OK with latest ImGui, but you can always update it to 3.4. 104 | See [Configure.md](./Configure#update-glfw) for updating GLFW. 105 | 106 | -------------------------------------------------------------------------------- /addon_config.mk: -------------------------------------------------------------------------------- 1 | # All variables and this file are optional, if they are not present the PG and the 2 | # makefiles will try to parse the correct values from the file system. 3 | # 4 | # Variables that specify exclusions can use % as a wildcard to specify that anything in 5 | # that position will match. A partial path can also be specified to, for example, exclude 6 | # a whole folder from the parsed paths from the file system 7 | # 8 | # Variables can be specified using = or += 9 | # = will clear the contents of that variable both specified from the file or the ones parsed 10 | # from the file system 11 | # += will add the values to the previous ones in the file or the ones parsed from the file 12 | # system 13 | # 14 | # The PG can be used to detect errors in this file, just create a new project with this addon 15 | # and the PG will write to the console the kind of error and in which line it is 16 | 17 | meta: 18 | ADDON_NAME = ofxImGui 19 | ADDON_DESCRIPTION = use ImGui inside openFrameworks 20 | ADDON_AUTHOR = Jason Van Cleave, Constantine Tarasenkov 21 | ADDON_TAGS = "gui" 22 | ADDON_URL = https://github.com/jvcleave/ofxImGui 23 | 24 | common: 25 | # dependencies with other addons, a list of them separated by spaces 26 | # or use += in several lines 27 | # ADDON_DEPENDENCIES = 28 | 29 | # include search paths, this will be usually parsed from the file system 30 | # but if the addon or addon libraries need special search paths they can be 31 | # specified here separated by spaces or one per line using += 32 | # ADDON_INCLUDES = 33 | 34 | # any special flag that should be passed to the compiler when using this 35 | # addon 36 | 37 | # Automatically enable ofxImGui features within other ofxAddons 38 | ADDON_CFLAGS = -DofxAddons_ENABLE_IMGUI 39 | 40 | # any special flag that should be passed to the linker when using this 41 | # addon, also used for system libraries with -lname 42 | # ADDON_LDFLAGS = 43 | 44 | # linux only, any library that should be included in the project using 45 | # pkg-config 46 | # ADDON_PKG_CONFIG_LIBRARIES = 47 | 48 | # osx/iOS only, any framework that should be included in the project 49 | # ADDON_FRAMEWORKS = 50 | 51 | # source files, these will be usually parsed from the file system looking 52 | # in the src folders in libs and the root of the addon. if your addon needs 53 | # to include files in different places or a different set of files per platform 54 | # they can be specified here 55 | # ADDON_SOURCES = 56 | ADDON_SOURCES_EXCLUDE = src/EngineVk.cpp 57 | 58 | # some addons need resources to be copied to the bin/data folder of the project 59 | # specify here any files that need to be copied, you can use wildcards like * and ? 60 | # ADDON_DATA = 61 | 62 | # when parsing the file system looking for libraries exclude this for all or 63 | # a specific platform 64 | # ADDON_LIBS_EXCLUDE = 65 | 66 | linux64: 67 | 68 | linux: 69 | 70 | linuxarmv6l: 71 | #ADDON_CFLAGS += -DOFXIMGUI_DEBUG 72 | ADDON_CFLAGS += -DIMGUI_IMPL_OPENGL_ES2 73 | #ADDON_CFLAGS += -DIMGUI_IMPL_OPENGL_ES3 74 | #ADDON_CFLAGS += -DUSE_PI_LEGACY 75 | #ADDON_LDFLAGS += -lGL 76 | 77 | 78 | linuxarmv7l: 79 | #ADDON_CFLAGS += -DOFXIMGUI_DEBUG 80 | ADDON_CFLAGS += -DIMGUI_IMPL_OPENGL_ES2 81 | #ADDON_CFLAGS += -DIMGUI_IMPL_OPENGL_ES3 82 | #ADDON_CFLAGS += -DUSE_PI_LEGACY 83 | 84 | msys2: 85 | 86 | android/armeabi: 87 | 88 | android/armeabi-v7a: 89 | 90 | ios: 91 | # osx/iOS only, any framework that should be included in the project 92 | ADDON_CFLAGS += -DIMGUI_IMPL_OPENGL_ES2 93 | # ADDON_SOURCES_EXCLUDE += libs/imgui/backends/imgui_impl_opengl2.cpp 94 | # ADDON_SOURCES_EXCLUDE += libs/imgui/backends/imgui_impl_opengl2.h 95 | # ADDON_SOURCES_EXCLUDE += libs/imgui/backends/imgui_impl_opengl3.cpp 96 | # ADDON_SOURCES_EXCLUDE += libs/imgui/backends/imgui_impl_opengl3.h 97 | ADDON_SOURCES_EXCLUDE += libs/imgui/backends/imgui_impl_glfw.cpp 98 | ADDON_SOURCES_EXCLUDE += libs/imgui/backends/imgui_impl_glfw.h 99 | ADDON_SOURCES_EXCLUDE += src/EngineGLFW.cpp 100 | ADDON_SOURCES_EXCLUDE += src/EngineGLFW.h 101 | -------------------------------------------------------------------------------- /example-ImGuizmo/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | ofxImGuizmo 3 | -------------------------------------------------------------------------------- /example-ImGuizmo/error.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/example-ImGuizmo/error.PNG -------------------------------------------------------------------------------- /example-ImGuizmo/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | 4 | //======================================================================== 5 | int main( ){ 6 | ofSetupOpenGL(1024,768,OF_WINDOW); // <-------- setup the GL context 7 | 8 | // this kicks off the running of my app 9 | // can be OF_WINDOW or OF_FULLSCREEN 10 | // pass in width and height too: 11 | ofRunApp(new ofApp()); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /example-ImGuizmo/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | #include 3 | 4 | 5 | //-------------------------------------------------------------- 6 | void ofApp::setup(){ 7 | gui_.setup(); 8 | cam_.setPosition({0,0,100}); 9 | cam_.lookAt({0,0,0}); 10 | } 11 | 12 | //-------------------------------------------------------------- 13 | void ofApp::update(){ 14 | 15 | } 16 | 17 | //-------------------------------------------------------------- 18 | void ofApp::draw(){ 19 | // Draw Cam 20 | cam_.begin(); 21 | node_.draw(); 22 | cam_.end(); 23 | 24 | // Start Gui 25 | gui_.begin(); 26 | 27 | // Instructions 28 | ImGui::SeparatorText("Instructions"); 29 | ImGui::TextWrapped("Press any of these keys to modify the guizmo."); 30 | ImGui::BulletText("W - Translate"); 31 | ImGui::BulletText("E - Scale"); 32 | ImGui::BulletText("R - Rotate"); 33 | ImGui::BulletText("Space - Toggle World/Local"); 34 | 35 | // ImGuizmo 36 | ImGuizmo::BeginFrame(); 37 | auto mat = node_.getGlobalTransformMatrix(); 38 | if(ImGuizmo::Manipulate(cam_, mat, op_, mode_)) { 39 | glm::mat4 transformation; 40 | glm::vec3 scale; 41 | glm::quat rotation; 42 | glm::vec3 translation; 43 | glm::vec3 skew; 44 | glm::vec4 perspective; 45 | glm::decompose(mat, scale, rotation, translation, skew, perspective); 46 | node_.setPosition(translation); 47 | node_.setScale(scale); 48 | node_.setOrientation(rotation); 49 | } 50 | 51 | // End gui 52 | gui_.end(); 53 | } 54 | 55 | //-------------------------------------------------------------- 56 | void ofApp::keyPressed(int key){ 57 | switch(key) { 58 | case 'w': op_ = ImGuizmo::TRANSLATE; break; 59 | case 'e': op_ = ImGuizmo::SCALE; break; 60 | case 'r': op_ = ImGuizmo::ROTATE; break; 61 | case ' ': mode_ = mode_==ImGuizmo::LOCAL?ImGuizmo::WORLD:ImGuizmo::LOCAL; break; 62 | } 63 | } 64 | 65 | //-------------------------------------------------------------- 66 | void ofApp::keyReleased(int key){ 67 | 68 | } 69 | 70 | //-------------------------------------------------------------- 71 | void ofApp::mouseMoved(int x, int y ){ 72 | 73 | } 74 | 75 | //-------------------------------------------------------------- 76 | void ofApp::mouseDragged(int x, int y, int button){ 77 | 78 | } 79 | 80 | //-------------------------------------------------------------- 81 | void ofApp::mousePressed(int x, int y, int button){ 82 | 83 | } 84 | 85 | //-------------------------------------------------------------- 86 | void ofApp::mouseReleased(int x, int y, int button){ 87 | 88 | } 89 | 90 | //-------------------------------------------------------------- 91 | void ofApp::mouseEntered(int x, int y){ 92 | 93 | } 94 | 95 | //-------------------------------------------------------------- 96 | void ofApp::mouseExited(int x, int y){ 97 | 98 | } 99 | 100 | //-------------------------------------------------------------- 101 | void ofApp::windowResized(int w, int h){ 102 | 103 | } 104 | 105 | //-------------------------------------------------------------- 106 | void ofApp::gotMessage(ofMessage msg){ 107 | 108 | } 109 | 110 | //-------------------------------------------------------------- 111 | void ofApp::dragEvent(ofDragInfo dragInfo){ 112 | 113 | } 114 | -------------------------------------------------------------------------------- /example-ImGuizmo/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | 5 | #define IMGUI_DEFINE_MATH_OPERATORS // Access to math operators 6 | #include "imgui_internal.h" 7 | 8 | #include "ofxImGui.h" 9 | #include "ofxImGuizmo.h" 10 | 11 | class ofApp : public ofBaseApp{ 12 | 13 | public: 14 | void setup(); 15 | void update(); 16 | void draw(); 17 | 18 | void keyPressed(int key); 19 | void keyReleased(int key); 20 | void mouseMoved(int x, int y ); 21 | void mouseDragged(int x, int y, int button); 22 | void mousePressed(int x, int y, int button); 23 | void mouseReleased(int x, int y, int button); 24 | void mouseEntered(int x, int y); 25 | void mouseExited(int x, int y); 26 | void windowResized(int w, int h); 27 | void dragEvent(ofDragInfo dragInfo); 28 | void gotMessage(ofMessage msg); 29 | private: 30 | ofCamera cam_; 31 | ImGuizmo::OPERATION op_; 32 | ImGuizmo::MODE mode_; 33 | ofNode node_; 34 | ofxImGui::Gui gui_; 35 | }; 36 | -------------------------------------------------------------------------------- /example-advanced/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | -------------------------------------------------------------------------------- /example-advanced/bin/data/of.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/example-advanced/bin/data/of.png -------------------------------------------------------------------------------- /example-advanced/bin/data/of_upside_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/example-advanced/bin/data/of_upside_down.png -------------------------------------------------------------------------------- /example-advanced/src/RandomTheme.cpp: -------------------------------------------------------------------------------- 1 | #include "RandomTheme.h" 2 | 3 | ofColor getRandomColor() 4 | { 5 | return ofColor(ofRandom(0, 255), ofRandom(0, 255), ofRandom(0, 255), 255); 6 | } 7 | 8 | void RandomTheme::setup() 9 | { 10 | ImGuiStyle* style = &ImGui::GetStyle(); 11 | 12 | style->WindowMinSize = ImVec2(160, 65); 13 | style->FramePadding = ImVec2(4, 2); 14 | style->ItemSpacing = ImVec2(6, 2); 15 | style->ItemInnerSpacing = ImVec2(6, 4); 16 | style->Alpha = 1.0f; 17 | style->WindowRounding = 0.0f; 18 | style->FrameRounding = 0.0f; 19 | style->IndentSpacing = 6.0f; 20 | style->ItemInnerSpacing = ImVec2(2, 4); 21 | style->ColumnsMinSpacing = 50.0f; 22 | style->GrabMinSize = 14.0f; 23 | style->GrabRounding = 0.0f; 24 | style->ScrollbarSize = 12.0f; 25 | style->ScrollbarRounding = 0.0f; 26 | 27 | style->Colors[ImGuiCol_Text] = ImVec4(getRandomColor(), 1.00f); 28 | style->Colors[ImGuiCol_TextDisabled] = ImVec4(getRandomColor(), 0.58f); 29 | style->Colors[ImGuiCol_WindowBg] = ImVec4(getRandomColor(), 0.70f); 30 | style->Colors[ImGuiCol_ChildBg] = ImVec4(getRandomColor(), 0.58f); 31 | style->Colors[ImGuiCol_Border] = ImVec4(getRandomColor(), 0.00f); 32 | style->Colors[ImGuiCol_BorderShadow] = ImVec4(getRandomColor(), 0.00f); 33 | style->Colors[ImGuiCol_FrameBg] = ImVec4(getRandomColor(), 1.00f); 34 | style->Colors[ImGuiCol_FrameBgHovered] = ImVec4(getRandomColor(), 0.78f); 35 | style->Colors[ImGuiCol_FrameBgActive] = ImVec4(getRandomColor(), 1.00f); 36 | style->Colors[ImGuiCol_TitleBg] = ImVec4(getRandomColor(), 1.00f); 37 | style->Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(getRandomColor(), 0.75f); 38 | style->Colors[ImGuiCol_TitleBgActive] = ImVec4(getRandomColor(), 1.00f); 39 | style->Colors[ImGuiCol_MenuBarBg] = ImVec4(getRandomColor(), 0.47f); 40 | style->Colors[ImGuiCol_ScrollbarBg] = ImVec4(getRandomColor(), 1.00f); 41 | style->Colors[ImGuiCol_ScrollbarGrab] = ImVec4(getRandomColor(), 0.21f); 42 | style->Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(getRandomColor(), 0.78f); 43 | style->Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(getRandomColor(), 1.00f); 44 | style->Colors[ImGuiCol_CheckMark] = ImVec4(getRandomColor(), 0.80f); 45 | style->Colors[ImGuiCol_SliderGrab] = ImVec4(getRandomColor(), 0.14f); 46 | style->Colors[ImGuiCol_SliderGrabActive] = ImVec4(getRandomColor(), 1.00f); 47 | style->Colors[ImGuiCol_Button] = ImVec4(getRandomColor(), 0.14f); 48 | style->Colors[ImGuiCol_ButtonHovered] = ImVec4(getRandomColor(), 0.86f); 49 | style->Colors[ImGuiCol_ButtonActive] = ImVec4(getRandomColor(), 1.00f); 50 | style->Colors[ImGuiCol_Header] = ImVec4(getRandomColor(), 0.76f); 51 | style->Colors[ImGuiCol_HeaderHovered] = ImVec4(getRandomColor(), 0.86f); 52 | style->Colors[ImGuiCol_HeaderActive] = ImVec4(getRandomColor(), 1.00f); 53 | style->Colors[ImGuiCol_Separator] = ImVec4(getRandomColor(), 0.32f); 54 | style->Colors[ImGuiCol_SeparatorHovered] = ImVec4(getRandomColor(), 0.78f); 55 | style->Colors[ImGuiCol_SeparatorActive] = ImVec4(getRandomColor(), 1.00f); 56 | style->Colors[ImGuiCol_ResizeGrip] = ImVec4(getRandomColor(), 0.04f); 57 | style->Colors[ImGuiCol_ResizeGripHovered] = ImVec4(getRandomColor(), 0.78f); 58 | style->Colors[ImGuiCol_ResizeGripActive] = ImVec4(getRandomColor(), 1.00f); 59 | style->Colors[ImGuiCol_PlotLines] = ImVec4(getRandomColor(), 0.63f); 60 | style->Colors[ImGuiCol_PlotLinesHovered] = ImVec4(getRandomColor(), 1.00f); 61 | style->Colors[ImGuiCol_PlotHistogram] = ImVec4(getRandomColor(), 0.63f); 62 | style->Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(getRandomColor(), 1.00f); 63 | style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(getRandomColor(), 0.43f); 64 | style->Colors[ImGuiCol_PopupBg] = ImVec4(getRandomColor(), 0.92f); 65 | style->Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(getRandomColor(), 0.73f); 66 | } 67 | -------------------------------------------------------------------------------- /example-advanced/src/RandomTheme.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "BaseTheme.h" 4 | #include "ofMain.h" 5 | 6 | class RandomTheme: public ofxImGui::BaseTheme 7 | { 8 | public: 9 | 10 | void setup() override; 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /example-advanced/src/fx.inl: -------------------------------------------------------------------------------- 1 | // Copyright 2020 - Daan de Lange 2 | #define g using 3 | g C=int;C f=10;g A=ImVec2;g B=float;bool E=1;B G;B U=IM_PI*2;B H=0;B R(A S){C X=S.x+S.y*57;X=(X<<13)^X;return .5+.5*(1.-((X*((X*X*15731)+789221)+1376312589)&0x7fffffff)/1073741824.);}B V(B Y,B Z,B X){B W=ImClamp((X-Y)/(Z-Y),0,1);return W*W*(3-2*W);}C I(A S){return C(ImMin(S.x,320-1)/f)+C(ImMin(S.y,180-1)/f)*(320/f);}A K[50];B Q[576];void FX(ImDrawList*F,A D,A,A b,ImVec4,B T){B J=0;if(E)G=(H+1337e-8*(intptr_t)&E);for(C M=0;M<576;++M){A c=A(fmodf(M,320/f),M/(320/f));if(E){B X=R(ImFloor(c)+A(G*f,0));Q[M]=(X<.5?1:(X>.7?0:2))+(H>T-1)*1-fmodf(T+M,2.1);}C d,e=d=0;if(Q[M]<=1){e=255-20*V(-1,0,fmodf(Q[M],1));d=e*V(1,0,Q[M]);}A S=D+c*f;F->AddRectFilled(S,S+A(f,10),IM_COL32(d,e,d,255));J+=Q[M]*(Q[M]>0&&Q[M]<=1);}for(C L=0;L<50;++L){if(E)K[L]=A(R(A(T,L)),R(A(L,T)))*b;A S=K[L];B O=(R(ImFloor(S/f)*f+A(L,L))+(C(T*.17))+T*.27*(L%2?1:-1))*U;C a=I(S);B&N=Q[a];N-=.2*(N<=1);A P(cos(O),sin(O));K[L]=ImClamp(K[L]+P*(Q[I(S+P*4)]<=1),A(0,0),b);F->AddCircleFilled(D+S,4,0xFF003acc);}if(H 24 | #define IMGUI_DEFINE_MATH_OPERATORS // Access to math operators 25 | #include "imgui_internal.h" 26 | #include "imgui.h" 27 | 28 | // Function signature: 29 | // void FX(ImDrawList* d, ImVec2 a, ImVec2 b, ImVec2 sz, ImVec4 mouse, float t); 30 | // d : draw list 31 | // a : upper-left corner 32 | // b : lower-right corner 33 | // sz : size (== b - a) 34 | // mouse : x,y = mouse position (normalized so 0,0 over 'a'; 1,1 is over 'b', not clamped) 35 | // z,w = left/right button held. <-1.0f not pressed, 0.0f just pressed, >0.0f time held. 36 | // t : time 37 | // If not using a given parameter, you can omit its name in your function to save a few characters. 38 | 39 | // Insert your code in fx.inl 40 | // This is the file which size we are measuring, and should be kept <1024 bytes 41 | #include "fx.inl" 42 | 43 | // Shared testbed 44 | void FxTestBed(bool* _pOpen=nullptr) 45 | { 46 | ImGuiIO& io = ImGui::GetIO(); 47 | ImGui::Begin("FX", _pOpen, ImGuiWindowFlags_AlwaysAutoResize); 48 | ImVec2 size(320.0f, 180.0f); 49 | ImGui::InvisibleButton("canvas", size); 50 | ImVec2 p0 = ImGui::GetItemRectMin(); 51 | ImVec2 p1 = ImGui::GetItemRectMax(); 52 | ImDrawList* draw_list = ImGui::GetWindowDrawList(); 53 | draw_list->PushClipRect(p0, p1); 54 | 55 | ImVec4 mouse_data; 56 | mouse_data.x = (io.MousePos.x - p0.x) / size.x; 57 | mouse_data.y = (io.MousePos.y - p0.y) / size.y; 58 | mouse_data.z = io.MouseDownDuration[0]; 59 | mouse_data.w = io.MouseDownDuration[1]; 60 | 61 | FX(draw_list, p0, p1, size, mouse_data, (float)ImGui::GetTime()); 62 | draw_list->PopClipRect(); 63 | ImGui::End(); 64 | } 65 | 66 | //----------------------------------------------------------------------------- 67 | -------------------------------------------------------------------------------- /example-advanced/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | #include "ofAppGLFWWindow.h" 4 | 5 | //======================================================================== 6 | int main( ){ 7 | 8 | #if defined( TARGET_OPENGLES ) || defined ( FORCE_GLES ) 9 | ofGLESWindowSettings settings; 10 | #if defined(TARGET_RASPBERRY_PI) 11 | settings.setGLESVersion(2); 12 | #else 13 | settings.setGLESVersion(3); 14 | #endif 15 | 16 | #else 17 | ofGLWindowSettings settings; 18 | #if defined(TARGET_OSX) 19 | settings.setGLVersion(3,2); 20 | #else 21 | settings.setGLVersion(4,1); 22 | #endif 23 | #endif 24 | 25 | settings.title="ofxImGui Example Advanced"; 26 | 27 | auto window1 = ofCreateWindow(settings); 28 | auto app1 = std::make_shared(); 29 | 30 | ofRunApp(window1, app1); 31 | ofRunMainLoop(); 32 | } 33 | -------------------------------------------------------------------------------- /example-advanced/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | -------------------------------------------------------------------------------- /example-debug/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | -------------------------------------------------------------------------------- /example-debug/src/imgui_windows_info.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | //#include "ofxImGui.h" 5 | #include "imgui.h" 6 | #include "imgui_internal.h" 7 | 8 | // Simple extension to query imgui windows, which requires access to imgui_internals 9 | namespace ImGuiEx { 10 | 11 | struct WindowInformation { 12 | WindowInformation(char* _name, ImVec2 _pos, ImVec2 _size) : name(_name), x(_pos.x), y(_pos.y), width(_size.x), height(_size.y){ 13 | 14 | } 15 | std::string name; 16 | int x; 17 | int y; 18 | int width; 19 | int height; 20 | }; 21 | 22 | // Returns a list of active windows 23 | static std::vector getWindowsInformation() { 24 | ImGuiContext& g = *GImGui; 25 | 26 | std::vector ret; 27 | 28 | // Iterate front to back 29 | for (int i = g.Windows.Size - 1; i >= 0; i--){ 30 | const ImGuiWindow* w = g.Windows[i]; 31 | 32 | // ignore inactive windows 33 | if(!w->WasActive) continue; 34 | 35 | ret.push_back( WindowInformation(w->Name, w->Pos, w->Size) ); 36 | } 37 | return ret; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example-debug/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | //#include "ofAppGLFWWindow.h" 4 | 5 | // Uncomment to force GLES for testing 6 | //#define FORCE_GLES 7 | 8 | // Uncomment to force FIXED pipeline for testing 9 | #define FORCE_FIXED_GL 10 | 11 | //======================================================================== 12 | int main( ){ 13 | ofSetLogLevel(OF_LOG_VERBOSE); 14 | 15 | int windowWidth = 900; 16 | int windowHeight = 900; 17 | 18 | #if defined( TARGET_OPENGLES ) || defined ( FORCE_GLES ) 19 | ofGLESWindowSettings settings; 20 | #ifdef FORCE_FIXED_GL 21 | settings.setGLESVersion(1); 22 | #else 23 | #if defined(TARGET_RASPBERRY_PI) 24 | settings.setGLESVersion(2); 25 | #else 26 | settings.setGLESVersion(3); 27 | #endif 28 | #endif 29 | #else 30 | ofGLWindowSettings settings; 31 | #ifdef FORCE_FIXED_GL 32 | settings.setGLVersion(2,1); 33 | #else 34 | #if defined(TARGET_OSX) 35 | settings.setGLVersion(3,2); 36 | #else 37 | settings.setGLVersion(4,1); 38 | #endif 39 | #endif 40 | #endif 41 | 42 | settings.title="ofxImGui Example Debug"; 43 | settings.setSize(windowWidth, windowHeight); 44 | 45 | auto window1 = ofCreateWindow(settings); 46 | auto app1 = std::make_shared(); 47 | 48 | ofRunApp(window1, app1); 49 | ofRunMainLoop(); 50 | } 51 | -------------------------------------------------------------------------------- /example-debug/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | -------------------------------------------------------------------------------- /example-demo/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | -------------------------------------------------------------------------------- /example-demo/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | 4 | int main(){ 5 | #if defined( TARGET_OPENGLES ) || defined ( FORCE_GLES ) 6 | ofGLESWindowSettings settings; 7 | #if defined(TARGET_RASPBERRY_PI) 8 | settings.setGLESVersion(2); 9 | #else 10 | settings.setGLESVersion(3); 11 | #endif 12 | 13 | #else 14 | ofGLWindowSettings settings; 15 | #if defined(TARGET_OSX) 16 | settings.setGLVersion(3,2); 17 | #else 18 | settings.setGLVersion(4,1); 19 | #endif 20 | #endif 21 | settings.setSize(1280, 720); 22 | ofCreateWindow(settings); 23 | 24 | ofRunApp( new ofApp()); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /example-demo/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | 3 | //-------------------------------------------------------------- 4 | void ofApp::setup() 5 | { 6 | ofSetLogLevel(OF_LOG_VERBOSE); 7 | 8 | //required call 9 | gui.setup(nullptr, true, ImGuiConfigFlags_ViewportsEnable ); 10 | 11 | //backgroundColor is stored as an ImVec4 type but can handle ofColor 12 | backgroundColor = ofColor(114, 144, 154); 13 | 14 | } 15 | 16 | //-------------------------------------------------------------- 17 | void ofApp::update(){ 18 | 19 | 20 | 21 | 22 | } 23 | //-------------------------------------------------------------- 24 | void ofApp::draw(){ 25 | 26 | //required to call this at beginning 27 | gui.begin(); 28 | 29 | // Show the ImGui test window. Most of the sample code is in ImGui::ShowDemoWindow() 30 | ImGui::SetNextWindowPos( ofVec2f( ofGetWindowPositionX(), ofGetWindowPositionY()), ImGuiCond_Once); 31 | ImGui::SetNextWindowSize( ofVec2f(ofGetWidth(), ofGetHeight()), ImGuiCond_Once); 32 | ImGui::ShowDemoWindow(); 33 | 34 | //required to call this at end 35 | gui.end(); 36 | 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /example-demo/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | #include "ofxImGui.h" 5 | 6 | class ofApp : public ofBaseApp{ 7 | public: 8 | void setup(); 9 | void update(); 10 | void draw(); 11 | 12 | ofxImGui::Gui gui; 13 | ImVec4 backgroundColor; 14 | }; 15 | -------------------------------------------------------------------------------- /example-dockingandviewports/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | -------------------------------------------------------------------------------- /example-dockingandviewports/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | #include "ofAppGLFWWindow.h" 4 | 5 | //======================================================================== 6 | int main( ){ 7 | #if defined( TARGET_OPENGLES ) || defined ( FORCE_GLES ) 8 | ofGLESWindowSettings settings; 9 | #if defined(TARGET_RASPBERRY_PI) 10 | settings.setGLESVersion(2); 11 | #else 12 | settings.setGLESVersion(3); 13 | #endif 14 | 15 | #else 16 | ofGLWindowSettings settings; 17 | #if defined(TARGET_OSX) 18 | settings.setGLVersion(3,2); 19 | #else 20 | settings.setGLVersion(4,1); 21 | #endif 22 | #endif 23 | settings.title="ofxImGui Example : Docking and Viewports"; 24 | 25 | auto window1 = ofCreateWindow(settings); 26 | auto app1 = std::make_shared(); 27 | 28 | ofRunApp(window1, app1); 29 | ofRunMainLoop(); 30 | } 31 | -------------------------------------------------------------------------------- /example-dockingandviewports/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | -------------------------------------------------------------------------------- /example-dockingandviewports/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | #include "ofxImGui.h" 5 | #include "imgui_internal.h" // <-- example uses some imgui internals... 6 | 7 | class ofApp : public ofBaseApp{ 8 | 9 | public: 10 | ofApp() {} 11 | 12 | void setup() { 13 | // Setup imgui with the appropriate config flags 14 | gui.setup(nullptr, false, ImGuiConfigFlags_DockingEnable | ImGuiConfigFlags_ViewportsEnable, true); 15 | 16 | // Uncomment below to perform docking with SHIFT key 17 | // Gives a better user experience, matter of opinion. 18 | //ImGui::GetIO().ConfigDockingWithShift=true; 19 | 20 | // Uncomment below to "force" all imgui windows to be standalone 21 | //ImGui::GetIO().ConfigViewportsNoAutoMerge=true; 22 | 23 | ofSetBackgroundAuto(false); 24 | ofEnableAlphaBlending(); 25 | } 26 | 27 | void draw() { 28 | // erase the bg progressively to reveal which ImGui window are within the OF window 29 | ofPushStyle(); 30 | ofEnableBlendMode(OF_BLENDMODE_SUBTRACT); 31 | ofFill(); 32 | ofSetColor(200, 200, 200, 2); 33 | ofSetRectMode(OF_RECTMODE_CENTER); 34 | ofDrawRectangle(ofGetWidth()*.5f, ofGetHeight()*.5f, ofGetWidth()+20, ofGetHeight()+20); 35 | ofSetRectMode(OF_RECTMODE_CORNER); 36 | ofPopStyle(); 37 | 38 | ofPushStyle(); 39 | // Example info text 40 | ofDrawBitmapStringHighlight( 41 | "Docking windows lets you easily re-arrange your window space.\n"\ 42 | "Start dragging a window and drop it on a dockable zone !\n\n"\ 43 | 44 | "Viewports : When you drag a window out of the oF window,\n"\ 45 | "it seamlessly leaves the oF window context to become standalone.\n"\ 46 | "if you see onion skins while dragging the window, it's in the same window as oF.", 47 | 100, 40 48 | ); 49 | ofPopStyle(); 50 | 51 | // If you need to know the gui viewport, checkout this helper 52 | // Note: For testing purposes demonstrated before the GUI starts, because this is accessible from anywhere. 53 | ofSetColor(ofColor::green, 5); 54 | ofFill(); 55 | ofRectangle vp = gui.getMainWindowViewportRect(); 56 | static const int cSize=10; 57 | ofDrawCircle(glm::vec2(vp.getTopLeft()), cSize); 58 | ofDrawCircle(glm::vec2(vp.getBottomLeft()), cSize); 59 | ofDrawCircle(glm::vec2(vp.getTopRight()), cSize); 60 | ofDrawCircle(glm::vec2(vp.getBottomRight()), cSize); 61 | 62 | // Start drawing to ImGui (newFrame) 63 | gui.begin(); 64 | 65 | // Make windows transparent, to demonstrate drawing behind them. 66 | ImGui::PushStyleColor(ImGuiCol_WindowBg , IM_COL32(200,200,200,128)); // This styles the docked windows 67 | 68 | ImGuiDockNodeFlags dockingFlags = ImGuiDockNodeFlags_PassthruCentralNode; // Make the docking space transparent 69 | // Fixes imgui to expected behaviour, having a transparent central node in passthru mode. 70 | // Alternative: Otherwise add in ImGui::DockSpace() [±line 14505] : if (flags & ImGuiDockNodeFlags_PassthruCentralNode) window_flags |= ImGuiWindowFlags_NoBackground; 71 | ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0,0,0,0)); 72 | 73 | //dockingFlags |= ImGuiDockNodeFlags_NoDockingInCentralNode; // Uncomment to always keep an empty "central node" (a visible oF space) 74 | //dockingFlags |= ImGuiDockNodeFlags_NoTabBar; // Uncomment to disable creating tabs in the main view 75 | 76 | // Define the ofWindow as a docking space 77 | // Also draws the docked windows at this stage. 78 | ImGuiID dockNodeID = ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(), dockingFlags); 79 | ImGui::PopStyleColor(2); 80 | 81 | // Show how to query the imgui docking layout and draw some stuff with it 82 | // Advanced use, you probably wouldn't need this. 83 | ImGuiDockNode* dockNode = ImGui::DockBuilderGetNode(dockNodeID); 84 | if(dockNode){ 85 | ImGuiDockNode* centralNode = ImGui::DockBuilderGetCentralNode(dockNodeID); 86 | // Verifies if the central node is empty (visible empty space for oF) 87 | if( centralNode && centralNode->IsEmpty() ){ 88 | ImRect availableSpace = centralNode->Rect(); 89 | //availableSpace.Max = availableSpace.Min + ImGui::GetContentRegionAvail(); 90 | 91 | // Submit a red rectangle using the ImGui draw api. 92 | // It will be drawn at the same stage as the other Gui elements, by order of submission. 93 | ImGui::GetForegroundDrawList()->AddRect(availableSpace.GetTL()+ImVec2(8,8), availableSpace.GetBR()-ImVec2(8,8), IM_COL32(255,50,50,255)); 94 | 95 | ImVec2 viewCenter = availableSpace.GetCenter(); 96 | // Depending on the viewports flag, the XY is either absolute or relative to the oF window. 97 | if(ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable ) viewCenter = viewCenter - ImVec2(ofGetWindowPositionX(),ofGetWindowPositionY()); 98 | 99 | // These drawings will be submitted immediately by the renderer pipeline. 100 | // So they will be behind the GUI, submitted on `gui.draw()` 101 | ofPushStyle(); 102 | ofSetRectMode(OF_RECTMODE_CENTER); 103 | ofSetColor(255,0,0,2); 104 | ofNoFill(); 105 | 106 | ofDrawRectangle( 107 | viewCenter.x, 108 | viewCenter.y, 109 | availableSpace.GetSize().x-6, 110 | availableSpace.GetSize().y-6 111 | ); 112 | ofNoFill(); 113 | ofSetColor(255,255,255,30); 114 | ofDrawRectangle( 115 | (viewCenter.x), 116 | (viewCenter.y), 117 | (availableSpace.GetSize().x-20)*fmodf(abs(sin(ofGetElapsedTimef())),1.f), 118 | (availableSpace.GetSize().y-20)*fmodf(abs(sin(ofGetElapsedTimef())),1.f) 119 | ); 120 | ofSetRectMode(OF_RECTMODE_CORNER); 121 | ofPopStyle(); 122 | } 123 | } 124 | 125 | // Draw a few windows 126 | static int val0=0, val1=0,val2=0,val3=0,val4=0,val5=0; 127 | drawWindow("Dockable Window", val0, 50, 100, ImGuiWindowFlags_None ); 128 | drawWindow("Window 1", val1, 300, 100, ImGuiWindowFlags_None ); 129 | drawWindow("Window 2", val2, 50, 350, ImGuiWindowFlags_None ); 130 | drawWindow("Window 3", val3, 300, 350, ImGuiWindowFlags_None ); 131 | drawWindow("Window 4", val4, 550, 100, ImGuiWindowFlags_None ); 132 | ImGui::SetNextWindowViewport(ImGui::GetMainViewport()->ID); // Attach a window to a viewport = prevent popping it out 133 | drawWindow("Stuck in main window", val5, 550, 350, ImGuiWindowFlags_None ); 134 | 135 | // End our ImGui Frame. Also Renders in autoDraw mode. 136 | gui.end(); 137 | 138 | gui.draw(); // <-- In manual mode, you can choose to render imgui at a given moment in your pipeline 139 | 140 | // Show FPS 141 | ofDrawBitmapStringHighlight( ofToString(ofGetFrameRate() ), 10, 50, ofColor(0,60), ofColor(255,128)); // <-- This text will be drawn over the layout 142 | 143 | if(!dockNode || !ImGui::DockBuilderGetCentralNode(dockNodeID) || !ImGui::DockBuilderGetCentralNode(dockNodeID)->IsEmpty()){ 144 | static int posX=1, posY=1, velX=1, velY=1; 145 | ofDrawBitmapStringHighlight("No empty dock space, nowhere to draw for oF !", posX, posY); 146 | posX+=velX*3; 147 | posY+=velY*3; 148 | ofBitmapFont f; 149 | ofRectangle strSize = f.getBoundingBox("No empty dock space, nowhere to draw for oF !",posX,posY); 150 | if(posX <= 0) velX=1; 151 | if(posY <= strSize.height) velY=1; 152 | if(posX >= ofGetWidth()-strSize.width) velX=-1; 153 | if(posY >= ofGetHeight()) velY=-1; 154 | } 155 | } 156 | 157 | private: 158 | 159 | void drawWindow(const char* _title, int& _value, int _x=300, int _y=300, ImGuiWindowFlags _flags=ImGuiWindowFlags_None ){ 160 | ImGui::SetNextWindowSize(ImVec2(200,200), ImGuiCond_Once); 161 | ImGui::SetNextWindowPos(ImVec2(_x+ofGetWindowPositionX(),_y+ofGetWindowPositionY()), ImGuiCond_Once); 162 | ImGui::Begin(_title, NULL, _flags ); 163 | 164 | ImGui::InputInt("InputInt", &_value); 165 | ImGui::SliderInt("SliderInt", &_value, 0, 10); 166 | ImGui::DragInt("DragInt", &_value); 167 | ImGui::End(); 168 | } 169 | 170 | ofxImGui::Gui gui; 171 | }; 172 | -------------------------------------------------------------------------------- /example-fonts/ProggyTiny-License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004, 2005 Tristan Grimmer 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /example-fonts/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | -------------------------------------------------------------------------------- /example-fonts/bin/data/Roboto-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/example-fonts/bin/data/Roboto-Medium.ttf -------------------------------------------------------------------------------- /example-fonts/bin/data/fa-regular-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/example-fonts/bin/data/fa-regular-400.ttf -------------------------------------------------------------------------------- /example-fonts/bin/data/fa-regular-400.ttf-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Font Awesome Free License 2 | ------------------------- 3 | 4 | Font Awesome Free is free, open source, and GPL friendly. You can use it for 5 | commercial projects, open source projects, or really almost whatever you want. 6 | Full Font Awesome Free license: https://fontawesome.com/license/free. 7 | 8 | # Icons: CC BY 4.0 License (https://creativecommons.org/licenses/by/4.0/) 9 | In the Font Awesome Free download, the CC BY 4.0 license applies to all icons 10 | packaged as SVG and JS file types. 11 | 12 | # Fonts: SIL OFL 1.1 License (https://scripts.sil.org/OFL) 13 | In the Font Awesome Free download, the SIL OFL license applies to all icons 14 | packaged as web and desktop font files. 15 | 16 | # Code: MIT License (https://opensource.org/licenses/MIT) 17 | In the Font Awesome Free download, the MIT license applies to all non-font and 18 | non-icon files. 19 | 20 | # Attribution 21 | Attribution is required by MIT, SIL OFL, and CC BY licenses. Downloaded Font 22 | Awesome Free files already contain embedded comments with sufficient 23 | attribution, so you shouldn't need to do anything additional when using these 24 | files normally. 25 | 26 | We've kept attribution comments terse, so we ask that you do not actively work 27 | to remove them from files, especially code. They're a great way for folks to 28 | learn about Font Awesome. 29 | 30 | # Brand Icons 31 | All brand icons are trademarks of their respective owners. The use of these 32 | trademarks does not indicate endorsement of the trademark holder by Font 33 | Awesome, nor vice versa. **Please do not use brand logos for any purpose except 34 | to represent the company, product, or service to which they refer.** 35 | -------------------------------------------------------------------------------- /example-fonts/example-fonts.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | import qbs.Process 3 | import qbs.File 4 | import qbs.FileInfo 5 | import qbs.TextFile 6 | import "../../../libs/openFrameworksCompiled/project/qtcreator/ofApp.qbs" as ofApp 7 | 8 | Project{ 9 | property string of_root: "../../.." 10 | 11 | ofApp { 12 | name: { return FileInfo.baseName(sourceDirectory) } 13 | cpp.minimumMacosVersion: '10.15' 14 | cpp.cxxLanguageVersion: 'c++17' 15 | 16 | files: [ 17 | 'src/main.cpp', 18 | 'src/ofApp.cpp', 19 | 'src/*.h' 20 | ] 21 | 22 | of.addons: [ 23 | 'ofxImGui', 24 | ] 25 | 26 | // additional flags for the project. the of module sets some 27 | // flags by default to add the core libraries, search paths... 28 | // this flags can be augmented through the following properties: 29 | of.pkgConfigs: [] // list of additional system pkgs to include 30 | of.includePaths: [] // include search paths 31 | of.cFlags: [] // flags passed to the c compiler 32 | of.cxxFlags: [] // flags passed to the c++ compiler 33 | of.linkerFlags: [] // flags passed to the linker 34 | of.defines: ['OFXIMGUI_DEBUG'] // defines are passed as -D to the compiler 35 | // and can be checked with #ifdef or #if in the code 36 | of.frameworks: [] // osx only, additional frameworks to link with the project 37 | of.staticLibraries: [] // static libraries 38 | of.dynamicLibraries: [] // dynamic libraries 39 | 40 | // other flags can be set through the cpp module: http://doc.qt.io/qbs/cpp-module.html 41 | // eg: this will enable ccache when compiling 42 | // 43 | // cpp.compilerWrapper: 'ccache' 44 | 45 | Depends{ 46 | name: "cpp" 47 | } 48 | 49 | // common rules that parse the include search paths, core libraries... 50 | Depends{ 51 | name: "of" 52 | } 53 | 54 | // dependency with the OF library 55 | Depends{ 56 | name: "openFrameworks" 57 | } 58 | } 59 | 60 | property bool makeOF: true // use makfiles to compile the OF library 61 | // will compile OF only once for all your projects 62 | // otherwise compiled per project with qbs 63 | 64 | 65 | property bool precompileOfMain: false // precompile ofMain.h 66 | // faster to recompile when including ofMain.h 67 | // but might use a lot of space per project 68 | 69 | references: [FileInfo.joinPaths(of_root, "/libs/openFrameworksCompiled/project/qtcreator/openFrameworks.qbs")] 70 | } 71 | -------------------------------------------------------------------------------- /example-fonts/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | 4 | int main() 5 | { 6 | 7 | #if defined(TARGET_OPENGLES) 8 | ofGLESWindowSettings settings; 9 | settings.setGLESVersion(2); 10 | #else 11 | ofGLFWWindowSettings settings; 12 | settings.setGLVersion(3, 2); 13 | #endif 14 | settings.setPosition(ofVec2f(0, 0)); 15 | settings.setSize(600, 600); 16 | settings.title="ofxImGui font usage example"; 17 | ofCreateWindow(settings); 18 | 19 | ofRunApp( new ofApp()); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /example-fonts/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | 3 | #include "imgui_stdlib.h" // For string input widgets 4 | 5 | // Important ! 6 | // Be sure to include each font file only 1 time from a cpp file. (do not include from a header file) 7 | #include "IconsFontAwesome5.h" 8 | #include "ProggyTiny.cpp" 9 | 10 | // Fixme for c++20 : `u8"stringLiteral"` will not compile anymore. 11 | // Will become : `(const char*) u8"stringLiteral` 12 | 13 | //-------------------------------------------------------------- 14 | void ofApp::setup() 15 | { 16 | ofSetLogLevel(OF_LOG_VERBOSE); 17 | 18 | // The call to setup() is required BEFORE adding fonts. 19 | bool autoDraw = true; 20 | ofxImGui::BaseTheme* theme = nullptr; 21 | ImGuiConfigFlags customFlags = ImGuiConfigFlags_DockingEnable; 22 | bool restoreGuiState = false; 23 | bool showImGuiMouseCursor = false; 24 | gui.setup(theme, autoDraw, customFlags, restoreGuiState, showImGuiMouseCursor); 25 | 26 | // Add polish characters 27 | static const ImWchar polishCharRanges[] = 28 | { 29 | 0x0020, 0x00FF, // Basic Latin + Latin Supplement 30 | 0x0100, 0x01FF, // Polish characters 31 | 0, 32 | }; 33 | static const ImWchar* normalCharRanges = ImGui::GetIO().Fonts->GetGlyphRangesDefault(); 34 | static const ImWchar* myCharRanges = polishCharRanges; 35 | //myCharRanges = normalCharRanges; // Uncomment to disable polish characters 36 | 37 | // Set font and keep a reference of it for using it later 38 | // Font files are located within the data folder. 39 | // Note: Takes ownership. Use for reference only. ImGui handles font ownership (unless explicitly requested by the user) 40 | customFont = gui.addFont("Roboto-Medium.ttf", 16.f, nullptr, myCharRanges, false); 41 | 42 | // Add fontawesome fonts 43 | // Demonstrates merging additional characters into an existing font 44 | // (to prevent having to change the ImGui font when displaying additional characters) 45 | // Note: MergeMode adds the additional glyphs into the last used/loaded font : customFont. 46 | useBigFaIcons = true; // Enable to demonstrate making the font bigger (optional) 47 | ImFontConfig faConfig; 48 | faConfig.MergeMode = true; // Merge within the previously used ImFont 49 | faConfig.GlyphMinAdvanceX = 13.0f; // To make the icon monospaced (optional) 50 | float faHeight = faConfig.MergeMode ? 16.f : 20.f; // It's advised to use the same height in merge mode ! 51 | // Make the fonts bigger 52 | if(useBigFaIcons){ 53 | faHeight += 8; 54 | // In MergeMode, it's advised to use the same height as the original font 55 | // If enabled with a different height, we can use GlyphOffset.y to center the glyphs vertically. 56 | if(faConfig.MergeMode){ 57 | faConfig.GlyphOffset.y = 8/2; // Center icons vertically 58 | } 59 | } 60 | // Inject glyphs 61 | static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; 62 | gui.addFont(FONT_ICON_FILE_NAME_FAR, faHeight, &faConfig, icon_ranges); // FONT_ICON_FILE_NAME_FAR = "fa-regular-400.ttf" 63 | 64 | // You can also load fonts from memory, optionally compressed 65 | // It will compile the font within the binary, so you don't have to ship the font file separately. Increases binary size. 66 | // https://github.com/ocornut/imgui/blob/master/docs/FONTS.md#using-font-data-embedded-in-source-code 67 | // #include "MyCompressedFont.h" 68 | // gui.addFontFromMemory((void*)MyCompressedFont, sizeof(MyCompressedFont),16.f, nullptr, myCharRanges); 69 | 70 | // Here we directly interact with the ImGui fonts API instead of ofxImGui 71 | // (not recommended, but supports some more features such as compression) 72 | // Fonts from memory are hard-coded in the compiled binary using a C++ source file holding the data. 73 | auto& io = ImGui::GetIO(); 74 | proggyFont = io.Fonts->AddFontFromMemoryCompressedTTF(&ProggyTiny_compressed_data, ProggyTiny_compressed_size, 10); 75 | 76 | // After manipulating fonts via the ImGui API, you need to rebuild the font texture 77 | gui.rebuildFontsTexture(); 78 | 79 | // For more advanced font loading examples, please refer to 80 | // https://github.com/ocornut/imgui/blob/master/docs/FONTS.md 81 | } 82 | 83 | //-------------------------------------------------------------- 84 | void ofApp::update(){ 85 | 86 | 87 | 88 | 89 | } 90 | 91 | //-------------------------------------------------------------- 92 | void ofApp::draw(){ 93 | 94 | // Start imgui 95 | gui.begin(); 96 | 97 | ImGui::SetNextWindowPos(ImVec2(5,5), ImGuiCond_Once); 98 | ImGui::SetNextWindowSize(ImVec2(600-10,600-10), ImGuiCond_Once); 99 | ImGui::Begin("Font Examples"); 100 | 101 | ImGui::Spacing(); 102 | ImGui::CollapsingHeader("Default font", ImGuiTreeNodeFlags_Leaf); 103 | // Uses the default font 104 | ImGui::Text("Hello, world!"); 105 | ImGui::Spacing(); 106 | 107 | // Use 2ndary font 108 | ImGui::CollapsingHeader("Special characters", ImGuiTreeNodeFlags_Leaf); 109 | 110 | // u8 ensures text is encoded as utf8 from the cpp source code 111 | ImGui::Text(u8"Witaj świecie !"); 112 | ImGui::SameLine(); 113 | ImGui::TextColored(ImVec4(255,255,255,0.5), "<-- one character is not loaded in this font !"); 114 | 115 | // Custom font has more caracters, allowing to render them all 116 | ImGui::PushFont(customFont); 117 | ImGui::Text(u8"Witaj świecie !"); 118 | ImGui::SameLine(); 119 | ImGui::TextColored(ImVec4(255,255,255,0.5), "<-- with another font, it's rendered correctly !"); 120 | ImGui::Text(u8"Some polish characters: ć, ń, ó, ś, ź, ż, ą, ę, ł."); 121 | ImGui::PopFont(); 122 | ImGui::Dummy(ImVec2(0,10)); 123 | 124 | // Fontawesome 125 | ImGui::CollapsingHeader("Fontawesome icons", ImGuiTreeNodeFlags_Leaf); 126 | ImGui::PushFont(customFont); 127 | ImGui::Text("FontAweome is loaded too ! %s", ICON_FA_THUMBS_UP); 128 | ImGui::TextWrapped("The glyphs are merged into another one, allowing mix text and " ICON_FA_IMAGES " without changing font."); 129 | ImGui::Button( ICON_FA_TRASH_ALT " Trash it !"); 130 | ImGui::SameLine(); 131 | ImGui::Button( ICON_FA_ANGRY " Mad button !"); 132 | ImGui::SameLine(); 133 | ImGui::Button( ICON_FA_BELL " Ring it !"); 134 | ImGui::PopFont(); 135 | if(useBigFaIcons){ 136 | ImGui::TextDisabled("Icons are loaded bigger on purpose."); 137 | } 138 | ImGui::TextDisabled("Note: the embedded icon set is NOT complete."); 139 | ImGui::Dummy(ImVec2(0,10)); 140 | 141 | // ProggyTiny font 142 | ImGui::PushFont(proggyFont); 143 | ImGui::CollapsingHeader("ProggyTiny font", ImGuiTreeNodeFlags_Leaf); 144 | ImGui::Text("This text is rendered with ProggyTiny."); 145 | ImGui::Text("The font has been loaded from the program binary."); 146 | ImGui::PopFont(); 147 | ImGui::Dummy(ImVec2(0,10)); 148 | 149 | // Here we test if the string literal is passed correctly, helps debugging 150 | ImGui::CollapsingHeader("ImGui character debugger helper", ImGuiTreeNodeFlags_Leaf); 151 | ImGui::TextDisabled("Helps debugging incorrectly rendered characters."); 152 | if(ImGui::TreeNode("Static string literal")){ 153 | ImGui::DebugTextEncoding("Witaj świecie !"); // incorrect on some platforms (for demo) 154 | //ImGui::DebugTextEncoding(u8"Witaj świecie !"); // correct 155 | ImGui::TreePop(); 156 | } 157 | if(ImGui::TreeNode("Dynamic text")){ 158 | static std::string customString = "0-éàî-°C"; 159 | ImGui::InputText("Custom string", &customString); 160 | ImGui::DebugTextEncoding(customString.c_str()); 161 | ImGui::TreePop(); 162 | } 163 | ImGui::Dummy(ImVec2(0,10)); 164 | 165 | // Default font 166 | ImGui::CollapsingHeader("Default font", ImGuiTreeNodeFlags_Leaf); 167 | ImGuiIO& io = ImGui::GetIO(); 168 | // Refer to imgui_internal GetDefaultFont() 169 | ImGui::Text("Default font: %s", io.FontDefault==nullptr?"[None]":io.FontDefault->GetDebugName()); 170 | if(io.FontDefault==nullptr){ 171 | ImGui::SameLine(); 172 | ImGui::TextDisabled(" (uses first font)"); 173 | } 174 | ImGui::Dummy(ImVec2(0,10)); 175 | 176 | // More 177 | ImGui::SeparatorText("More"); 178 | ImGui::TextWrapped("For more advanced font loading examples, please refer to : "); 179 | ImGui::Text("https://github.com/ocornut/imgui/blob/master/docs/FONTS.md"); 180 | ImGui::Dummy(ImVec2(0,10)); 181 | 182 | // Show imgui font viewer / debugger 183 | ImGui::Dummy(ImVec2(0,10)); 184 | ImGui::CollapsingHeader("ImGui Font Debugger", ImGuiTreeNodeFlags_Leaf); 185 | //ImGui::ShowFontSelector("Default font"); 186 | ImGui::ShowStyleEditor(); 187 | 188 | ImGui::End(); // close window 189 | 190 | // End imgui 191 | gui.end(); 192 | 193 | } 194 | 195 | //-------------------------------------------------------------- 196 | void ofApp::keyPressed(int key){ 197 | 198 | } 199 | 200 | //-------------------------------------------------------------- 201 | void ofApp::keyReleased(int key){ 202 | 203 | } 204 | 205 | 206 | void ofApp::mouseScrolled(int x, int y, float scrollX, float scrollY) 207 | { 208 | 209 | } 210 | //-------------------------------------------------------------- 211 | void ofApp::mouseMoved(int x, int y){ 212 | 213 | } 214 | 215 | //-------------------------------------------------------------- 216 | void ofApp::mouseDragged(int x, int y, int button){ 217 | 218 | } 219 | 220 | //-------------------------------------------------------------- 221 | void ofApp::mousePressed(int x, int y, int button){ 222 | 223 | } 224 | 225 | //-------------------------------------------------------------- 226 | void ofApp::mouseReleased(int x, int y, int button){ 227 | 228 | } 229 | 230 | //-------------------------------------------------------------- 231 | void ofApp::windowResized(int w, int h){ 232 | 233 | } 234 | 235 | //-------------------------------------------------------------- 236 | void ofApp::gotMessage(ofMessage msg){ 237 | 238 | } 239 | 240 | //-------------------------------------------------------------- 241 | void ofApp::dragEvent(ofDragInfo dragInfo){ 242 | 243 | } 244 | -------------------------------------------------------------------------------- /example-fonts/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | #include "ofxImGui.h" 5 | #include "IconsFontAwesome5.h" 6 | 7 | class ofApp : public ofBaseApp{ 8 | public: 9 | void setup(); 10 | void update(); 11 | void draw(); 12 | 13 | void keyPressed(int key); 14 | void keyReleased(int key); 15 | void mouseMoved(int x, int y); 16 | void mouseDragged(int x, int y, int button); 17 | void mousePressed(int x, int y, int button); 18 | void mouseReleased(int x, int y, int button); 19 | void windowResized(int w, int h); 20 | void dragEvent(ofDragInfo dragInfo); 21 | void gotMessage(ofMessage msg); 22 | void mouseScrolled(int x, int y, float scrollX, float scrollY); 23 | 24 | ofxImGui::Gui gui; 25 | ImFont* customFont = nullptr; 26 | ImFont* proggyFont = nullptr; 27 | bool useBigFaIcons = false; 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /example-helpers/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | -------------------------------------------------------------------------------- /example-helpers/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | #include "ofAppGLFWWindow.h" 4 | 5 | //======================================================================== 6 | int main() { 7 | ofSetLogLevel(OF_LOG_VERBOSE); 8 | 9 | int windowWidth = 800; 10 | int windowHeight = 600; 11 | 12 | #if defined( TARGET_OPENGLES ) || defined ( FORCE_GLES ) 13 | ofGLESWindowSettings settings; 14 | #if defined(TARGET_RASPBERRY_PI) 15 | settings.setGLESVersion(2); 16 | #else 17 | settings.setGLESVersion(3); 18 | #endif 19 | 20 | #else 21 | ofGLWindowSettings settings; 22 | #if defined(TARGET_OSX) 23 | settings.setGLVersion(3, 2); 24 | #else 25 | settings.setGLVersion(3, 2); 26 | // settings.setGLVersion(4,1); // Uncomment if your GPU supports it 27 | #endif 28 | #endif 29 | settings.title = "ofxImGui example-helpers"; 30 | settings.setSize(windowWidth, windowHeight); 31 | 32 | auto window1 = ofCreateWindow(settings); 33 | auto app1 = std::make_shared(); 34 | 35 | ofRunApp(window1, app1); 36 | ofRunMainLoop(); 37 | } 38 | -------------------------------------------------------------------------------- /example-helpers/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | #include 3 | #include 4 | #include 5 | 6 | // Uncomment to switch between 2 modes 7 | //#define GLOBAL_ARB_TEX 8 | 9 | //-------------------------------------------------------------- 10 | void ofApp::setup() 11 | { 12 | ofSetLogLevel(OF_LOG_NOTICE); 13 | ofSetBackgroundAuto(false); 14 | ofSetVerticalSync(true); 15 | ofSetFrameRate(60); 16 | 17 | this->stepper = 0.0f; 18 | 19 | // FBO 20 | #ifdef GLOBAL_ARB_TEX 21 | // Option 1 : Set all textures to GL_TEXTURE_2D in setup (recommended) 22 | ofDisableArbTex(); 23 | fbo.allocate(200,200,GL_RGBA); 24 | #else 25 | // Option 2 : Specify the texture target explicitly (when you can't set yourall ofApp textures to GL_TEXTURE_2D 26 | ofFbo::Settings fboSettings ; 27 | fboSettings.width = 200; 28 | fboSettings.height = 200; 29 | fboSettings.internalformat = GL_RGBA ; 30 | fboSettings.textureTarget = GL_TEXTURE_2D; 31 | fbo.allocate(fboSettings); 32 | #endif 33 | fbo.checkStatus(); 34 | fbo.begin(); 35 | ofClear(0,0); 36 | ofSetColor(10,200,10); 37 | ofFill(); 38 | ofDrawCircle(100,100, 90); 39 | fbo.end(); 40 | 41 | // Gui 42 | gui.setup(nullptr, true, ImGuiConfigFlags_None, true); 43 | this->guiVisible = true; 44 | } 45 | 46 | //-------------------------------------------------------------- 47 | void ofApp::update() 48 | { 49 | this->stepper += this->speed; 50 | cubeSize = ofMap(sinf(this->stepper), -1.0f, 1.0f, this->sizeMin, this->sizeMax); 51 | } 52 | 53 | //-------------------------------------------------------------- 54 | void ofApp::draw() 55 | { 56 | // We have to use ofParameter::get() since this we are using an ofFloatColor. 57 | ofClear(this->background.get()); 58 | 59 | this->camera.begin(); 60 | { 61 | ofEnableDepthTest(); 62 | 63 | ofSetColor(ofColor::white); 64 | 65 | if (this->enabled) 66 | { 67 | ofPushStyle(); 68 | { 69 | // We have to use ofParameter::get() since this we are using an ofFloatColor. 70 | ofSetColor(this->foreground.get()); 71 | 72 | auto fillRender = static_cast(this->fillMode.get()); 73 | if (fillRender != RenderMode::None) 74 | { 75 | ofFill(); 76 | if (fillRender == RenderMode::Texture && this->texture.isAllocated()) 77 | { 78 | this->texture.bind(); 79 | } 80 | ofDrawBox(this->cubeSize); 81 | if (fillRender == RenderMode::Texture && this->texture.isAllocated()) 82 | { 83 | this->texture.unbind(); 84 | } 85 | } 86 | 87 | auto strokeRender = static_cast(this->strokeMode.get()); 88 | if (strokeRender != RenderMode::None) 89 | { 90 | ofNoFill(); 91 | if (strokeRender == RenderMode::Texture && this->texture.isAllocated()) 92 | { 93 | this->texture.bind(); 94 | } 95 | ofDrawBox(this->cubeSize); 96 | if (strokeRender == RenderMode::Texture && this->texture.isAllocated()) 97 | { 98 | this->texture.unbind(); 99 | } 100 | } 101 | } 102 | ofPopStyle(); 103 | } 104 | 105 | ofDisableDepthTest(); 106 | } 107 | this->camera.end(); 108 | 109 | // Gui 110 | this->mouseOverGui = false; 111 | if (this->guiVisible) 112 | { 113 | this->mouseOverGui = this->imGui(); 114 | } 115 | if (this->mouseOverGui) 116 | { 117 | this->camera.disableMouseInput(); 118 | } 119 | else 120 | { 121 | this->camera.enableMouseInput(); 122 | } 123 | } 124 | 125 | //-------------------------------------------------------------- 126 | void ofApp::keyPressed(int key) { 127 | 128 | } 129 | 130 | //-------------------------------------------------------------- 131 | void ofApp::keyReleased(int key) { 132 | 133 | } 134 | 135 | //-------------------------------------------------------------- 136 | void ofApp::mouseMoved(int x, int y) { 137 | 138 | } 139 | 140 | //-------------------------------------------------------------- 141 | void ofApp::mouseDragged(int x, int y, int button) { 142 | 143 | } 144 | 145 | //-------------------------------------------------------------- 146 | void ofApp::mousePressed(int x, int y, int button) { 147 | 148 | } 149 | 150 | //-------------------------------------------------------------- 151 | void ofApp::mouseReleased(int x, int y, int button) { 152 | 153 | } 154 | 155 | //-------------------------------------------------------------- 156 | void ofApp::mouseEntered(int x, int y) { 157 | 158 | } 159 | 160 | //-------------------------------------------------------------- 161 | void ofApp::mouseExited(int x, int y) { 162 | 163 | } 164 | 165 | //-------------------------------------------------------------- 166 | void ofApp::windowResized(int w, int h) { 167 | 168 | } 169 | 170 | //-------------------------------------------------------------- 171 | void ofApp::gotMessage(ofMessage msg) { 172 | 173 | } 174 | 175 | //-------------------------------------------------------------- 176 | void ofApp::dragEvent(ofDragInfo dragInfo) { 177 | 178 | } 179 | 180 | //-------------------------------------------------------------- 181 | bool ofApp::loadImage(const string & filePath) 182 | { 183 | ofImage image; 184 | image.setUseTexture(false); 185 | if (!image.load(filePath)) 186 | { 187 | ofLogError(__FUNCTION__) << "No image found at " << filePath; 188 | return false; 189 | } 190 | 191 | ofTextureData texData; 192 | texData.width = image.getWidth(); 193 | texData.height = image.getHeight(); 194 | texData.textureTarget = GL_TEXTURE_2D; 195 | this->texture.allocate(texData); 196 | this->texture.loadData(image.getPixels()); 197 | //texData.bFlipTexture = true; 198 | 199 | this->imagePath = ofFilePath::makeRelative(ofToDataPath(""), filePath); 200 | return true; 201 | } 202 | 203 | //-------------------------------------------------------------- 204 | bool ofApp::imGui() 205 | { 206 | auto mainSettings = ofxImGui::Settings(); 207 | 208 | this->gui.begin(); 209 | { 210 | static bool bCollapse = false; 211 | if (ofxImGui::BeginWindow("Helpers", mainSettings, ImGuiWindowFlags_NoCollapse, &bCollapse)) 212 | { 213 | ImGui::Text("%.1f FPS (%.3f ms/frame)", ofGetFrameRate(), 1000.0f / ImGui::GetIO().Framerate); 214 | 215 | if (ofxImGui::BeginTree(this->colors, mainSettings)) 216 | { 217 | ofxImGui::AddParameter(this->background, false); 218 | ofxImGui::AddParameter(this->foreground); 219 | 220 | ofxImGui::EndTree(mainSettings); 221 | } 222 | 223 | if (ofxImGui::BeginTree(this->mesh, mainSettings)) 224 | { 225 | ofxImGui::AddParameter(this->enabled); 226 | ofxImGui::AddRange("Size Range", this->sizeMin, this->sizeMax, 1.0f); 227 | ofxImGui::AddParameter(this->speed); 228 | ImGui::Text("Size: %.2f", this->cubeSize); 229 | 230 | ofxImGui::EndTree(mainSettings); 231 | } 232 | 233 | if (ofxImGui::BeginTree(this->render, mainSettings)) 234 | { 235 | if (ImGui::Button("Load Image...")) 236 | { 237 | auto dialogResult = ofSystemLoadDialog("Load Image", false, ofToDataPath("")); 238 | if (dialogResult.bSuccess) 239 | { 240 | this->loadImage(dialogResult.filePath); 241 | } 242 | } 243 | 244 | static const std::vector labels = { "None", "Color", "Texture" }; 245 | 246 | ofxImGui::AddRadio(this->fillMode, labels, 3); 247 | ofxImGui::AddRadio(this->strokeMode, labels, 3); 248 | 249 | if (this->texture.isAllocated()) 250 | { 251 | ofxImGui::AddParameter(this->preview); 252 | } 253 | 254 | ofxImGui::EndTree(mainSettings); 255 | } 256 | 257 | // Some work has yet to be done on the Helpers. 258 | // For example, the line below causes a crash 259 | // ofxImGui::AddGroup(this->render, mainSettings); 260 | } 261 | ofxImGui::EndWindow(mainSettings); 262 | //ImGui::End(); 263 | 264 | // 2nd window 265 | auto altSettings = ofxImGui::Settings(); 266 | if (ofxImGui::BeginWindow("2nd Helpers", altSettings, ImGuiWindowFlags_NoCollapse, &bCollapse)) 267 | { 268 | ImGui::TextWrapped("%s", "The helper settings return information about the window state : the white box around this window shows how to use them.\n"\ 269 | "Also, when you reopen this application, window positions and sizes should restore to their last state before exiting." ); 270 | } 271 | ofxImGui::EndWindow(altSettings); 272 | 273 | // Draw a rectangle to check if the returned values are correct 274 | #define MY_MARGING 10 275 | ofPushStyle(); 276 | ofNoFill(); 277 | ofDrawRectRounded(altSettings.windowPos-ofVec2f(MY_MARGING,MY_MARGING), altSettings.windowSize.x+2*MY_MARGING, altSettings.windowSize.y+2*MY_MARGING, MY_MARGING); 278 | ofPopStyle(); 279 | 280 | if (this->preview) 281 | { 282 | static const float kPreviewSize = 256.0f; 283 | auto previewSettings = ofxImGui::Settings(); 284 | previewSettings.windowPos = ofVec2f(ofGetWidth() - kPreviewSize - kImGuiMargin * 3, kImGuiMargin); 285 | previewSettings.windowSize = ofVec2f(kPreviewSize, kPreviewSize); 286 | 287 | if (ofxImGui::BeginWindow(this->preview, previewSettings, false)) 288 | { 289 | ofxImGui::AddImage(this->texture, previewSettings.windowSize); 290 | } 291 | ofxImGui::EndWindow(previewSettings); 292 | } 293 | if(ImGui::Begin("ofFboTexture")){ 294 | glm::vec2 size = {fbo.getWidth(), fbo.getHeight()}; 295 | ofxImGui::AddImage(fbo, size); 296 | } 297 | ImGui::End(); 298 | } 299 | this->gui.end(); 300 | 301 | return mainSettings.mouseOverGui; 302 | } 303 | -------------------------------------------------------------------------------- /example-helpers/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | 5 | #include "ofxImGui.h" 6 | #include "ImHelpers.h" 7 | 8 | class ofApp 9 | : public ofBaseApp 10 | { 11 | public: 12 | void setup(); 13 | void update(); 14 | void draw(); 15 | 16 | void keyPressed(int key); 17 | void keyReleased(int key); 18 | void mouseMoved(int x, int y); 19 | void mouseDragged(int x, int y, int button); 20 | void mousePressed(int x, int y, int button); 21 | void mouseReleased(int x, int y, int button); 22 | void mouseEntered(int x, int y); 23 | void mouseExited(int x, int y); 24 | void windowResized(int w, int h); 25 | void dragEvent(ofDragInfo dragInfo); 26 | void gotMessage(ofMessage msg); 27 | 28 | protected: 29 | enum class RenderMode 30 | { 31 | None, 32 | Color, 33 | Texture 34 | }; 35 | 36 | // Camera 37 | ofEasyCam camera; 38 | 39 | // Mesh 40 | float stepper; 41 | float cubeSize; 42 | 43 | // Render 44 | bool loadImage(const string & filePath); 45 | 46 | ofTexture texture; 47 | 48 | // Gui 49 | bool imGui(); 50 | 51 | ofxImGui::Gui gui; 52 | bool guiVisible; 53 | bool mouseOverGui; 54 | 55 | // Parameters 56 | ofParameter background{ "Background", ofFloatColor::black }; 57 | ofParameter foreground{ "Foreground", ofColor::crimson }; 58 | ofParameterGroup colors{ "Colors", background, foreground }; 59 | 60 | ofParameter enabled{ "Enabled", true }; 61 | ofParameter sizeMin{ "Size Min", 10.0f, 0.0f, 1000.0f }; 62 | ofParameter sizeMax{ "Size Max", 200.0f, 0.0f, 1000.0f }; 63 | ofParameter speed{ "Speed", 0.1f, 0.0f, 1.0f }; 64 | ofParameterGroup mesh{ "Mesh", enabled, sizeMin, sizeMax, speed }; 65 | 66 | ofParameter fillMode{ "Fill Mode", static_cast(RenderMode::Texture) }; 67 | ofParameter strokeMode{ "Stroke Mode", static_cast(RenderMode::None) }; 68 | ofParameter preview{ "Preview", false }; 69 | ofParameter imagePath{ "Image Path", "texture.jpg" }; 70 | ofParameterGroup render{ "Render", fillMode, strokeMode, preview, imagePath }; 71 | 72 | ofFbo fbo; 73 | }; 74 | -------------------------------------------------------------------------------- /example-ios/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | ofxiOS -------------------------------------------------------------------------------- /example-ios/bin/data/of.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/example-ios/bin/data/of.png -------------------------------------------------------------------------------- /example-ios/bin/data/of_upside_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/example-ios/bin/data/of_upside_down.png -------------------------------------------------------------------------------- /example-ios/src/InputTextButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxiOSExtras.h" 4 | #include "ofxImGui.h" 5 | 6 | class InputTextButton; 7 | 8 | @interface TextFieldDelegate : NSObject 9 | { 10 | @public 11 | InputTextButton* inputTextButton; 12 | } 13 | - (void)textFieldEditingChanged:(id)sender; 14 | - (BOOL)textFieldShouldReturn:(UITextField *)textField; 15 | 16 | @end 17 | 18 | class InputTextButton 19 | { 20 | 21 | public: 22 | InputTextButton(); 23 | void setup(std::string initialString); 24 | void draw(); 25 | void onTextEdit(std::string); 26 | UITextField* textField; 27 | TextFieldDelegate* textFieldDelegate; 28 | std::string text; 29 | }; 30 | -------------------------------------------------------------------------------- /example-ios/src/InputTextButton.mm: -------------------------------------------------------------------------------- 1 | // 2 | // InputTextButton.m 3 | // ImGuiTest 4 | // 5 | // Created by Jason Van Cleave on 2/12/16. 6 | // 7 | // 8 | 9 | #include "InputTextButton.h" 10 | 11 | @implementation TextFieldDelegate 12 | 13 | - (void)textFieldEditingChanged:(id)sender 14 | { 15 | 16 | UITextField* textField = (UITextField *)sender; 17 | inputTextButton->onTextEdit([textField.text UTF8String]); 18 | } 19 | - (BOOL)textFieldShouldReturn:(UITextField *)textField { 20 | [textField resignFirstResponder]; 21 | return NO; 22 | } 23 | @end 24 | 25 | 26 | void InputTextButton::onTextEdit(std::string s) 27 | { 28 | text = [textField.text UTF8String]; 29 | if(text.empty()) 30 | { 31 | //text = [textField.placeholder UTF8String]; 32 | } 33 | } 34 | InputTextButton::InputTextButton() 35 | { 36 | textField = NULL; 37 | text = ""; 38 | textFieldDelegate = [[TextFieldDelegate alloc] init]; 39 | }; 40 | 41 | void InputTextButton::setup(std::string initialString) 42 | { 43 | text = initialString; 44 | 45 | textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 20)]; 46 | textField.text = [NSString stringWithUTF8String:text.c_str()]; 47 | textField.placeholder = textField.text; 48 | textField.hidden = YES; 49 | textField.delegate = textFieldDelegate; 50 | textFieldDelegate->inputTextButton = this; 51 | 52 | [textField addTarget:textFieldDelegate 53 | action:@selector(textFieldEditingChanged:) 54 | forControlEvents:UIControlEventEditingChanged]; 55 | 56 | 57 | [ofxiOSGetGLParentView() addSubview:textField]; 58 | 59 | } 60 | void InputTextButton::draw() 61 | { 62 | if(ImGui::Button(text.c_str())) 63 | { 64 | if(![textField isFirstResponder]) 65 | { 66 | [textField becomeFirstResponder]; 67 | } 68 | } 69 | textField.text = [NSString stringWithUTF8String:text.c_str()]; 70 | } 71 | 72 | -------------------------------------------------------------------------------- /example-ios/src/main.mm: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | 3 | int main() { 4 | 5 | // here are the most commonly used iOS window settings. 6 | //------------------------------------------------------ 7 | ofiOSWindowSettings settings; 8 | settings.enableRetina = true; // enables retina resolution if the device supports it. 9 | settings.enableDepth = false; // enables depth buffer for 3d drawing. 10 | settings.enableAntiAliasing = false; // enables anti-aliasing which smooths out graphics on the screen. 11 | settings.numOfAntiAliasingSamples = 0; // number of samples used for anti-aliasing. 12 | settings.enableHardwareOrientation = true; // enables native view orientation. 13 | settings.enableHardwareOrientationAnimation = false; // enables native orientation changes to be animated. 14 | settings.glesVersion = OFXIOS_RENDERER_ES2; // type of renderer to use, ES1, ES2, ES3 15 | settings.windowControllerType = GL_KIT; 16 | settings.windowMode = OF_FULLSCREEN; 17 | //settings.width = 1024; 18 | //settings.height = 768; 19 | settings.setSize(1024, 768); 20 | settings.setupOrientation = OF_ORIENTATION_90_LEFT; 21 | ofCreateWindow(settings); 22 | 23 | return ofRunApp(new ofApp); 24 | } 25 | -------------------------------------------------------------------------------- /example-ios/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxiOS.h" 4 | #include "ofxImGui.h" 5 | #include "InputTextButton.h" 6 | 7 | class ofApp : public ofxiOSApp { 8 | 9 | public: 10 | void setup(); 11 | void update(); 12 | void draw(); 13 | void exit(); 14 | 15 | void touchDown(ofTouchEventArgs & touch); 16 | void touchMoved(ofTouchEventArgs & touch); 17 | void touchUp(ofTouchEventArgs & touch); 18 | void touchDoubleTap(ofTouchEventArgs & touch); 19 | void touchCancelled(ofTouchEventArgs & touch); 20 | 21 | void lostFocus(); 22 | void gotFocus(); 23 | void gotMemoryWarning(); 24 | void deviceOrientationChanged(int newOrientation); 25 | 26 | ofxImGui::Gui gui; 27 | ImVec4 backgroundColor; 28 | bool show_test_window; 29 | bool show_another_window; 30 | 31 | float floatValue; 32 | ofImage imageButtonSource; 33 | GLuint imageButtonID; 34 | 35 | ofPixels pixelsButtonSource; 36 | GLuint pixelsButtonID; 37 | 38 | ofTexture textureSource; 39 | GLuint textureSourceID; 40 | 41 | InputTextButton inputTextButton; 42 | 43 | }; 44 | 45 | 46 | -------------------------------------------------------------------------------- /example-ios/src/ofApp.mm: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | 3 | //-------------------------------------------------------------- 4 | void ofApp::setup(){ 5 | 6 | ofSetLogLevel(OF_LOG_VERBOSE); 7 | ofLogVerbose() << ofGetWidth() << " x " << ofGetHeight(); 8 | //required call 9 | gui.setup(); 10 | 11 | ImGui::GetIO().MouseDrawCursor = false; 12 | //backgroundColor is stored as an ImVec4 type but can handle ofColor 13 | backgroundColor = ofColor(114, 144, 154); 14 | show_test_window = true; 15 | show_another_window = false; 16 | floatValue = 0.0f; 17 | //load your own ofImage 18 | imageButtonSource.load("of.png"); 19 | imageButtonID = gui.loadImage(imageButtonSource); 20 | 21 | //or have the loading done for you if you don't need the ofImage reference 22 | //imageButtonID = gui.loadImage("of.png"); 23 | 24 | //can also use ofPixels in same manner 25 | ofLoadImage(pixelsButtonSource, "of_upside_down.png"); 26 | pixelsButtonID = gui.loadPixels(pixelsButtonSource); 27 | 28 | //and alt method 29 | //pixelsButtonID = gui.loadPixels("of_upside_down.png"); 30 | 31 | //pass in your own texture reference if you want to keep it 32 | textureSourceID = gui.loadTexture(textureSource, "of_upside_down.png"); 33 | 34 | //or just pass a path 35 | //textureSourceID = gui.loadTexture("of_upside_down.png"); 36 | 37 | ofLogVerbose() << "textureSourceID: " << textureSourceID; 38 | ofAppiOSWindow* curWin = (ofAppiOSWindow*) ofGetCurrentWindow().get(); 39 | //ofGetCurrentRenderer() 40 | ofLogVerbose("RENDERER TYPE : ") << curWin->getGLESVersion() << " // " << curWin->getWindowControllerType() << " // " << ofGetCurrentRenderer()->getType()<< ofGetGLRenderer()->getGLVersionMajor() << ";" << ofGetGLRenderer()->getGLVersionMinor(); 41 | //auto renderer = (ofGLProgrammableRenderer)ofGetCurrentRenderer(); 42 | 43 | 44 | inputTextButton.setup("Editable Text Button"); 45 | } 46 | 47 | //-------------------------------------------------------------- 48 | void ofApp::update() 49 | { 50 | 51 | 52 | } 53 | 54 | 55 | //-------------------------------------------------------------- 56 | void ofApp::draw(){ 57 | //backgroundColor is stored as an ImVec4 type but is converted to ofColor automatically 58 | 59 | ofSetBackgroundColor(backgroundColor); 60 | 61 | //required to call this at beginning 62 | gui.begin(); 63 | 64 | //In between gui.begin() and gui.end() you can use ImGui as you would anywhere else 65 | 66 | // 1. Show a simple window 67 | { 68 | inputTextButton.draw(); 69 | 70 | ImGui::Text(inputTextButton.text.c_str()); 71 | ImGui::SliderFloat("Float", &floatValue, 0.0f, 1.0f); 72 | 73 | //this will change the app background color 74 | ImGui::ColorEdit3("Background Color", (float*)&backgroundColor); 75 | if(ImGui::Button("Test Window")) 76 | { 77 | show_test_window = !show_test_window; 78 | } 79 | 80 | if (ImGui::Button("Another Window")) 81 | { 82 | //bitwise OR 83 | show_another_window ^= 1; 84 | 85 | } 86 | ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); 87 | } 88 | // 2. Show another window, this time using an explicit ImGui::Begin and ImGui::End 89 | if (show_another_window) 90 | { 91 | //note: ofVec2f and ImVec2f are interchangeable 92 | ImGui::SetNextWindowSize(ofVec2f(200,100), ImGuiCond_FirstUseEver); 93 | ImGui::Begin("Another Window", &show_another_window); 94 | ImGui::Text("Hello"); 95 | ImGui::End(); 96 | } 97 | 98 | // 3. Show the ImGui test window. Most of the sample code is in ImGui::ShowTestWindow() 99 | if (show_test_window) 100 | { 101 | ImGui::SetNextWindowPos(ofVec2f(650, 20), ImGuiCond_FirstUseEver); 102 | ImGui::ShowDemoWindow(&show_test_window); 103 | } 104 | 105 | bool pressed = ImGui::ImageButton((ImTextureID)(uintptr_t)imageButtonID, ImVec2(200, 200)); 106 | pressed = ImGui::ImageButton((ImTextureID)(uintptr_t)pixelsButtonID, ImVec2(200, 200)); 107 | pressed = ImGui::ImageButton((ImTextureID)(uintptr_t)textureSourceID, ImVec2(200, 200)); 108 | 109 | 110 | 111 | 112 | //required to call this at end 113 | gui.end(); 114 | 115 | if(textureSource.isAllocated()) 116 | { 117 | //textureSource.draw(ofRandom(200), ofRandom(200)); 118 | } 119 | } 120 | 121 | //-------------------------------------------------------------- 122 | void ofApp::exit(){ 123 | 124 | } 125 | 126 | //-------------------------------------------------------------- 127 | void ofApp::touchDown(ofTouchEventArgs & touch){ 128 | 129 | } 130 | 131 | //-------------------------------------------------------------- 132 | void ofApp::touchMoved(ofTouchEventArgs & touch){ 133 | 134 | } 135 | 136 | //-------------------------------------------------------------- 137 | void ofApp::touchUp(ofTouchEventArgs & touch){ 138 | 139 | } 140 | 141 | //-------------------------------------------------------------- 142 | void ofApp::touchDoubleTap(ofTouchEventArgs & touch){ 143 | 144 | } 145 | 146 | //-------------------------------------------------------------- 147 | void ofApp::touchCancelled(ofTouchEventArgs & touch){ 148 | 149 | } 150 | 151 | //-------------------------------------------------------------- 152 | void ofApp::lostFocus(){ 153 | 154 | } 155 | 156 | //-------------------------------------------------------------- 157 | void ofApp::gotFocus(){ 158 | 159 | } 160 | 161 | //-------------------------------------------------------------- 162 | void ofApp::gotMemoryWarning(){ 163 | 164 | } 165 | 166 | //-------------------------------------------------------------- 167 | void ofApp::deviceOrientationChanged(int newOrientation){ 168 | 169 | } 170 | -------------------------------------------------------------------------------- /example-multiwindow/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | -------------------------------------------------------------------------------- /example-multiwindow/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | #include "ofAppGLFWWindow.h" 4 | 5 | #pragma message "Warning, ofxImGui in multiple ofAppBaseWindows is in testing phase. Proceed with caution !" 6 | 7 | //======================================================================== 8 | int main( ){ 9 | ofSetLogLevel( OF_LOG_VERBOSE ); 10 | 11 | ofGLFWWindowSettings settings; // <-- GLES or GL depending on environment 12 | #if defined( TARGET_OPENGLES ) 13 | #if defined(TARGET_RASPBERRY_PI) 14 | settings.setGLESVersion(2); 15 | #else 16 | settings.setGLESVersion(3); 17 | #endif 18 | #else 19 | #if defined(TARGET_OSX) 20 | settings.setGLVersion(3,2); 21 | #else 22 | settings.setGLVersion(3,2); 23 | // settings.setGLVersion(3,2); // Uncomment if your GPU supports it 24 | #endif 25 | #endif 26 | 27 | settings.setSize(400, 400); 28 | settings.setPosition(ofVec2f(0, 220)); 29 | 30 | settings.title="Master Window"; 31 | auto window1 = ofCreateWindow(settings); 32 | 33 | // Note: using a different width to test coordinates, specially useful in non-viewports mode where they are relative 34 | settings.setPosition(ofVec2f(400, 20)); 35 | settings.setSize(500, 600); 36 | settings.title="Slave Window"; 37 | #if !defined( TARGET_OPENGLES ) 38 | settings.shareContextWith = window1; 39 | #else 40 | #pragma message "Warning, cannot share context with GLES windows. This example might not work correctly." 41 | #endif 42 | 43 | // WARNING : 44 | // For now, both GL versions must be the same for ImGui to work in a multiwindow context. 45 | //settings.setGLVersion(2, 1); 46 | auto window2 = ofCreateWindow(settings); 47 | 48 | auto app1 = std::make_shared(); 49 | auto app2 = std::make_shared(); 50 | 51 | #if !defined( TARGET_OPENGLES ) 52 | std::cout << "Window 1 = (ofAppBaseWindow)" << window1.get() << " // (ofAppGLFWWindow)" << (ofAppBaseWindow*) window1.get() << " // (GLFWwindow)" << ((ofAppGLFWWindow*) window1.get())->getGLFWWindow() << std::endl; 53 | std::cout << "Window 2 = (ofAppBaseWindow)" << window2.get() << " // (ofAppGLFWWindow)" << (ofAppBaseWindow*) window2.get() << " // (GLFWwindow)" << ((ofAppGLFWWindow*) window2.get())->getGLFWWindow() << std::endl; 54 | #else 55 | std::cout << "Window 1 = (ofAppBaseWindow)" << window1.get() << " // (ofAppBaseWindow)" << (ofAppBaseWindow*) window1.get() << " // " << std::endl; 56 | std::cout << "Window 2 = (ofAppBaseWindow)" << window2.get() << " // (ofAppBaseWindow)" << (ofAppBaseWindow*) window2.get() << " // " << std::endl; 57 | #endif 58 | ofRunApp(window1, app1); 59 | ofRunApp(window2, app2); 60 | 61 | return ofRunMainLoop(); 62 | } 63 | -------------------------------------------------------------------------------- /example-multiwindow/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | 3 | namespace ImGuiEx { 4 | 5 | void ShowHelpMarker(const char* desc){ 6 | ImGui::SameLine(); 7 | ImGui::TextDisabled("[?]"); 8 | if (ImGui::IsItemHovered()) 9 | { 10 | ImGui::BeginTooltip(); 11 | ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); 12 | ImGui::TextUnformatted(desc); 13 | ImGui::PopTextWrapPos(); 14 | ImGui::EndTooltip(); 15 | } 16 | } 17 | 18 | void ShowWarningMarker(const char* desc){ 19 | ImGui::SameLine(); 20 | ImGui::PushStyleColor(ImGuiCol_TextDisabled, IM_COL32(255,100,0,255)); 21 | ImGui::TextDisabled("/!\\"); 22 | ImGui::PopStyleColor(); 23 | 24 | if (ImGui::IsItemHovered()) 25 | { 26 | ImGui::BeginTooltip(); 27 | ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); 28 | ImGui::TextUnformatted(desc); 29 | ImGui::PopTextWrapPos(); 30 | ImGui::EndTooltip(); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /example-sharedcontext/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | -------------------------------------------------------------------------------- /example-sharedcontext/example-sharedContext.qbs: -------------------------------------------------------------------------------- 1 | import qbs 2 | import qbs.Process 3 | import qbs.File 4 | import qbs.FileInfo 5 | import qbs.TextFile 6 | import "../../../libs/openFrameworksCompiled/project/qtcreator/ofApp.qbs" as ofApp 7 | 8 | Project{ 9 | property string of_root: "../../.." 10 | 11 | ofApp { 12 | name: { return FileInfo.baseName(sourceDirectory) } 13 | cpp.minimumMacosVersion: '10.15' 14 | cpp.cxxLanguageVersion: 'c++17' 15 | 16 | files: [ 17 | 'src/main.cpp', 18 | 'src/ofApp.cpp', 19 | 'src/ofApp.h', 20 | 'src/myAddonClass.cpp', 21 | 'src/myAddonClass.h', 22 | 'src/privateAddonClass.cpp', 23 | 'src/privateAddonClass.h' 24 | ] 25 | 26 | of.addons: [ 27 | 'ofxImGui', 28 | ] 29 | 30 | // additional flags for the project. the of module sets some 31 | // flags by default to add the core libraries, search paths... 32 | // this flags can be augmented through the following properties: 33 | of.pkgConfigs: [] // list of additional system pkgs to include 34 | of.includePaths: [] // include search paths 35 | of.cFlags: [] // flags passed to the c compiler 36 | of.cxxFlags: [] // flags passed to the c++ compiler 37 | of.linkerFlags: [] // flags passed to the linker 38 | of.defines: [ // defines are passed as -D to the compiler 39 | // and can be checked with #ifdef or #if in the code 40 | 'OFXIMGUI_DEBUG', 41 | 'OFXIMGUI_ENABLE_OF_BINDINGS', 42 | ] 43 | of.frameworks: [] // osx only, additional frameworks to link with the project 44 | of.staticLibraries: [] // static libraries 45 | of.dynamicLibraries: [] // dynamic libraries 46 | 47 | // other flags can be set through the cpp module: http://doc.qt.io/qbs/cpp-module.html 48 | // eg: this will enable ccache when compiling 49 | // 50 | // cpp.compilerWrapper: 'ccache' 51 | 52 | Depends{ 53 | name: "cpp" 54 | } 55 | 56 | // common rules that parse the include search paths, core libraries... 57 | Depends{ 58 | name: "of" 59 | } 60 | 61 | // dependency with the OF library 62 | Depends{ 63 | name: "openFrameworks" 64 | } 65 | } 66 | 67 | property bool makeOF: true // use makfiles to compile the OF library 68 | // will compile OF only once for all your projects 69 | // otherwise compiled per project with qbs 70 | 71 | 72 | property bool precompileOfMain: false // precompile ofMain.h 73 | // faster to recompile when including ofMain.h 74 | // but might use a lot of space per project 75 | 76 | references: [FileInfo.joinPaths(of_root, "/libs/openFrameworksCompiled/project/qtcreator/openFrameworks.qbs")] 77 | } 78 | -------------------------------------------------------------------------------- /example-sharedcontext/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | #include "ofAppGLFWWindow.h" 4 | 5 | //======================================================================== 6 | int main( ){ 7 | 8 | #if defined( TARGET_OPENGLES ) || defined ( FORCE_GLES ) 9 | ofGLESWindowSettings settings; 10 | #if defined(TARGET_RASPBERRY_PI) 11 | settings.setGLESVersion(2); 12 | #else 13 | settings.setGLESVersion(3); 14 | #endif 15 | 16 | #else 17 | ofGLWindowSettings settings; 18 | #if defined(TARGET_OSX) 19 | settings.setGLVersion(3,2); 20 | #else 21 | settings.setGLVersion(4,1); 22 | #endif 23 | #endif 24 | 25 | settings.title="ofxImGui Shared Context Demo"; 26 | 27 | auto window1 = ofCreateWindow(settings); 28 | auto app1 = std::make_shared(); 29 | 30 | ofRunApp(window1, app1); 31 | 32 | ofRunMainLoop(); 33 | } 34 | -------------------------------------------------------------------------------- /example-sharedcontext/src/myAddonClass.cpp: -------------------------------------------------------------------------------- 1 | #include "myAddonClass.h" 2 | 3 | //-------------------------------------------------------------- 4 | void myAddonClass::setup() 5 | { 6 | // Ensure the gui is setup. 7 | if(gui==nullptr){ 8 | gui = new ofxImGui::Gui(); 9 | gui->setup(); 10 | } 11 | 12 | // Rest of setup code 13 | // ... 14 | } 15 | 16 | void myAddonClass::setup(ofxImGui::Gui& _parentGui) 17 | { 18 | // Use parent's shared gui 19 | if( _parentGui.isInSharedMode() ){ 20 | gui = &_parentGui; 21 | } 22 | else { 23 | ofLogError("myAddonClass::setup") << "The provided Gui is not running in shared mode, or has not been setup yet. Setting up a new Gui instead."; 24 | } 25 | 26 | // Continue with regular setup 27 | this->setup(); 28 | } 29 | 30 | //-------------------------------------------------------------- 31 | void myAddonClass::drawImGui() 32 | { 33 | auto mainSettings = ofxImGui::Settings(); 34 | 35 | gui->begin(); 36 | { 37 | if( showGuiWindow ){ 38 | // 1st window 39 | if( ImGui::Begin("myAddonClass 1st Window", &showGuiWindow, ImGuiWindowFlags_None) ){ 40 | ImGui::Text("Rectangle settings"); 41 | ImGui::Checkbox( "Draw Rectangles", &enableDrawing ); 42 | ImGui::ColorEdit4("Color", (float*)&color); 43 | ImGui::SliderFloat("Speed", &speedf, 0.f, 2.f); 44 | ImGui::SliderFloat("Size", &sizef, 0.f, 2.f); 45 | } 46 | ImGui::End(); 47 | 48 | // 2nd window 49 | // Using ofParameters 50 | if (ofxImGui::BeginWindow("myAddonClass 2nd Window", mainSettings, ImGuiWindowFlags_None, &showGuiWindow)){ 51 | ImGui::Text("These controls are bound to ofParameters"); 52 | ofxImGui::AddGroup(colors, mainSettings); 53 | ofxImGui::AddSlider(rotationOffset); 54 | ofxImGui::AddSlider(minSize); 55 | } 56 | ofxImGui::EndWindow(mainSettings); 57 | } 58 | } 59 | 60 | // Extend application menu 61 | ImGui::BeginMainMenuBar(); 62 | if(ImGui::BeginMenu("myAddonMenu")){ 63 | //ImGui::MenuItem( "Show Gui" ); 64 | ImGui::Checkbox("Show Controls", &showGuiWindow); 65 | ImGui::EndMenu(); 66 | } 67 | 68 | // You can even append your menu items to existing menus 69 | if(ImGui::BeginMenu("Main")){ 70 | ImGui::Checkbox( "Draw Rectangles", &enableDrawing ); 71 | ImGui::EndMenu(); 72 | } 73 | ImGui::EndMainMenuBar(); 74 | 75 | gui->end(); 76 | } 77 | 78 | //-------------------------------------------------------------- 79 | void myAddonClass::draw() 80 | { 81 | if( enableDrawing ){ 82 | float staticAnimationPos = ((cos(ofGetElapsedTimef()*TWO_PI*speedf))); 83 | int rectSize = minSize + abs( (((ofGetHeight()-minSize)*sizef))*(staticAnimationPos)); 84 | ofPushMatrix(); 85 | ofTranslate(ofGetWidth()*.5f, ofGetHeight()*.5f); 86 | ofRotateDeg((-rotationOffset*(staticAnimationPos))); 87 | ofSetColor(background->r*255, background->g*255, background->b*255, background->a*255); 88 | ofDrawRectangle( -rectSize*.5f, -rectSize*.5f, rectSize, rectSize ); 89 | ofRotateDeg(rotationOffset*(staticAnimationPos)); 90 | ofSetColor(color.x*255, color.y*255, color.z*255, color.w*255); 91 | ofDrawRectangle( -rectSize*.5f, -rectSize*.5f, rectSize, rectSize ); 92 | ofRotateDeg(rotationOffset*(staticAnimationPos)); 93 | ofSetColor(foreground->r*255, foreground->g*255, foreground->b*255, foreground->a*255); 94 | ofDrawRectangle( -rectSize*.5f, -rectSize*.5f, rectSize, rectSize ); 95 | ofPopMatrix(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /example-sharedcontext/src/myAddonClass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | 5 | #include "ofxImGui.h" 6 | #include "ImHelpers.h" 7 | 8 | class myAddonClass : public ofBaseApp 9 | { 10 | public: 11 | virtual void setup() override; 12 | virtual void setup( ofxImGui::Gui& _gui ); 13 | virtual void draw() override; 14 | // virtual void exit() override; // Todo: destroy gui on exit and see what happens ? 15 | void drawImGui(); 16 | 17 | private: 18 | ofxImGui::Gui* gui = nullptr; 19 | 20 | float sizef = 1; 21 | float speedf = 0.1f; 22 | ImVec4 color = {1,1,1,1}; 23 | bool showGuiWindow = true; 24 | bool enableDrawing = true; 25 | 26 | // ofParameters 27 | ofParameter background{ "Background", ofFloatColor::black }; 28 | ofParameter foreground{ "Foreground", ofFloatColor::crimson }; 29 | ofParameterGroup colors{ "Colors", background, foreground }; 30 | ofParameter rotationOffset{ "Rotation Offset", 180.0f, 0.0f, 360.f }; 31 | ofParameter minSize{ "Min size", 0.f, 0.0f, (float)ofGetHeight() }; // (float) is needed on Windows 32 | }; 33 | -------------------------------------------------------------------------------- /example-sharedcontext/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | #include "ofxImGui.h" 5 | #include "myAddonClass.h" 6 | #include "privateAddonClass.h" 7 | 8 | class ofApp : public ofBaseApp{ 9 | 10 | public: 11 | void setup() override; 12 | void draw() override; 13 | 14 | private: 15 | 16 | // instance 1 (ofApp) 17 | ofxImGui::Gui ofAppGui; 18 | ImVec4 ofAppColor = ofColor(114, 144, 154); 19 | void drawImGui(); 20 | 21 | // instance 2 (class/addon build for shared contexts) 22 | myAddonClass myAddonObject; 23 | 24 | // Instance 3 (class/addon that you can not modify) 25 | privateAddonClass privateAddonObject; 26 | }; 27 | -------------------------------------------------------------------------------- /example-sharedcontext/src/privateAddonClass.cpp: -------------------------------------------------------------------------------- 1 | #include "privateAddonClass.h" 2 | 3 | //-------------------------------------------------------------- 4 | void privateAddonClass::setup() 5 | { 6 | gui.setup(); 7 | } 8 | 9 | //-------------------------------------------------------------- 10 | void privateAddonClass::drawImGui() 11 | { 12 | 13 | gui.begin(); 14 | 15 | // 2nd window 16 | if(showGuiWindow){ 17 | if(ImGui::Begin("privateAddon Gui Window", &showGuiWindow)){ 18 | ImGui::Text("Circle settings"); 19 | ImGui::Checkbox( "Draw Circle", &enableDrawing ); 20 | ImGui::ColorEdit4("Color", (float*)&color); 21 | ImGui::SliderFloat("Speed", &speedf, 0.f, 2.f); 22 | ImGui::SliderFloat("Circle Size", &sizef, 0.f, 2.f); 23 | } 24 | ImGui::End(); 25 | } 26 | 27 | // Extend application menu 28 | ImGui::BeginMainMenuBar(); 29 | 30 | if( ImGui::BeginMenu("Circle") ){ 31 | ImGui::Checkbox( "Show Controls", &showGuiWindow ); 32 | ImGui::EndMenu(); 33 | } 34 | 35 | // You can even append your menu items to existing menus 36 | if( ImGui::BeginMenu("Main") ){ 37 | ImGui::Checkbox( "Draw Circle", &enableDrawing ); 38 | ImGui::EndMenu(); 39 | } 40 | ImGui::EndMainMenuBar(); 41 | 42 | gui.end(); 43 | } 44 | 45 | //-------------------------------------------------------------- 46 | void privateAddonClass::draw() 47 | { 48 | if( enableDrawing ){ 49 | ofSetColor(color.x*255, color.y*255, color.z*255, color.w*255); 50 | ofDrawCircle( ofGetWidth()*.5f, ofGetHeight()*.5f, ofGetHeight()*.5f*sizef*((fmod(ofGetElapsedTimef()*speedf, 1.f)-0.5f)*2.f) ); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /example-sharedcontext/src/privateAddonClass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | 5 | #include "ofxImGui.h" 6 | 7 | class privateAddonClass : public ofBaseApp 8 | { 9 | public: 10 | virtual void setup() override; 11 | virtual void draw() override; 12 | 13 | void drawImGui(); 14 | private: 15 | ofxImGui::Gui gui; 16 | 17 | float sizef = 1; 18 | float speedf = 0.1f; 19 | ImVec4 color = {1,1,1,1}; 20 | bool showGuiWindow = true; 21 | bool enableDrawing = true; 22 | }; 23 | -------------------------------------------------------------------------------- /example-simple/addons.make: -------------------------------------------------------------------------------- 1 | ofxImGui 2 | -------------------------------------------------------------------------------- /example-simple/src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ofMain.h" 2 | #include "ofApp.h" 3 | #include "ofAppGLFWWindow.h" 4 | 5 | //======================================================================== 6 | int main( ){ 7 | ofSetLogLevel(OF_LOG_VERBOSE); 8 | 9 | int windowWidth = 800; 10 | int windowHeight = 600; 11 | 12 | #if defined( TARGET_OPENGLES ) || defined ( FORCE_GLES ) 13 | ofGLESWindowSettings settings; 14 | #if defined(TARGET_RASPBERRY_PI) 15 | settings.setGLESVersion(2); 16 | #else 17 | settings.setGLESVersion(3); 18 | #endif 19 | 20 | #else 21 | ofGLWindowSettings settings; 22 | #if defined(TARGET_OSX) 23 | settings.setGLVersion(3,2); 24 | #else 25 | settings.setGLVersion(3,2); 26 | // settings.setGLVersion(4,1); // Uncomment if your GPU supports it 27 | #endif 28 | #endif 29 | settings.title="ofxImGui example-simple"; 30 | settings.setSize(windowWidth, windowHeight); 31 | 32 | auto window1 = ofCreateWindow(settings); 33 | auto app1 = std::make_shared(); 34 | 35 | ofRunApp(window1, app1); 36 | ofRunMainLoop(); 37 | } 38 | -------------------------------------------------------------------------------- /example-simple/src/ofApp.cpp: -------------------------------------------------------------------------------- 1 | #include "ofApp.h" 2 | -------------------------------------------------------------------------------- /example-simple/src/ofApp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofMain.h" 4 | #include "ofxImGui.h" 5 | 6 | // Comment below to use manual drawing 7 | #define USE_AUTODRAW 8 | 9 | class ofApp : public ofBaseApp{ 10 | 11 | public: 12 | ofApp() {} 13 | 14 | void setup() { 15 | ofSetLogLevel(OF_LOG_VERBOSE); 16 | #ifdef USE_AUTODRAW 17 | gui.setup(nullptr, true, ImGuiConfigFlags_ViewportsEnable, true ); 18 | #else 19 | gui.setup(nullptr, false); 20 | #endif 21 | } 22 | 23 | void draw() { 24 | ofSetBackgroundColor(backGroundColor[0]*100, backGroundColor[1]*100, backGroundColor[2]*100); 25 | 26 | // Start drawing to ImGui (newFrame) 27 | gui.begin(); 28 | 29 | if(bDrawOfxImGuiDebug){ 30 | gui.drawOfxImGuiDebugWindow(); 31 | } 32 | 33 | // Create a new window 34 | ImGui::Begin("ofxImGui example-simple"); 35 | 36 | // Method 1 - Passing variables to ImGui 37 | // In ImGui code, you'll often find static (stack) variables, as below. 38 | // They are created once in a stack and remain accessible there, unlike non-static variables which get destructed once the stack closes. 39 | // Many arguments you pass to ImGui functions need to remain valid between frames. (they are passed by reference [&]) 40 | static bool staticBool = false; 41 | ImGui::Checkbox("Checkbox", &staticBool); 42 | ImGui::Checkbox("Show ofxImGui Debug Window", &bDrawOfxImGuiDebug); 43 | 44 | // You can hide and show Gui parts on demand 45 | if(staticBool){ 46 | ImGui::Text("The checkbox above is checked."); 47 | } 48 | 49 | ImGui::Dummy(ImVec2(10,10)); 50 | ImGui::Separator(); 51 | 52 | // Method 2 - Passing variables to ImGui 53 | // This method is closer to OF practises, defining it as a member variable of your ofApp, and passing it to ImGui as a reference. 54 | ImGui::Checkbox("Draw lines", &drawLines); 55 | ImGui::ColorEdit3("Background color", &backGroundColor[0]); 56 | ImGui::SliderFloat("Float Slider", &v1, -10.f, 10.f); 57 | 58 | // Close the main window 59 | ImGui::End(); 60 | 61 | // The GUI hasn't been rendered yet : we can still draw below it 62 | if(drawLines){ 63 | auto halfWidth = ofGetWidth()*.5f; 64 | auto halfHeight = ofGetHeight()*.5f; 65 | ofDrawLine( halfWidth+ofRandomf()*halfWidth, halfHeight+ofRandomf()*halfHeight, halfWidth+ofRandomf()*halfWidth, halfHeight+ofRandomf()*halfHeight ); 66 | } 67 | ofDrawBitmapStringHighlight( "Float value used in oF: " +ofToString(v1), 10, 20); 68 | 69 | // End our ImGui Frame. 70 | gui.end(); 71 | 72 | #ifdef USE_AUTODRAW 73 | ofDrawBitmapStringHighlight( "I'm below the Gui !", 10, 40); // <-- This text will be over below the gui, except in shared mode 74 | #else 75 | gui.draw(); // <-- In manual mode, you can choose to render imgui at a given moment in your rendering pipeline 76 | ofDrawBitmapStringHighlight( "I'm over the Gui thanks to manual draw !", 10, 40); // <-- This text will be drawn over the gui 77 | #endif 78 | 79 | // If shared mode is on together with autodraw, rendering will happen after this scope, using the ofApp::draw callback. 80 | } 81 | 82 | void update(){ 83 | // Gui variables are also accessible outside of the draw() loop. 84 | int v1copy = v1; 85 | v1copy*=1;// silence "unused variable" warning ! 86 | } 87 | 88 | private: 89 | ofxImGui::Gui gui; 90 | 91 | // Variables exposed to ImGui 92 | float v1 = 0; 93 | float backGroundColor[3] = {1,1,1}; 94 | bool drawLines = false; 95 | bool bDrawOfxImGuiDebug = false; 96 | }; 97 | -------------------------------------------------------------------------------- /images/ImageButton.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/images/ImageButton.gif -------------------------------------------------------------------------------- /images/Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/images/Screenshot.png -------------------------------------------------------------------------------- /images/ofxImGui.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/images/ofxImGui.gif -------------------------------------------------------------------------------- /libs/Glfw_GLES1_Support.diff: -------------------------------------------------------------------------------- 1 | diff --git a/./imgui_git/backends/imgui_impl_opengl2.cpp b/./imgui/backends/imgui_impl_opengl2.cpp 2 | index 0028369..2a2a978 100644 3 | --- a/./imgui_git/backends/imgui_impl_opengl2.cpp 4 | +++ b/./imgui/backends/imgui_impl_opengl2.cpp 5 | @@ -1,3 +1,8 @@ 6 | +// Warning! 7 | +// This file has been modified for ofxImGui to support GLES1. 8 | +// This is not the original one. Changes are indicated. 9 | +//---- 10 | + 11 | // dear imgui: Renderer Backend for OpenGL2 (legacy OpenGL, fixed pipeline) 12 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 13 | 14 | @@ -55,6 +60,12 @@ 15 | #pragma clang diagnostic ignored "-Wnonportable-system-include-path" 16 | #endif 17 | 18 | +// --- BEGIN CUSTOM MODIFICATION 19 | +#include "ofxImGuiConstants.h" 20 | +#if defined(OFXIMGUI_RENDERER_GLES) 21 | +#include "gles1CompatibilityHacks.h" 22 | +#else// --- END CUSTOM MODIFICATION 23 | + 24 | // Include OpenGL header (without an OpenGL loader) requires a bit of fiddling 25 | #if defined(_WIN32) && !defined(APIENTRY) 26 | #define APIENTRY __stdcall // It is customary to use APIENTRY for OpenGL function pointer declarations on all platforms. Additionally, the Windows OpenGL header needs APIENTRY. 27 | @@ -68,6 +79,7 @@ 28 | #else 29 | #include 30 | #endif 31 | +#endif // CUSTOM OFXIMGUI ADDED LINE 32 | 33 | struct ImGui_ImplOpenGL2_Data 34 | { 35 | -------------------------------------------------------------------------------- /libs/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 | // (Requires: GLFW 3.1+. Prefer GLFW 3.3+ 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 are obsolete since 1.87 and not supported since 1.91.5] 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 | // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 13 | // Issues: 14 | // [ ] Platform: Multi-viewport: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor). 15 | 16 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 17 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 18 | // Learn about Dear ImGui: 19 | // - FAQ https://dearimgui.com/faq 20 | // - Getting Started https://dearimgui.com/getting-started 21 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 22 | // - Introduction, links and more at the top of imgui.cpp 23 | 24 | #pragma once 25 | #include "imgui.h" // IMGUI_IMPL_API 26 | #ifndef IMGUI_DISABLE 27 | 28 | struct GLFWwindow; 29 | struct GLFWmonitor; 30 | 31 | // Follow "Getting Started" link and check examples/ folder to learn about using backends! 32 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 33 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 34 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks); 35 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 36 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 37 | 38 | // Emscripten related initialization phase methods (call after ImGui_ImplGlfw_InitForOpenGL) 39 | #ifdef __EMSCRIPTEN__ 40 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCallbacks(GLFWwindow* window, const char* canvas_selector); 41 | //static inline void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector) { ImGui_ImplGlfw_InstallEmscriptenCallbacks(nullptr, canvas_selector); } } // Renamed in 1.91.0 42 | #endif 43 | 44 | // GLFW callbacks install 45 | // - 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. 46 | // - 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. 47 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); 48 | IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); 49 | 50 | // GFLW callbacks options: 51 | // - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user) 52 | IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows); 53 | 54 | // GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks) 55 | IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 56 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 57 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 58 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 59 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 60 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 61 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 62 | IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event); 63 | 64 | // GLFW helpers 65 | IMGUI_IMPL_API void ImGui_ImplGlfw_Sleep(int milliseconds); 66 | 67 | #endif // #ifndef IMGUI_DISABLE 68 | -------------------------------------------------------------------------------- /libs/imgui/backends/imgui_impl_glfw_arc_support.h: -------------------------------------------------------------------------------- 1 | // This file is here to bring support for obj-c ARC which was introduced in of_v0.12.0. 2 | // ImGui doesn't support compiling with ARC features and OF enabled it by default now. 3 | // It also fixes prior OF versions when eventually compiled with ARC support enabled. 4 | // 5 | // We need to tell the ARC meccanism either to `(__bridge void*)` or `CFBridgingRetain(...)` 6 | // ofAppGLFWWindow.cpp uses `__bridge` so I blindly choose that solution. Maybe it's wrong. 7 | // See also issue #134 : https://github.com/jvcleave/ofxImGui/issues/134 8 | 9 | #pragma once 10 | 11 | // Required for non-Clang compiler support 12 | // Thanks to @GitBruno : https://github.com/PlaymodesStudio/ofxImGuiSimple/issues/3#issuecomment-2586343914 13 | #ifndef __has_feature // Optional of course 14 | #define __has_feature(x) 0 // Compatibility with non-clang compilers 15 | #endif 16 | #ifndef __has_extension 17 | #define __has_extension __has_feature // Compatibility with pre-3.0 compilers 18 | #endif 19 | 20 | // Hacky but simple :) 21 | // Injects ARC support by defining glfwGetCocoaWindow something else 22 | #if defined(__OBJC__) && __has_feature(objc_arc) 23 | # define glfwGetCocoaWindow (__bridge void*) glfwGetCocoaWindow 24 | // Alternatives 25 | //# define glfwGetCocoaWindow(X) (__bridge void*) glfwGetCocoaWindow(X) 26 | #else 27 | # undef glfwGetCocoaWindow 28 | // Alternatives 29 | //# define glfwGetCocoaWindow(X) glfwGetCocoaWindow(X) 30 | #endif 31 | -------------------------------------------------------------------------------- /libs/imgui/backends/imgui_impl_glfw_context_support.cpp: -------------------------------------------------------------------------------- 1 | 2 | //#pragma once 3 | 4 | #include "imgui_impl_glfw_context_support.h" 5 | #include "ofxImGuiConstants.h" // To get the definition of OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 6 | 7 | #if defined(OFXIMGUI_BACKEND_GLFW) && (OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP == 1) 8 | 9 | #include "backends/imgui_impl_glfw.h" 10 | #include "LinkedList.hpp" 11 | 12 | // Fwd declarations 13 | class ImGui_ImplGlfw_Data; 14 | 15 | // Some global vars 16 | LinkedList ImGui_ImplGlfw_ScopedContext::Contexts = {}; 17 | 18 | #else 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /libs/imgui/backends/imgui_impl_glfw_context_support.h: -------------------------------------------------------------------------------- 1 | // Fixes for enabling multi-context support for the GLFW backend 2 | // See https://github.com/ocornut/imgui/pull/3934#issuecomment-873213161 3 | // See https://github.com/ocornut/imgui/issues/5439 4 | 5 | // Multi-context is temporary in ofxImGui until ImGui eventually implements "additional host viewports" 6 | // Creating and managing multiple contexts is temporary and not recommended by Omar. 7 | 8 | // Glfw events are a bit messed; this ensures that the right windows events call upon the right imgui contexts. (see PR#3934 ) 9 | // This file aims to reduce changes in the GLFW backend while injecting context switching before imgui callbacks are triggered. 10 | 11 | #pragma once 12 | 13 | #include "ofxImGuiConstants.h" // To get the definition of OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 14 | #if defined(OFXIMGUI_BACKEND_GLFW) && (OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP == 1) 15 | 16 | #include "backends/imgui_impl_glfw.h" 17 | 18 | #include "LinkedList.hpp" 19 | 20 | // Fwd declarations 21 | struct ImGui_ImplGlfw_Data; 22 | 23 | namespace ofxImGui { 24 | class Gui; 25 | } 26 | 27 | // A scoped struct to set the correct context and restores it when destroyed 28 | // Reduces 29 | struct ImGui_ImplGlfw_ScopedContext { 30 | friend class ofxImGui::Gui; 31 | public: 32 | inline ImGui_ImplGlfw_ScopedContext(GLFWwindow* window): prevContext(ImGui::GetCurrentContext()){ 33 | ImGuiContext* context = Contexts.findData(window); 34 | if(context){ 35 | ImGui::SetCurrentContext(context); 36 | } 37 | } 38 | ~ImGui_ImplGlfw_ScopedContext(){ 39 | if(prevContext != nullptr){ 40 | ImGui::SetCurrentContext(prevContext); 41 | } 42 | } 43 | static inline void RegisterWindowContext(GLFWwindow* window, ImGuiContext* context){ 44 | Contexts.add( window, context ); 45 | } 46 | static inline void RemoveWindowContext(GLFWwindow* window){ 47 | Contexts.remove(window); 48 | } 49 | 50 | private: 51 | ImGuiContext* const prevContext; 52 | // Contains all standalone viewport windows. 53 | static LinkedList Contexts; 54 | }; 55 | 56 | // Very tmp not to modify imgui_glfw again 57 | inline void ImGui_ImplGlfw_RegisterWindowContext(GLFWwindow* window, ImGuiContext* context){ 58 | ImGui_ImplGlfw_ScopedContext::RegisterWindowContext(window, context); 59 | } 60 | inline void ImGui_ImplGlfw_RemoveWindowContext(GLFWwindow* window){ 61 | ImGui_ImplGlfw_ScopedContext::RemoveWindowContext(window); 62 | } 63 | 64 | // Todo: set context for : 65 | // - ImGui_ImplGlfw_UpdateKeyModifiers ? 66 | // - ImGui_ImplGlfw_MonitorCallback ? 67 | 68 | #else 69 | // Define classes, compiler should strip all in optimisation steps as it's just dummy code. 70 | class GLFWwindow; 71 | class ImGuiContext; 72 | inline void ImGui_ImplGlfw_RemoveWindowContext(GLFWwindow* window){} 73 | inline void ImGui_ImplGlfw_RegisterWindowContext(GLFWwindow* window, ImGuiContext* context){} 74 | struct ImGui_ImplGlfw_ScopedContext { 75 | ImGui_ImplGlfw_ScopedContext(GLFWwindow* window){} 76 | }; 77 | #endif 78 | -------------------------------------------------------------------------------- /libs/imgui/backends/imgui_impl_opengl2.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for OpenGL2 (legacy OpenGL, fixed pipeline) 2 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 3 | 4 | // Implemented features: 5 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! 6 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 7 | 8 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 9 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 10 | // Learn about Dear ImGui: 11 | // - FAQ https://dearimgui.com/faq 12 | // - Getting Started https://dearimgui.com/getting-started 13 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 14 | // - Introduction, links and more at the top of imgui.cpp 15 | 16 | // **DO NOT USE THIS CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** 17 | // **Prefer using the code in imgui_impl_opengl3.cpp** 18 | // This code is mostly provided as a reference to learn how ImGui integration works, because it is shorter to read. 19 | // If your code is using GL3+ context or any semi modern OpenGL calls, using this is likely to make everything more 20 | // complicated, will require your code to reset every single OpenGL attributes to their initial state, and might 21 | // confuse your GPU driver. 22 | // The GL2 code is unable to reset attributes or even call e.g. "glUseProgram(0)" because they don't exist in that API. 23 | 24 | #pragma once 25 | #include "imgui.h" // IMGUI_IMPL_API 26 | #ifndef IMGUI_DISABLE 27 | 28 | // Follow "Getting Started" link and check examples/ folder to learn about using backends! 29 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_Init(); 30 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_Shutdown(); 31 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_NewFrame(); 32 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_RenderDrawData(ImDrawData* draw_data); 33 | 34 | // Called by Init/NewFrame/Shutdown 35 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateFontsTexture(); 36 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyFontsTexture(); 37 | IMGUI_IMPL_API bool ImGui_ImplOpenGL2_CreateDeviceObjects(); 38 | IMGUI_IMPL_API void ImGui_ImplOpenGL2_DestroyDeviceObjects(); 39 | 40 | #endif // #ifndef IMGUI_DISABLE 41 | -------------------------------------------------------------------------------- /libs/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 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 10 | 11 | // About WebGL/ES: 12 | // - You need to '#define IMGUI_IMPL_OPENGL_ES2' or '#define IMGUI_IMPL_OPENGL_ES3' to use WebGL or OpenGL ES. 13 | // - This is done automatically on iOS, Android and Emscripten targets. 14 | // - 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. 15 | 16 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 17 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 18 | // Learn about Dear ImGui: 19 | // - FAQ https://dearimgui.com/faq 20 | // - Getting Started https://dearimgui.com/getting-started 21 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 22 | // - Introduction, links and more at the top of imgui.cpp 23 | 24 | // About GLSL version: 25 | // The 'glsl_version' initialization parameter should be nullptr (default) or a "#version XXX" string. 26 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" 27 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. 28 | 29 | #pragma once 30 | #include "imgui.h" // IMGUI_IMPL_API 31 | #ifndef IMGUI_DISABLE 32 | 33 | // Follow "Getting Started" link and check examples/ folder to learn about using backends! 34 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = nullptr); 35 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 36 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); 37 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); 38 | 39 | // (Optional) Called by Init/NewFrame/Shutdown 40 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); 41 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); 42 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); 43 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); 44 | 45 | // Configuration flags to add in your imconfig file: 46 | //#define IMGUI_IMPL_OPENGL_ES2 // Enable ES 2 (Auto-detected on Emscripten) 47 | //#define IMGUI_IMPL_OPENGL_ES3 // Enable ES 3 (Auto-detected on iOS/Android) 48 | 49 | // 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. 50 | #if !defined(IMGUI_IMPL_OPENGL_ES2) \ 51 | && !defined(IMGUI_IMPL_OPENGL_ES3) 52 | 53 | // Try to detect GLES on matching platforms 54 | #if defined(__APPLE__) 55 | #include 56 | #endif 57 | #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) 58 | #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" 59 | #elif defined(__EMSCRIPTEN__) || defined(__amigaos4__) 60 | #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" 61 | #else 62 | // Otherwise imgui_impl_opengl3_loader.h will be used. 63 | #endif 64 | 65 | #endif 66 | 67 | #endif // #ifndef IMGUI_DISABLE 68 | -------------------------------------------------------------------------------- /libs/imgui/docs/BACKENDS.md: -------------------------------------------------------------------------------- 1 | _(You may browse this at https://github.com/ocornut/imgui/blob/master/docs/BACKENDS.md or view this file with any Markdown viewer)_ 2 | 3 | ## Dear ImGui: Backends 4 | 5 | ### Integrating backends 6 | 7 | 💡 The **[Getting Started](https://github.com/ocornut/imgui/wiki/Getting-Started) wiki guide** has examples of how to integrate Dear ImGui into an existing application. 8 |
The [EXAMPLES.MD](https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md) documentation may also be worth a read. 9 | 10 | ### What are backends? 11 | 12 | Dear ImGui is highly portable and only requires a few things to run and render, typically: 13 | 14 | - Required: providing mouse/keyboard inputs (fed into the `ImGuiIO` structure). 15 | - Required: uploading the font atlas texture into graphics memory. 16 | - Required: rendering indexed textured triangles with a clipping rectangle. 17 | 18 | Extra features are opt-in, our backends try to support as many as possible: 19 | 20 | - Optional: custom texture binding support. 21 | - Optional: clipboard support. 22 | - Optional: gamepad support. 23 | - Optional: mouse cursor shape support. 24 | - Optional: IME support. 25 | - Optional: multi-viewports support. 26 | etc. 27 | 28 | This is essentially what each backend is doing + obligatory portability cruft. Using standard backends ensure you can get all those features including the ones that would be harder to implement on your side (e.g. multi-viewports support). 29 | 30 | It is important to understand the difference between the core Dear ImGui library (files in the root folder) 31 | and the backends which we are describing here (backends/ folder). 32 | 33 | - Some issues may only be backend or platform specific. 34 | - You should be able to write backends for pretty much any platform and any 3D graphics API. 35 | e.g. you can get creative and use software rendering or render remotely on a different machine. 36 | 37 | ### Standard backends 38 | 39 | **The [backends/](https://github.com/ocornut/imgui/blob/master/backends) folder contains backends for popular platforms/graphics API, which you can use in 40 | your application or engine to easily integrate Dear ImGui.** Each backend is typically self-contained in a pair of files: imgui_impl_XXXX.cpp + imgui_impl_XXXX.h. 41 | 42 | - The 'Platform' backends are in charge of: mouse/keyboard/gamepad inputs, cursor shape, timing, and windowing.
43 | e.g. Windows ([imgui_impl_win32.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_win32.cpp)), GLFW ([imgui_impl_glfw.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_glfw.cpp)), SDL2 ([imgui_impl_sdl2.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_sdl2.cpp)), etc. 44 | 45 | - The 'Renderer' backends are in charge of: creating atlas texture, and rendering imgui draw data.
46 | e.g. DirectX11 ([imgui_impl_dx11.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_dx11.cpp)), OpenGL/WebGL ([imgui_impl_opengl3.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_opengl3.cpp)), Vulkan ([imgui_impl_vulkan.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_vulkan.cpp)), etc. 47 | 48 | - For some high-level frameworks, a single backend usually handles both 'Platform' and 'Renderer' parts.
49 | e.g. Allegro 5 ([imgui_impl_allegro5.cpp](https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_allegro5.cpp)). If you end up creating a custom backend for your engine, you may want to do the same. 50 | 51 | An application usually combines one Platform backend + one Renderer backend + main Dear ImGui sources. 52 | For example, the [example_win32_directx11](https://github.com/ocornut/imgui/tree/master/examples/example_win32_directx11) application combines imgui_impl_win32.cpp + imgui_impl_dx11.cpp. There are 20+ examples in the [examples/](https://github.com/ocornut/imgui/blob/master/examples/) folder. See [EXAMPLES.MD](https://github.com/ocornut/imgui/blob/master/docs/EXAMPLES.md) for details. 53 | 54 | **Once Dear ImGui is setup and running, run and refer to `ImGui::ShowDemoWindow()` in imgui_demo.cpp for usage of the end-user API.** 55 | 56 | ### List of backends 57 | 58 | In the [backends/](https://github.com/ocornut/imgui/blob/master/backends) folder: 59 | 60 | List of Platforms Backends: 61 | 62 | imgui_impl_android.cpp ; Android native app API 63 | imgui_impl_glfw.cpp ; GLFW (Windows, macOS, Linux, etc.) http://www.glfw.org/ 64 | imgui_impl_osx.mm ; macOS native API (not as feature complete as glfw/sdl backends) 65 | imgui_impl_sdl2.cpp ; SDL2 (Windows, macOS, Linux, iOS, Android) https://www.libsdl.org 66 | imgui_impl_sdl3.cpp ; SDL3 (Windows, macOS, Linux, iOS, Android) https://www.libsdl.org (*EXPERIMENTAL UNTIL SDL3 IS RELEASED*) 67 | imgui_impl_win32.cpp ; Win32 native API (Windows) 68 | imgui_impl_glut.cpp ; GLUT/FreeGLUT (this is prehistoric software and absolutely not recommended today!) 69 | 70 | List of Renderer Backends: 71 | 72 | imgui_impl_dx9.cpp ; DirectX9 73 | imgui_impl_dx10.cpp ; DirectX10 74 | imgui_impl_dx11.cpp ; DirectX11 75 | imgui_impl_dx12.cpp ; DirectX12 76 | imgui_impl_metal.mm ; Metal (with ObjC) 77 | imgui_impl_opengl2.cpp ; OpenGL 2 (legacy, fixed pipeline <- don't use with modern OpenGL context) 78 | imgui_impl_opengl3.cpp ; OpenGL 3/4, OpenGL ES 2, OpenGL ES 3 (modern programmable pipeline) 79 | imgui_impl_sdlrenderer2.cpp ; SDL_Renderer (optional component of SDL2 available from SDL 2.0.18+) 80 | imgui_impl_sdlrenderer3.cpp ; SDL_Renderer (optional component of SDL3 available from SDL 3.0.0+) 81 | imgui_impl_vulkan.cpp ; Vulkan 82 | imgui_impl_wgpu.cpp ; WebGPU (web and desktop) 83 | 84 | List of high-level Frameworks Backends (combining Platform + Renderer): 85 | 86 | imgui_impl_allegro5.cpp 87 | 88 | Emscripten is also supported! 89 | The SDL+GL, GLFW+GL and GLFW+WebGPU examples are all ready to build and run with Emscripten. 90 | 91 | ### Backends for third-party frameworks, graphics API or other languages 92 | 93 | See https://github.com/ocornut/imgui/wiki/Bindings for the full list (e.g. Adventure Game Studio, Cinder, Cocos2d-x, Game Maker Studio2, Godot, LÖVE+LUA, Magnum, Monogame, Ogre, openFrameworks, OpenSceneGraph, SFML, Sokol, Unity, Unreal Engine and many others). 94 | 95 | ### Recommended Backends 96 | 97 | If you are not sure which backend to use, the recommended platform/frameworks for portable applications: 98 | 99 | |Library |Website |Backend |Note | 100 | |--------|--------|--------|-----| 101 | | GLFW | https://github.com/glfw/glfw | imgui_impl_glfw.cpp | | 102 | | SDL2 | https://www.libsdl.org | imgui_impl_sdl2.cpp | | 103 | | Sokol | https://github.com/floooh/sokol | [util/sokol_imgui.h](https://github.com/floooh/sokol/blob/master/util/sokol_imgui.h) | Lower-level than GLFW/SDL | 104 | 105 | 106 | ### Using a custom engine? 107 | 108 | You will likely be tempted to start by rewrite your own backend using your own custom/high-level facilities...
109 | Think twice! 110 | 111 | If you are new to Dear ImGui, first try using the existing backends as-is. 112 | You will save lots of time integrating the library. 113 | You can LATER decide to rewrite yourself a custom backend if you really need to. 114 | In most situations, custom backends have fewer features and more bugs than the standard backends we provide. 115 | If you want portability, you can use multiple backends and choose between them either at compile time 116 | or at runtime. 117 | 118 | **Example A**: your engine is built over Windows + DirectX11 but you have your own high-level rendering 119 | system layered over DirectX11.
120 | Suggestion: try using imgui_impl_win32.cpp + imgui_impl_dx11.cpp first. 121 | Once it works, if you really need it, you can replace the imgui_impl_dx11.cpp code with a 122 | custom renderer using your own rendering functions, and keep using the standard Win32 code etc. 123 | 124 | **Example B**: your engine runs on Windows, Mac, Linux and uses DirectX11, Metal, and Vulkan respectively.
125 | Suggestion: use multiple generic backends! 126 | Once it works, if you really need it, you can replace parts of backends with your own abstractions. 127 | 128 | **Example C**: your engine runs on platforms we can't provide public backends for (e.g. PS4/PS5, Switch), 129 | and you have high-level systems everywhere.
130 | Suggestion: try using a non-portable backend first (e.g. win32 + underlying graphics API) to get 131 | your desktop builds working first. This will get you running faster and get your acquainted with 132 | how Dear ImGui works and is setup. You can then rewrite a custom backend using your own engine API... 133 | 134 | Generally: 135 | It is unlikely you will add value to your project by creating your own backend. 136 | 137 | Also: 138 | The [multi-viewports feature](https://github.com/ocornut/imgui/wiki/Multi-Viewports) of the 'docking' branch allows 139 | Dear ImGui windows to be seamlessly detached from the main application window. This is achieved using an 140 | extra layer to the Platform and Renderer backends, which allows Dear ImGui to communicate platform-specific 141 | requests such as: "create an additional OS window", "create a render context", "get the OS position of this 142 | window" etc. See 'ImGuiPlatformIO' for details. 143 | Supporting the multi-viewports feature correctly using 100% of your own abstractions is more difficult 144 | than supporting single-viewport. 145 | If you decide to use unmodified imgui_impl_XXXX.cpp files, you can automatically benefit from 146 | improvements and fixes related to viewports and platform windows without extra work on your side. 147 | -------------------------------------------------------------------------------- /libs/imgui/extras/imgui_stdlib.cpp: -------------------------------------------------------------------------------- 1 | // dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.) 2 | // This is also an example of how you may wrap your own similar types. 3 | 4 | // Changelog: 5 | // - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string 6 | 7 | // See more C++ related extension (fmt, RAII, syntaxis sugar) on Wiki: 8 | // https://github.com/ocornut/imgui/wiki/Useful-Extensions#cness 9 | 10 | #include "imgui.h" 11 | #ifndef IMGUI_DISABLE 12 | #include "imgui_stdlib.h" 13 | 14 | // Clang warnings with -Weverything 15 | #if defined(__clang__) 16 | #pragma clang diagnostic push 17 | #pragma clang diagnostic ignored "-Wsign-conversion" // warning: implicit conversion changes signedness 18 | #endif 19 | 20 | struct InputTextCallback_UserData 21 | { 22 | std::string* Str; 23 | ImGuiInputTextCallback ChainCallback; 24 | void* ChainCallbackUserData; 25 | }; 26 | 27 | static int InputTextCallback(ImGuiInputTextCallbackData* data) 28 | { 29 | InputTextCallback_UserData* user_data = (InputTextCallback_UserData*)data->UserData; 30 | if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) 31 | { 32 | // Resize string callback 33 | // If for some reason we refuse the new length (BufTextLen) and/or capacity (BufSize) we need to set them back to what we want. 34 | std::string* str = user_data->Str; 35 | IM_ASSERT(data->Buf == str->c_str()); 36 | str->resize(data->BufTextLen); 37 | data->Buf = (char*)str->c_str(); 38 | } 39 | else if (user_data->ChainCallback) 40 | { 41 | // Forward to user callback, if any 42 | data->UserData = user_data->ChainCallbackUserData; 43 | return user_data->ChainCallback(data); 44 | } 45 | return 0; 46 | } 47 | 48 | bool ImGui::InputText(const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) 49 | { 50 | IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0); 51 | flags |= ImGuiInputTextFlags_CallbackResize; 52 | 53 | InputTextCallback_UserData cb_user_data; 54 | cb_user_data.Str = str; 55 | cb_user_data.ChainCallback = callback; 56 | cb_user_data.ChainCallbackUserData = user_data; 57 | return InputText(label, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data); 58 | } 59 | 60 | bool ImGui::InputTextMultiline(const char* label, std::string* str, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) 61 | { 62 | IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0); 63 | flags |= ImGuiInputTextFlags_CallbackResize; 64 | 65 | InputTextCallback_UserData cb_user_data; 66 | cb_user_data.Str = str; 67 | cb_user_data.ChainCallback = callback; 68 | cb_user_data.ChainCallbackUserData = user_data; 69 | return InputTextMultiline(label, (char*)str->c_str(), str->capacity() + 1, size, flags, InputTextCallback, &cb_user_data); 70 | } 71 | 72 | bool ImGui::InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) 73 | { 74 | IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0); 75 | flags |= ImGuiInputTextFlags_CallbackResize; 76 | 77 | InputTextCallback_UserData cb_user_data; 78 | cb_user_data.Str = str; 79 | cb_user_data.ChainCallback = callback; 80 | cb_user_data.ChainCallbackUserData = user_data; 81 | return InputTextWithHint(label, hint, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data); 82 | } 83 | 84 | #if defined(__clang__) 85 | #pragma clang diagnostic pop 86 | #endif 87 | 88 | #endif // #ifndef IMGUI_DISABLE 89 | -------------------------------------------------------------------------------- /libs/imgui/extras/imgui_stdlib.h: -------------------------------------------------------------------------------- 1 | // dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.) 2 | // This is also an example of how you may wrap your own similar types. 3 | 4 | // Changelog: 5 | // - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string 6 | 7 | // See more C++ related extension (fmt, RAII, syntaxis sugar) on Wiki: 8 | // https://github.com/ocornut/imgui/wiki/Useful-Extensions#cness 9 | 10 | #pragma once 11 | 12 | #include "imgui.h" 13 | #ifndef IMGUI_DISABLE 14 | 15 | #include 16 | 17 | namespace ImGui 18 | { 19 | // ImGui::InputText() with std::string 20 | // Because text input needs dynamic resizing, we need to setup a callback to grow the capacity 21 | IMGUI_API bool InputText(const char* label, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = nullptr, void* user_data = nullptr); 22 | IMGUI_API bool InputTextMultiline(const char* label, std::string* str, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = nullptr, void* user_data = nullptr); 23 | IMGUI_API bool InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = nullptr, void* user_data = nullptr); 24 | } 25 | 26 | #endif // #ifndef IMGUI_DISABLE 27 | -------------------------------------------------------------------------------- /libs/imgui/src/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2024 Omar Cornut 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ofxaddons_thumbnail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Daandelange/ofxImGui/823bdb5b742d5f1fa3a6f859be34c29302ffb17d/ofxaddons_thumbnail.png -------------------------------------------------------------------------------- /scripts/ci/install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | echo "REMOVING IOS EXAMPLE" 5 | 6 | rm -rfv example-ios/ 7 | -------------------------------------------------------------------------------- /src/BaseEngine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofEvents.h" 4 | #include "ofAppBaseWindow.h" 5 | 6 | // Seems needed on windows 7 | #include "imgui.h" 8 | //struct ImGuiContext; 9 | 10 | // Fwd declaration 11 | namespace ofxImGui { 12 | class Gui; 13 | } 14 | //#define OFFSETOF(TYPE, ELEMENT) ((size_t)&(((TYPE *)0)->ELEMENT)) 15 | 16 | namespace ofxImGui 17 | { 18 | class BaseEngine 19 | { 20 | friend class EngineGLFW; 21 | friend class ofxImGui::Gui; 22 | public: 23 | BaseEngine() 24 | : isSetup(false) 25 | { 26 | //std::cout << "New BaseEngine " << this << std::endl; 27 | } 28 | 29 | virtual ~BaseEngine() 30 | {} 31 | 32 | // Prevent making copies, prevents making mistakes messing up the gui instances and contexts 33 | BaseEngine( const BaseEngine& ) = delete; 34 | BaseEngine& operator=( const BaseEngine& ) = delete; 35 | 36 | virtual void setup(ofAppBaseWindow* _window, ImGuiContext* imguiContext, bool autoDraw) = 0; 37 | //void setup(ofAppBaseWindow* _window, bool autoDraw); // for retro-compatibility, can be removed in next major release 38 | virtual void exit() = 0; 39 | 40 | virtual void newFrame() = 0; 41 | virtual void render() = 0; 42 | 43 | virtual bool updateFontsTexture() = 0; 44 | 45 | // This is here to keep a compatibility layer with old codebases. 46 | // Not recommended to use, Upload with OF and use the GL_TEXTURE_2D's textureID directly. 47 | virtual GLuint loadTextureImage2D(unsigned char * pixels, int width, int height); 48 | 49 | protected: 50 | const char* getGLVersionFromOF() const; 51 | static ImGuiKey oFKeyToImGuiKey(int key); 52 | bool isSetup; 53 | 54 | // Context handling helpers for events 55 | bool setImGuiContext(); 56 | void restoreImGuiContext(); 57 | 58 | // Copy of associated ImGui context 59 | // For handling events, as we don't know which context is set when they are called 60 | ImGuiContext* imguiContext = nullptr; 61 | ImGuiContext* imguiContextPrev = nullptr; 62 | }; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /src/BaseTheme.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "imgui.h" 4 | 5 | namespace ofxImGui 6 | { 7 | class BaseTheme 8 | { 9 | public: 10 | BaseTheme() 11 | { 12 | 13 | } 14 | virtual ~BaseTheme() 15 | { 16 | 17 | } 18 | 19 | virtual void setup()=0; 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /src/DefaultTheme.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "BaseTheme.h" 3 | 4 | namespace ofxImGui 5 | { 6 | class DefaultTheme: public ofxImGui::BaseTheme 7 | { 8 | public: 9 | 10 | void setup() override; 11 | }; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/EngineGLFW.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofxImGuiConstants.h" 4 | 5 | #ifdef OFXIMGUI_BACKEND_GLFW 6 | 7 | // This include is also used in the imgui glfw example, I hope it breaks nothing.... 8 | //#if defined(IMGUI_IMPL_OPENGL_ES2) 9 | //#include 10 | //#endif 11 | 12 | #include "BaseEngine.h" 13 | 14 | struct GLFWwindow; 15 | #if OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS == 1 16 | #if OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP == 1 17 | 18 | //struct GLFWwindow; 19 | 20 | #include "GLFW/glfw3.h" 21 | #include "LinkedList.hpp" 22 | 23 | struct GlfwCallbacks { 24 | // To store the original openFrameworks callbacks 25 | GLFWwindowfocusfun originalCallbackWindowFocus; 26 | GLFWcursorenterfun originalCallbackCursorEnter; 27 | GLFWcursorposfun originalCallbackCursorPos; 28 | GLFWmousebuttonfun originalCallbackMousebutton; 29 | GLFWscrollfun originalCallbackScroll; 30 | GLFWkeyfun originalCallbackKey; 31 | GLFWcharfun originalCallbackChar; 32 | GLFWmonitorfun originalCallbackMonitor; 33 | bool isValid; 34 | }; 35 | 36 | #endif 37 | #else 38 | //struct GLFWwindow; 39 | #endif 40 | 41 | namespace ofxImGui 42 | { 43 | class EngineGLFW 44 | : public BaseEngine 45 | { 46 | public: 47 | EngineGLFW(){ 48 | //std::cout << "New GLFWEngine " << this << std::endl; 49 | } 50 | ~EngineGLFW() 51 | { 52 | exit(); 53 | } 54 | 55 | // BaseEngine required 56 | void setup(ofAppBaseWindow* _window, ImGuiContext* _imguiContext, bool autoDraw) override; 57 | void exit() override; 58 | 59 | void newFrame() override; 60 | void render() override; 61 | 62 | bool updateFontsTexture() override; 63 | 64 | //void registerCallbacks(ofAppGLFWWindow* ofWindowPtr, GLFWwindow* glfwWindowPtr); 65 | void registerCallbacks(ofAppBaseWindow* ofWindowPtr, GLFWwindow* glfwWindowPtr); 66 | void unregisterCallbacks(); 67 | 68 | void onWindowExit(ofEventArgs& event); 69 | 70 | // Clipboard Functions 71 | //static const char* ImGui_ImplGlfw_GetClipboardText(void* user_data); 72 | //static void ImGui_ImplGlfw_SetClipboardText(void* user_data, const char* text); 73 | 74 | static GLuint g_FontTexture; 75 | 76 | // Bind to GLFW ? 77 | #if OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS == 1 78 | #if OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP == 1 79 | // Below --> might be temporary, see https://github.com/ocornut/imgui/blob/9764adc7bb7a582601dd4dd1c34d4fa17ab5c8e8/backends/imgui_impl_glfw.cpp#L142-L145 80 | // We act as the imgui backend : unbinding OF events then calling them with the new functions again 81 | // Idea: Maybe not-so-tmp; this might also facilitate some nice hackery to (optionally) stop propagation to OF when ImGui is being used ? :D 82 | 83 | // These allow binding a static method and call the member functions below. 84 | // They simply route events to the engine instance of the corresponding window 85 | static void GlfwWindowFocusCallbackGlobal(GLFWwindow* window, int focused); // Since 1.84 86 | static void GlfwCursorEnterCallbackGlobal(GLFWwindow* window, int entered); // Since 1.84 87 | static void GlfwCursorPosCallbackGlobal(GLFWwindow* window, double x, double y); // Since 1.87 88 | static void GlfwMouseButtonCallbackGlobal(GLFWwindow* window, int button, int action, int mods); 89 | static void GlfwScrollCallbackGlobal(GLFWwindow* window, double xoffset, double yoffset); 90 | static void GlfwKeyCallbackGlobal(GLFWwindow* window, int key, int scancode, int action, int mods); 91 | static void GlfwCharCallbackGlobal(GLFWwindow* window, unsigned int c); 92 | static void GlfwMonitorCallbackGlobal(GLFWmonitor* monitor, int event); 93 | 94 | // Non-static callbacks 95 | void GlfwWindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 96 | void GlfwCursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 97 | void GlfwCursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 98 | void GlfwMouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 99 | void GlfwScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 100 | void GlfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 101 | void GlfwCharCallback(GLFWwindow* window, unsigned int c); 102 | void GlfwMonitorCallback(GLFWmonitor* monitor, int event); 103 | 104 | static LinkedList enginesMap; 105 | // Alternative: Use GLFW callback userdata to find back our object when the static callback is called 106 | // See https://github.com/ocornut/imgui/pull/3934#issuecomment-873213161 107 | // Error : OF also sets the GLFW user pointer. If we set it, OF breaks. 108 | 109 | // One storage for all original callbacks 110 | GlfwCallbacks originalOFCallbacks; 111 | #elif OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP == 1 112 | GLFWwindow* mainGLFWWindow = nullptr; 113 | #endif 114 | // Bind to Openframeworks 115 | #else 116 | // Input events 117 | void onKeyEvent(ofKeyEventArgs& event); 118 | void onCharInput(uint32_t& _char); 119 | 120 | // Mouse events 121 | void onMouseMoved(ofMouseEventArgs& event); 122 | void onMouseDragged(ofMouseEventArgs& event); 123 | void onMouseScrolled(ofMouseEventArgs& event); 124 | void onMouseButton(ofMouseEventArgs& event); 125 | 126 | // Window events 127 | //void onWindowResized(ofResizeEventArgs& window); 128 | 129 | // todo : exit_cb, drop_cb 130 | // can't : framebuffer_size_cb, error_cb 131 | #endif 132 | 133 | }; 134 | } 135 | #endif 136 | -------------------------------------------------------------------------------- /src/EngineOpenFrameworks.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofConstants.h" 4 | 5 | //#include "ofxImGuiConstants.h" // To get the definition of OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 6 | //#if defined(OFXIMGUI_BACKEND_GLFW) 7 | 8 | // OpenGL ES platform includes 9 | #ifdef IMGUI_IMPL_OPENGL_ES2 10 | 11 | // This include is also used in the imgui glfw example, I hope it breaks nothing.... 12 | //#include 13 | 14 | // Linux GLES (rpi & desktop) 15 | #ifdef TARGET_LINUX_ARM // TARGET_RASPBERRY_PI 16 | // includes from ofConstants.h / Linux ARM 17 | #include "GLES/gl.h" 18 | #include "GLES/glext.h" 19 | #include "GLES2/gl2.h" 20 | #include "GLES2/gl2ext.h" 21 | 22 | #define EGL_EGLEXT_PROTOTYPES 23 | #include "EGL/egl.h" 24 | #include "EGL/eglext.h" 25 | // iOS 26 | #elif defined(TARGET_OF_IOS) 27 | // includes from ofConstants.h / iOS 28 | #import 29 | #import 30 | #import 31 | #import 32 | // Other = Unsupported 33 | #else 34 | #pragma error "IMGUI_IMPL_OPENGL_ES2 is defined but your platform doesn't support it (yet?). Compilation will fail." 35 | #endif 36 | 37 | #endif // IMGUI_IMPL_OPENGL_ES2 38 | 39 | // Warn Vulkan users 40 | #if defined(OF_TARGET_API_VULKAN) 41 | #include "backends/imgui_impl_vulkan.h" 42 | #elif defined(TARGET_OPENGLES) && !defined(TARGET_GLFW_WINDOW) 43 | // Todo: include GLSL stuff ? 44 | #endif 45 | 46 | #include "BaseEngine.h" 47 | 48 | #include "ofEvents.h" 49 | #include "imgui.h" 50 | 51 | // This is the native openFrameworks ImGui custom PLATFORM backend. 52 | // It uses the default imgui opengl 2+3 RENDERER backends. 53 | // The platform backend is directly bound to openFrameworks so that it works in any project configuration. 54 | // It's however recommended to use the native GLFW backend because: 55 | // - Custom backends are harder to maintain between ImGui versions and have therefore less backend features implemented. 56 | // - The native backends has more advanced feautures such as viewports support. 57 | 58 | namespace ofxImGui 59 | { 60 | class EngineOpenFrameworks 61 | : public BaseEngine 62 | { 63 | public: 64 | ~EngineOpenFrameworks() 65 | { 66 | exit(); 67 | } 68 | 69 | // BaseEngine required 70 | void setup(ofAppBaseWindow* _window, ImGuiContext* imguiContext, bool autoDraw) override; 71 | void exit() override; 72 | 73 | void newFrame() override; 74 | void render() override; 75 | 76 | bool updateFontsTexture() override; 77 | 78 | // Keyboard events 79 | void onKeyEvent(ofKeyEventArgs& event); 80 | void onCharInput(uint32_t& _char); 81 | 82 | // Mouse events 83 | void onMouseMoved(ofMouseEventArgs& event); 84 | void onMouseDragged(ofMouseEventArgs& event); 85 | void onMouseScrolled(ofMouseEventArgs& event); 86 | void onMouseButton(ofMouseEventArgs& event); 87 | #ifdef OFXIMGUI_TOUCH_EVENTS 88 | void onTouchInput(ofTouchEventArgs & touch); 89 | //void onTouchDown(ofTouchEventArgs & touch); 90 | //void onTouchMoved(ofTouchEventArgs & touch); 91 | //void onTouchUp(ofTouchEventArgs & touch); 92 | //void onTouchDoubleTap(ofTouchEventArgs & touch); 93 | //void onTouchCancelled(ofTouchEventArgs & touch); 94 | #endif 95 | 96 | // Window events 97 | void onWindowResized(ofResizeEventArgs& window); 98 | #ifdef OFXIMGUI_TOUCH_EVENTS 99 | // void onLostFocus(); 100 | // void onGotFocus(); 101 | // void onDeviceOrientationChanged(int newOrientation); 102 | #endif 103 | 104 | // todo: gamepad support ? io.AddKeyEvent()/io.AddKeyAnalogEvent() 105 | 106 | // Clipboard handling 107 | static const char* getClipboardString(void * userData); 108 | static void setClipboardString(void * userData, const char * text); 109 | static std::string g_ClipboardText; // Is this still useful ? Maybe ofWin->setClipboardString needs a reference that stays alive ? 110 | 111 | // Helpers 112 | //static ImGuiKey oFKeyToImGuiKey(int key); 113 | static ImGuiKey keyCodeToImGuiKey(int keyCode); 114 | 115 | 116 | protected: 117 | void registerListeners(); 118 | void unregisterListeners(); 119 | }; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /src/EngineOpenGLES.cpp: -------------------------------------------------------------------------------- 1 | #include "EngineOpenGLES.h" 2 | #ifdef OFXIMGUI_BACKEND_GLES 3 | // Since the new backends, the GLES renderer is not used anymore, and rpis use the glfw backend with a GL or GLES renderer, having their respective backends too. 4 | #if defined(TARGET_OPENGLES) && !defined(TARGET_GLFW_WINDOW)// && defined(USE_GLFW_WINDOW) //&& !defined(TARGET_RASPBERRY_PI_LEGACY) 5 | 6 | //#include "ofAppiOSWindow.h" 7 | //#include "imgui_impl_osx.h" 8 | //#include "imgui_impl_opengl3.h" 9 | #include "ofAppRunner.h" 10 | #include "ofGLProgrammableRenderer.h" 11 | 12 | namespace ofxImGui 13 | { 14 | ofShader EngineOpenGLES::g_Shader; 15 | 16 | //-------------------------------------------------------------- 17 | void EngineOpenGLES::setup(bool autoDraw) 18 | { 19 | if (isSetup) return; 20 | 21 | ImGuiIO& io = ImGui::GetIO(); 22 | 23 | #ifdef OFXIMGUI_DEBUG 24 | ofLogVerbose(__FUNCTION__) << "ofxImGui loading GLES with native imgui bindings"; 25 | #pragma message "ofxImGui compiling with GLES renderer and native imgui bindings." 26 | #endif 27 | // TODO 28 | // Init window 29 | //ofAppiOSWindow* curWin = (ofAppiOSWindow*)ofGetWindowPtr()->getWindowContext(); 30 | //ImGui_ImplIOS_Init(); 31 | 32 | isSetup = true; 33 | } 34 | 35 | //-------------------------------------------------------------- 36 | void EngineOpenGLES::exit() 37 | { 38 | if (!isSetup) return; 39 | 40 | isSetup = false; 41 | } 42 | 43 | //-------------------------------------------------------------- 44 | void EngineOpenGLES::render() 45 | { 46 | // todo 47 | 48 | // Handle viewports 49 | // todo: check if this works 50 | ImGuiIO& io = ImGui::GetIO(); 51 | if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 52 | { 53 | // This line has to be ported to GLES 54 | //GLFWwindow* backup_current_context = glfwGetCurrentContext(); 55 | 56 | ImGui::UpdatePlatformWindows(); 57 | ImGui::RenderPlatformWindowsDefault(); 58 | 59 | // Restore context so we can continue to render with oF 60 | // This line has to be ported to GLES 61 | //glfwMakeContextCurrent(backup_current_context); 62 | } 63 | } 64 | } // end namespace ofxImGui 65 | 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /src/EngineOpenGLES.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofConstants.h" 4 | #include "ofxImGuiConstants.h" 5 | 6 | // Note : this implementation is broken, the file is kept for reference, if ported. 7 | #ifdef OFXIMGUI_BACKEND_GLES 8 | // Note: USE_GLFW_WINDOW is for ofxRPI4Window 9 | #if defined(TARGET_OPENGLES) && !defined(TARGET_GLFW_WINDOW)// && defined(USE_GLFW_WINDOW) //&& !defined(TARGET_RASPBERRY_PI_LEGACY) 10 | 11 | //#pragma GCC error "The OpenGLES implementation has not been updated yet ! (needs to be implemented)" 12 | 13 | //#ifdef TARGET_RASPBERRY_PI 14 | //#pragma GCC error "On oF 0.11 you should use a GLFW Window which supports GLES 1 2 and 3." 15 | //#pragma GCC error "On oF 0.10 and below, you should check out an older ofxImGui version. (below 1.80)" 16 | //#endif 17 | 18 | #include "BaseEngine.h" 19 | 20 | #include "ofEvents.h" 21 | #include "ofShader.h" 22 | #include "imgui.h" 23 | 24 | namespace ofxImGui 25 | { 26 | class EngineOpenGLES 27 | : public BaseEngine 28 | { 29 | public: 30 | ~EngineOpenGLES() 31 | { 32 | exit(); 33 | } 34 | 35 | // BaseEngine required 36 | virtual void setup(bool autoDraw) override; 37 | virtual void exit() override; 38 | 39 | virtual void render() override; 40 | virtual void newFrame() override{}; 41 | virtual void endFrame() override{}; 42 | 43 | virtual bool updateFontsTexture() override{ return false; }; 44 | 45 | static ofShader g_Shader; 46 | }; 47 | } 48 | 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/EngineVk.h: -------------------------------------------------------------------------------- 1 | #ifndef GUARD_ENGINE_VK_H 2 | #define GUARD_ENGINE_VK_H 3 | 4 | // We include this to check for #define OF_TARGET_API_VULKAN 5 | #include "ofConstants.h" 6 | #include "ofxImGuiConstants.h" 7 | 8 | #if defined(OF_TARGET_API_VULKAN) 9 | 10 | #pragma GCC error "Sorry, there's no support for Vulkan yet while it should be very easy to implement." 11 | #pragma message "Try to compile with OFXIMGUI_FORCE_OF_BACKEND defined to use the legacy version." 12 | // See https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_vulkan.h or ImGui_ImplGlfw_InitForVulkan 13 | 14 | 15 | #include "BaseEngine.h" 16 | 17 | #include "ofEvents.h" 18 | #include "imgui.h" 19 | #include 20 | 21 | #include "vk/ImageAllocator.h" 22 | #include "vk/Context.h" 23 | #include "vk/Texture.h" 24 | #include "vk/DrawCommand.h" 25 | #include "vk/RenderBatch.h" 26 | 27 | class ofVkRenderer; // ffdecl. 28 | 29 | namespace ofxImGui 30 | { 31 | class EngineVk 32 | : public BaseEngine 33 | { 34 | public: 35 | ~EngineVk() 36 | { 37 | exit(); 38 | } 39 | 40 | // BaseEngine required 41 | void setup(bool autoDraw) override; 42 | void exit() override; 43 | bool createDeviceObjects() override; 44 | void invalidateDeviceObjects() override; 45 | 46 | bool createFontsTexture(); 47 | 48 | void onKeyReleased(ofKeyEventArgs& event) override; 49 | void onKeyPressed(ofKeyEventArgs& event) override; 50 | void onMousePressed(ofMouseEventArgs& event) override; 51 | 52 | // Custom 53 | static void render(ImDrawData * draw_data); 54 | static void setRenderBatch( of::vk::RenderBatch& batch ); 55 | 56 | private: 57 | 58 | static ::vk::Device mDevice; // Non-owning reference to current VK device 59 | std::shared_ptr mRenderer; // Reference to current renderer 60 | static ::of::vk::RenderBatch* batch; // Current batch used for drawing 61 | static std::unique_ptr mImageAllocator; // Allocator used for font texture 62 | static std::shared_ptr<::vk::Image> mFontImage; // Data store for image data 63 | static std::shared_ptr mFontTexture; // Wrapper with sampler around font texture 64 | static std::unique_ptr mDrawCommand; // Used to draw ImGui components 65 | 66 | void createDrawCommands(); 67 | void setupImageAllocator(); 68 | 69 | }; 70 | 71 | } 72 | 73 | #endif // OF_TARGET_API_VULKAN 74 | #endif // GUARD_ENGINE_VK_H 75 | -------------------------------------------------------------------------------- /src/Gui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofImage.h" 4 | #include "ofPixels.h" 5 | #include "ofTexture.h" 6 | #include "ofEvents.h" 7 | #include "ofAppBaseWindow.h" 8 | #include "ofRectangle.h" 9 | 10 | #include 11 | #include 12 | 13 | #include "ofxImGuiConstants.h" 14 | #include "DefaultTheme.h" 15 | //#include "LinkedList.hpp" 16 | #include 17 | #include "imgui.h" // for ImFont* 18 | 19 | #if defined(OFXIMGUI_BACKEND_OPENFRAMEWORKS) 20 | #include "EngineOpenFrameworks.h" 21 | #elif defined (OFXIMGUI_BACKEND_VULKAN) 22 | #include "EngineVk.h" 23 | #elif defined(OFXIMGUI_BACKEND_GLES) 24 | #include "EngineOpenGLES.h" 25 | #elif defined(OFXIMGUI_BACKEND_GLFW) 26 | #include "EngineGLFW.h" 27 | #else 28 | #include "EngineOpenFrameworks.h" 29 | //#error "Sorry, ofxImGui is incorrectly configured, cannot proceed !" 30 | #endif 31 | 32 | //#include "imgui_internal.h" // for ImGuiContext* 33 | 34 | // Notes on context handling in ImGui 35 | // - Ideally, we should create 1 imgui context per ofApp and one host viewports per ofAppBaseWindow, which actually is not possible. 36 | // Related issues: 37 | // - Use of viewports with existing windows : https://github.com/ocornut/imgui/issues/4298 38 | // - Multiple host viewports (solution: 1 context per window) : https://github.com/ocornut/imgui/issues/3012 39 | // - Currently implemented, the easiest way to achieve this is by providing one ImGui context per ofWindow, letting instances draw to it. 40 | // The only drawback of this is that ImGui windows (or other draggables) cannot be moved to the other gui. 41 | // This should not be an issue in most ofApps. Generally in GPU apps it's recommended to keep the GUI to one application window. 42 | 43 | // Todo: We could provide a way to intercept/filter OF mouse clicks when they are used by ImGui ? 44 | 45 | // Todo: count slave instances so only master exits when no more slaves ? 46 | 47 | // Todo: Maybe we could move setup() to main.cpp, or bind it to an ofxImGuiWindow 48 | // This could clarify the setup process by explicitly giving is the window handle. 49 | 50 | 51 | namespace ofxImGui { 52 | class Gui; 53 | } 54 | // A context pointer with some more info. One ofxImGuiContext per ofAppWindow. 55 | struct ofxImGuiContext { 56 | friend class ofxImGui::Gui; 57 | friend struct std::pair; 58 | public: 59 | explicit ofxImGuiContext(std::shared_ptr& _window) : 60 | imguiContext(ImGui::CreateContext()), 61 | ofWindow(_window), 62 | autoDraw(false), 63 | slaveCount(0), 64 | isRenderingFrame(false){} 65 | public: 66 | // Prevent making copies 67 | ofxImGuiContext( const ofxImGuiContext& ) = delete; 68 | ofxImGuiContext& operator=( const ofxImGuiContext& ) = delete; 69 | 70 | // Allow move contructor & move assign 71 | explicit ofxImGuiContext(ofxImGuiContext&& other) noexcept : imguiContext{other.imguiContext}{ 72 | other.imguiContext = nullptr; 73 | //other. = false; 74 | } 75 | // ofxImGuiContext& operator=(ofxImGuiContext&& other) noexcept { 76 | 77 | // } 78 | 79 | ~ofxImGuiContext(){ 80 | if(imguiContext) { 81 | ImGui::DestroyContext(imguiContext); 82 | } 83 | } 84 | 85 | ImGuiContext* imguiContext = nullptr; 86 | std::shared_ptr ofWindow; 87 | bool autoDraw; 88 | 89 | inline bool isShared() const { 90 | return slaveCount > 1; 91 | } 92 | 93 | // Note: Explicit, not to mess with compilers casting it to anything ! 94 | explicit operator bool() const { 95 | return imguiContext != nullptr; 96 | } 97 | bool operator !() const { 98 | return !(bool)this;//imguiContext == nullptr; 99 | } 100 | protected: 101 | unsigned int slaveCount; 102 | bool isRenderingFrame; 103 | 104 | #if defined (OFXIMGUI_BACKEND_OPENFRAMEWORKS) 105 | ofxImGui::EngineOpenFrameworks engine; 106 | #elif defined (OFXIMGUI_BACKEND_VULKAN) 107 | ofxImGui::EngineVk engine; 108 | #elif defined(OFXIMGUI_BACKEND_OPENGLES) 109 | ofxImGui::EngineOpenGLES engine; 110 | #elif defined(OFXIMGUI_BACKEND_GLFW) 111 | ofxImGui::EngineGLFW engine; 112 | #else 113 | ofxImGui::EngineOpenFrameworks engine; 114 | #endif 115 | }; 116 | 117 | namespace ofxImGui 118 | { 119 | enum SetupState : unsigned char { 120 | Error = 0, // Keep to 0 so that it evaluates to false ? 121 | Slave = 1 << 1, 122 | Master = 1 << 2, 123 | // Success flag 124 | Success = Slave | Master, // Use like: if(mState & Success) 125 | }; 126 | std::ostream& operator<<(std::ostream& os, const SetupState& _state); 127 | 128 | class Gui 129 | { 130 | // to provide access to window->context map 131 | friend class BaseEngine; 132 | friend class EngineGLFW; 133 | friend class EngineOpenFrameworks; 134 | public: 135 | Gui(); 136 | ~Gui(); 137 | 138 | // Prevent making copies, prevents making mistakes messing up the gui instances and contexts 139 | Gui( const Gui& ) = delete; 140 | Gui& operator=( const Gui& ) = delete; 141 | 142 | SetupState setup(BaseTheme* theme = nullptr, bool autoDraw = true, ImGuiConfigFlags customFlags_=ImGuiConfigFlags_None, bool _restoreGuiState = false, bool _showImGuiMouseCursor = false ); 143 | SetupState setup(std::shared_ptr& _ofWindow, BaseTheme* theme = nullptr, bool autoDraw = true, ImGuiConfigFlags customFlags_=ImGuiConfigFlags_None, bool _restoreGuiState = false, bool _showImGuiMouseCursor = false ); 144 | void exit(); 145 | 146 | // Todo: remove these ? Adapt them ? 147 | //void setSharedMode(bool _sharedMode=true); 148 | bool isInSharedMode() const; 149 | bool isMaster() const; 150 | 151 | void begin(); 152 | void end(); 153 | 154 | void draw(); 155 | 156 | bool setDefaultFont(int indexAtlasFont); 157 | bool setDefaultFont(ImFont* _atlasFont); 158 | ImFont* addFont(const std::string & fontPath, float fontSize = 13.0f, const ImFontConfig* _fontConfig = nullptr, const ImWchar* _glyphRanges = nullptr, bool _setAsDefaultFont=false ); 159 | ImFont* addFontFromMemory(void* fontData, int fontDataSize, float fontSize = 13.0f, const ImFontConfig* _fontConfig = nullptr, const ImWchar* _glyphRanges = nullptr, bool _setAsDefaultFont=false ); 160 | bool rebuildFontsTexture(); 161 | 162 | void setTheme(BaseTheme* theme); 163 | 164 | GLuint loadImage(ofImage& image); 165 | GLuint loadImage(const std::string& imagePath); 166 | 167 | GLuint loadPixels(const std::string& imagePath); 168 | GLuint loadPixels(ofPixels& pixels); 169 | 170 | GLuint loadTexture(const std::string& imagePath); 171 | GLuint loadTexture(ofTexture& texture, const std::string& imagePath); 172 | // todo: updateFontTexture ? 173 | 174 | void afterDraw(ofEventArgs& _args); // Listener 175 | 176 | // Helper window to debug ofxImGui specific stuff, and provide some hints on your setup. 177 | void drawOfxImGuiDebugWindow(bool* open=nullptr) const; 178 | 179 | // Helper to retrieve the current gui-free zone within the ofAppWindow. 180 | // Basically returns windowRect - MenuBarSpace - SideDocks 181 | ofRectangle getMainWindowViewportRect(bool returnScreenCoords=false, bool removeMenuBar=true, bool removeDockingAreas=true) const; 182 | int getMenuHeight() const; 183 | ofRectangle getDockingViewport() const; 184 | 185 | private: 186 | void render(); 187 | static void initialiseForWindow(); 188 | 189 | //#if defined (OFXIMGUI_FORCE_OF_BACKEND) 190 | // EngineOpenFrameworks engine; 191 | //#elif defined (OF_TARGET_API_VULKAN) 192 | // EngineVk engine; 193 | ////#elif defined(TARGET_OPENGLES) && !defined(TARGET_GLFW_WINDOW) 194 | //// EngineOpenGLES engine; 195 | //#else 196 | // EngineGLFW engine; 197 | //#endif 198 | ofEventListener autoDrawListener; 199 | 200 | BaseTheme* theme=nullptr; // Todo: move this into ofxImguiContext ? 201 | 202 | std::vector loadedTextures; 203 | 204 | ofRectangle dockingViewport; 205 | int menuHeight; 206 | 207 | void updateDockingVp(); 208 | 209 | // Static context instance. All Gui instances share the same context. 210 | // If you're dealing with dynamic libraries, you might need to pass this over to another ImGui instance. 211 | ofxImGuiContext* context = nullptr; // Short-hand value, same as stored in the map, faster access 212 | bool isContextOwned = false; // Copy of context, set when it needs destruction 213 | 214 | //static LinkedList imguiContexts; // Window/MasterContext map 215 | static std::unordered_map imguiContexts; // Window/MasterContext map 216 | }; 217 | } 218 | -------------------------------------------------------------------------------- /src/ImHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ofGLBaseTypes.h" 4 | #include "ofParameter.h" 5 | #include "ofRectangle.h" 6 | #include "ofTexture.h" 7 | #include "ofGLBaseTypes.h" 8 | #include "imgui.h" 9 | #include // Needed for Arch Linux 10 | 11 | #include "gles1CompatibilityHacks.h" // needed on rpi3 for GL_TEXTURE_RECTANGLE 12 | 13 | static const int kImGuiMargin = 10; 14 | 15 | // Todo: ScopedHelpers like in ImGuiMagnumIntegration and Cinder's ImGui 16 | 17 | namespace ofxImGui 18 | { 19 | 20 | bool VectorCombo(const char* label, int* currIndex, std::vector& values); 21 | bool VectorListBox(const char* label, int* currIndex, std::vector& values); 22 | 23 | 24 | struct WindowOpen 25 | { 26 | std::stack> usedNames; 27 | std::shared_ptr> parameter; 28 | bool value; 29 | }; 30 | 31 | struct Settings 32 | { 33 | Settings(); 34 | 35 | ofVec2f windowPos; 36 | ofVec2f windowSize; 37 | bool lockPosition; 38 | 39 | bool mouseOverGui; 40 | bool windowBlock; 41 | int treeLevel; 42 | 43 | ofRectangle totalBounds; 44 | ofRectangle screenBounds; 45 | }; 46 | 47 | static WindowOpen windowOpen; 48 | 49 | bool IsMouseOverGui(); 50 | 51 | const char * GetUniqueName(ofAbstractParameter& parameter); 52 | const char * GetUniqueName(const std::string& candidate); 53 | 54 | void SetNextWindow(Settings& settings); 55 | bool BeginWindow(ofParameter& parameter, Settings& settings, bool collapse = true); 56 | bool BeginWindow(const std::string& name, Settings& settings, bool collapsible = true, bool * open = nullptr); 57 | bool BeginWindow(const std::string& name, Settings& settings, ImGuiWindowFlags flags, bool * open = nullptr); 58 | void EndWindow(Settings& settings); 59 | 60 | bool BeginTree(ofAbstractParameter& parameter, Settings& settings); 61 | bool BeginTree(const std::string& name, Settings& settings); 62 | void EndTree(Settings& settings); 63 | 64 | void AddGroup(ofParameterGroup& group, Settings& settings); 65 | 66 | #if OF_VERSION_MINOR >= 10 67 | bool AddParameter(ofParameter& parameter); 68 | bool AddParameter(ofParameter& parameter); 69 | bool AddParameter(ofParameter& parameter); 70 | 71 | bool AddParameter(ofParameter& parameter); 72 | bool AddParameter(ofParameter& parameter); 73 | bool AddParameter(ofParameter& parameter); 74 | #endif 75 | 76 | bool AddParameter(ofParameter& parameter); 77 | bool AddParameter(ofParameter& parameter); 78 | bool AddParameter(ofParameter& parameter); 79 | bool AddParameter(ofParameter& parameter, bool alpha = true); 80 | bool AddParameter(ofParameter& parameter, bool alpha = true); 81 | 82 | bool AddParameter(ofParameter& parameter, size_t maxChars = 255, bool multiline = false); 83 | 84 | bool AddParameter(ofParameter& parameter, float width = 0); 85 | 86 | template 87 | bool AddParameter(ofParameter& parameter); 88 | 89 | template 90 | bool AddText(ofParameter& parameter, bool label = true); 91 | 92 | bool AddRadio(ofParameter& parameter, std::vector labels, int columns = 1); 93 | bool AddCombo(ofParameter& parameter, std::vector labels); 94 | bool AddStepper(ofParameter& parameter, int step = 1, int stepFast = 100); 95 | 96 | bool AddSlider(ofParameter& parameter, const char* format = "%.3f", bool logarithmic = false); 97 | 98 | bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, int speed = 1); 99 | bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); 100 | #if OF_VERSION_MINOR >= 10 101 | bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); 102 | bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); 103 | bool AddRange(const std::string& name, ofParameter& parameterMin, ofParameter& parameterMax, float speed = 0.01f); 104 | #endif 105 | 106 | #if OF_VERSION_MINOR >= 10 107 | bool AddValues(const std::string& name, std::vector& values, int minValue = 0, int maxValue = 0); 108 | bool AddValues(const std::string& name, std::vector& values, int minValue = 0, int maxValue = 0); 109 | bool AddValues(const std::string& name, std::vector& values, int minValue = 0, int maxValue = 0); 110 | 111 | bool AddValues(const std::string& name, std::vector& values, float minValue = 0, float maxValue = 0); 112 | bool AddValues(const std::string& name, std::vector& values, float minValue = 0, float maxValue = 0); 113 | bool AddValues(const std::string& name, std::vector& values, float minValue = 0, float maxValue = 0); 114 | #endif 115 | 116 | bool AddValues(const std::string& name, std::vector& values, float minValue = 0, float maxValue = 0); 117 | bool AddValues(const std::string& name, std::vector& values, float minValue = 0, float maxValue = 0); 118 | bool AddValues(const std::string& name, std::vector& values, float minValue = 0, float maxValue = 0); 119 | 120 | template 121 | bool AddValues(const std::string& name, std::vector& values, DataType minValue, DataType maxValue); 122 | 123 | void AddImage(const ofBaseHasTexture& hasTexture, const ofVec2f& size); 124 | void AddImage(const ofTexture& texture, const ofVec2f& size); 125 | #if OF_VERSION_MINOR >= 10 126 | void AddImage(const ofBaseHasTexture& hasTexture, const glm::vec2& size); 127 | void AddImage(const ofTexture& texture, const glm::vec2& size); 128 | #endif 129 | } 130 | 131 | static ImTextureID GetImTextureID(const ofTexture& texture) 132 | { 133 | #ifdef TARGET_OPENGLES 134 | if (false) // GLES only has 2d textures ? (to be verified) 135 | #else 136 | if (texture.getTextureData().textureTarget != GL_TEXTURE_2D) 137 | #endif 138 | { 139 | 140 | ofLogWarning("Warning, ImGui only supports drawing textures of type GL_TEXTURE_2D."); 141 | } 142 | return (ImTextureID)(uintptr_t)texture.texData.textureID; 143 | } 144 | 145 | static ImTextureID GetImTextureID(const ofBaseHasTexture& hasTexture) 146 | { 147 | 148 | return GetImTextureID(hasTexture.getTexture()); 149 | } 150 | 151 | static ImTextureID GetImTextureID(GLuint glID) 152 | { 153 | 154 | return (ImTextureID)(uintptr_t)glID; 155 | 156 | } 157 | 158 | //-------------------------------------------------------------- 159 | template 160 | bool ofxImGui::AddParameter(ofParameter& parameter) 161 | { 162 | auto tmpRef = parameter.get(); 163 | const auto& info = typeid(ParameterType); 164 | if (info == typeid(float)) 165 | { 166 | if (ImGui::SliderFloat(GetUniqueName(parameter), (float *)&tmpRef, parameter.getMin(), parameter.getMax())) 167 | { 168 | parameter.set(tmpRef); 169 | return true; 170 | } 171 | return false; 172 | } 173 | if (info == typeid(int)) 174 | { 175 | if (ImGui::SliderInt(GetUniqueName(parameter), (int *)&tmpRef, parameter.getMin(), parameter.getMax())) 176 | { 177 | parameter.set(tmpRef); 178 | return true; 179 | } 180 | return false; 181 | } 182 | if (info == typeid(bool)) 183 | { 184 | if (ImGui::Checkbox(GetUniqueName(parameter), (bool *)&tmpRef)) 185 | { 186 | parameter.set(tmpRef); 187 | return true; 188 | } 189 | return false; 190 | } 191 | 192 | ofLogWarning(__FUNCTION__) << "Could not create GUI element for type " << info.name(); 193 | return false; 194 | } 195 | 196 | //-------------------------------------------------------------- 197 | template 198 | bool ofxImGui::AddText(ofParameter& parameter, bool label) 199 | { 200 | if (label) 201 | { 202 | ImGui::LabelText(parameter.getName().c_str(), ofToString(parameter.get()).c_str()); 203 | } 204 | else 205 | { 206 | ImGui::Text(ofToString(parameter.get()).c_str()); 207 | } 208 | return true; 209 | } 210 | 211 | //-------------------------------------------------------------- 212 | template 213 | bool ofxImGui::AddValues(const std::string& name, std::vector& values, DataType minValue, DataType maxValue) 214 | { 215 | auto result = false; 216 | const auto& info = typeid(DataType); 217 | for (int i = 0; i < values.size(); ++i) 218 | { 219 | const auto iname = name + " " + ofToString(i); 220 | if (info == typeid(float)) 221 | { 222 | result |= ImGui::SliderFloat(GetUniqueName(iname), *values[i], minValue, maxValue); 223 | } 224 | else if (info == typeid(int)) 225 | { 226 | result |= ImGui::SliderInt(GetUniqueName(iname), *values[i], minValue, maxValue); 227 | } 228 | else if (info == typeid(bool)) 229 | { 230 | result |= ImGui::Checkbox(GetUniqueName(iname), *values[i]); 231 | } 232 | else 233 | { 234 | ofLogWarning("Gui::AddValues") << "Could not create GUI element for type " << info.name(); 235 | return false; 236 | } 237 | } 238 | return result; 239 | } 240 | -------------------------------------------------------------------------------- /src/LinkedList.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright Daan de Lange 2023 3 | // 4 | 5 | // A very simple linked list implementation 6 | // Inspired by Mosra/Corrade's LinkedList 7 | // About 10 times faster then a std::map. 8 | // Relatively slow add/remove but very fast to iterate. 9 | // No ownership, just referencing pointers. 10 | 11 | #pragma once 12 | 13 | #include // is_pointer 14 | 15 | // Fwd declaration needed 16 | template 17 | class LinkedList; 18 | 19 | // List Items 20 | template 21 | struct LinkedListItem { 22 | friend class LinkedList; 23 | using DATA_REF = typename std::conditional::value, T_DATA, T_DATA&>::type; 24 | public: 25 | LinkedListItem* const getNext(){ 26 | return next; 27 | }; 28 | T_KEY* const key; 29 | T_DATA data; 30 | //LinkedListItem(T_KEY* _key, DATA_REF _data, LinkedListItem* _next = nullptr) : 31 | // next(_next), key(_key), data(std::move(_data)){} 32 | LinkedListItem(T_KEY* _key, DATA_REF _data, LinkedListItem* _next = nullptr) : 33 | next(_next), key(_key), data(_data){} 34 | 35 | private: 36 | LinkedListItem* next = nullptr; 37 | }; 38 | 39 | // THE list 40 | template 41 | class LinkedList { 42 | public: 43 | LinkedList() : first(nullptr) {} 44 | ~LinkedList(){ 45 | LinkedListItem* item = first; 46 | while(item){ 47 | LinkedListItem* next = item->next; 48 | delete item; 49 | item->next = nullptr; 50 | item = next; 51 | } 52 | first = nullptr; 53 | } 54 | 55 | using DATA_PTR = typename std::conditional::value, T_DATA, T_DATA*>::type; 56 | using DATA_REF = typename std::conditional::value, T_DATA, T_DATA&>::type; 57 | 58 | // Disable copy 59 | LinkedList( const LinkedList& ) = delete; 60 | LinkedList& operator=(const LinkedList&) = delete; 61 | 62 | void add(T_KEY* _key, DATA_REF _data){ 63 | LinkedListItem* last = first; 64 | LinkedListItem* newEntry = new LinkedListItem(_key, _data); 65 | // First entry ? 66 | if(last==nullptr){ 67 | first = newEntry; 68 | return; 69 | } 70 | while(last){ 71 | if(last->getNext()){ 72 | last = last->getNext(); 73 | } 74 | else { 75 | break; 76 | } 77 | } 78 | last->next = newEntry; 79 | } 80 | void remove(T_KEY* _key){ 81 | if(_key==nullptr) return; 82 | LinkedListItem* item = first; 83 | while(item){ 84 | // Replace first with next if it's the first entry 85 | if(item == first && item->key == _key){ 86 | first = item->next; 87 | return; 88 | } 89 | // Replace next of previous-to-item 90 | if(item->next != nullptr && item->next->key == _key){ 91 | item->next = item->next->next; 92 | return; 93 | } 94 | // Incremment 95 | item = item->next; 96 | } 97 | return; 98 | } 99 | 100 | bool hasKey(T_KEY* _key){ 101 | return findData(_key) != nullptr; 102 | } 103 | 104 | DATA_PTR findData(T_KEY* _key){ 105 | if(_key==nullptr) return nullptr; 106 | LinkedListItem* item = first; 107 | while(item){ 108 | if(item->key == _key) return dataToPtr(item->data); 109 | item = item->getNext(); 110 | } 111 | return nullptr; 112 | } 113 | 114 | T_KEY* findKey(DATA_PTR _data){ 115 | if(_data==nullptr) return nullptr; 116 | LinkedListItem* item = first; 117 | while(item){ 118 | if(dataToPtr(item->data) == _data) return item->key; 119 | item = item->getNext(); 120 | } 121 | return nullptr; 122 | } 123 | LinkedListItem* const getFirst(){ 124 | return first; 125 | } 126 | private: 127 | // How verbose is this ?! 128 | template 129 | // static inline typename std::enable_if::value && std::is_same::value, DATA_PTR>::type dataToPtr(C& _v){// getPtr(DATA_TYPE& _v){ 130 | static inline typename std::enable_if::value, DATA_PTR>::type dataToPtr(C& _v){// getPtr(DATA_TYPE& _v){ 131 | return &_v; 132 | } 133 | template 134 | // static inline typename std::enable_if::value && std::is_same::value, DATA_PTR>::type dataToPtr(C _v){ 135 | static inline typename std::enable_if::value, DATA_PTR>::type dataToPtr(C _v){ 136 | return _v; 137 | } 138 | 139 | LinkedListItem* first = nullptr; 140 | }; 141 | -------------------------------------------------------------------------------- /src/gles1CompatibilityHacks.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "ofxImGuiConstants.h" 5 | #if defined (OFXIMGUI_RENDERER_GLES)// && defined (OFXIMGUI_RENDERER_GLES_1) 6 | 7 | // Todo: maybe not all RPIs need this... Anyways, it's only used when GL ES 1 is required, compilation needs to be fixed anyways. 8 | #pragma message "[Notice] Using some GL ES 1.1 compatibility hack for the RPI ! (prefer using at least GL ES 2)" 9 | 10 | // Instead of loading GL, we load GL ES. This is normally not supported by the native DearImGui backend, but it seems to work. 11 | // Openframeworks does support it, so here we hack in support by loading gles1 and providing some dirty fallbacks for unimplemented functionality. 12 | // GLSL ES 1 (fixed pipeline) (OpenGL ES 2.0) is not supported by ImGui, so we try to provide some hacks here. 13 | // 14 | // Note: 15 | // - imgui_impl_opengl2.cpp ( fixed pipeline) --> OpenGL 2.0 and GLES 1 16 | // - imgui_impl_opengl3.cpp (programable pipeline) --> OpenGL 3.0+ and GLES 2+ 17 | 18 | //#ifndef GL_VERSION_1_0 19 | #pragma message "Trying to include on rpi, instead of . If you get errors, please comment the inclusion below." 20 | //#undef __gl_h_ // this forces re-loading GL/gl.h 21 | //#include // --> Original inclusion, on RPIs in /usr/include/GL/gl.h 22 | 23 | // GL ES 1 Includes 24 | #if defined(TARGET_TARGET_LINUX_ARM) || defined(TARGET_RASPBERRY_PI) 25 | #include 26 | #include 27 | #elif defined(TARGET_OF_IOS) 28 | #import 29 | #import 30 | //#import 31 | //#import 32 | #else 33 | // Other : warn about unsupported platform 34 | // If this error throws, there might not be much to do to support them, if your platform supports GLES. 35 | // Note: For GL ES 2 & 3, this file is probably not needed, imgui_impl_opengl2 should be excluded from compilation or compiled pseudo-empty. Best is to support both gles 1 and 2+3 if the platform also supports it. 36 | #error "ofxImGui doesn't know where GLES 1 is located for your platform !" 37 | #endif 38 | 39 | // - - - - - - - - - - 40 | // Compatibility hacks 41 | // - - - - - - - - - - 42 | 43 | // Rpis might want to apt install libmesa-dev or mesa-common-dev... they look already installed here. 44 | 45 | // Todo: Is this still relevant ? 46 | #ifndef GL_VERSION_1_1 47 | #pragma message " was included, but not loaded correctly." 48 | #endif 49 | 50 | // Todo: Is this still relevant ? 51 | #ifdef GL_VERSION_ES_CM_1_0 52 | #pragma message " was loaded somewhere, thus using GL ES 1, which needs some the tweaks below to become GL 1 compilable." 53 | #endif 54 | 55 | #if !defined(GL_VERSION_1_1) && defined(GL_VERSION_ES_CM_1_0) 56 | #pragma message "Hacking GL ES to support GL 1.0, specially for RPIs. ofxImGui might behave weirdly as some GL functions are simply ignored." 57 | // These defines are needed for fixed pipeline (GL ES 1) to compile with the RPI. 58 | // Some have fallbacks, others simply disable the problematic calls. 59 | #define glOrtho glOrthof // Different function name 60 | #define glPolygonMode( X, Y ) // No alternative, but seems not to affect rendering 61 | #define glPushAttrib( X ) // No alternative, but seems not to affect rendering 62 | #define glPopAttrib( X ) 63 | #define GL_POLYGON_MODE GL_LINES 64 | #define GL_FILL 0 // Enabled by default 65 | #endif // !GL_VERSION_1_0 && GL_VERSION_ES_CM_1_0 66 | 67 | // Some defines needed ? 68 | #ifndef GL_TEXTURE_RECTANGLE 69 | #define GL_TEXTURE_RECTANGLE 0 // TODO: find correct value 70 | #endif 71 | 72 | #ifndef GL_VERTEX_ARRAY_BINDING 73 | #define GL_VERTEX_ARRAY_BINDING 0 74 | #endif 75 | 76 | #ifndef GL_ENABLE_BIT 77 | #define GL_ENABLE_BIT 0 78 | #endif 79 | 80 | #ifndef GL_TRANSFORM_BIT 81 | #define GL_TRANSFORM_BIT 0 82 | #endif 83 | 84 | // iOS GLES 2.0 hasn't got GL_UNPACK_ROW_LENGTH 85 | #ifndef GL_UNPACK_ROW_LENGTH 86 | OFXIMGUI_COMPILER_MESSAGE("GLES 2.0 doesn't have GL_UNPACK_ROW_LENGTH, providing a dummy placeholder !") 87 | #define GL_UNPACK_ROW_LENGTH 0 88 | #endif 89 | 90 | #endif // rpi & gles1 91 | -------------------------------------------------------------------------------- /src/glfwCompatibilityHacks.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include "ofxImGuiConstants.h" 5 | #ifdef OFXIMGUI_BACKEND_GLES 6 | 7 | #ifndef GLFW_GAMEPAD_BUTTON_A 8 | #pragma message "Warning, you are using an older GLFW version. Trying to provide some fallbacks." 9 | #endif 10 | 11 | // Dirty: Add support for older GLFW releases (needed for RPi Stretch at least, Glfw 3.2) 12 | // These defines were hardcoded in older releases, but they're easier to read with these nice macros 13 | #ifndef GLFW_GAMEPAD_BUTTON_A 14 | #define GLFW_GAMEPAD_BUTTON_A 0 15 | #endif 16 | #ifndef GLFW_GAMEPAD_BUTTON_B 17 | #define GLFW_GAMEPAD_BUTTON_B 1 18 | #endif 19 | #ifndef GLFW_GAMEPAD_BUTTON_X 20 | #define GLFW_GAMEPAD_BUTTON_X 2 21 | #endif 22 | #ifndef GLFW_GAMEPAD_BUTTON_Y 23 | #define GLFW_GAMEPAD_BUTTON_Y 3 24 | #endif 25 | #ifndef GLFW_GAMEPAD_BUTTON_LEFT_BUMPER 26 | #define GLFW_GAMEPAD_BUTTON_LEFT_BUMPER 4 27 | #endif 28 | #ifndef GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER 29 | #define GLFW_GAMEPAD_BUTTON_RIGHT_BUMPER 5 30 | #endif 31 | #ifndef GLFW_GAMEPAD_BUTTON_BACK 32 | #define GLFW_GAMEPAD_BUTTON_BACK 6 33 | #endif 34 | #ifndef GLFW_GAMEPAD_BUTTON_START 35 | #define GLFW_GAMEPAD_BUTTON_START 7 36 | #endif 37 | #ifndef GLFW_GAMEPAD_BUTTON_GUIDE 38 | #define GLFW_GAMEPAD_BUTTON_GUIDE 8 39 | #endif 40 | #ifndef GLFW_GAMEPAD_BUTTON_LEFT_THUMB 41 | #define GLFW_GAMEPAD_BUTTON_LEFT_THUMB 9 42 | #endif 43 | #ifndef GLFW_GAMEPAD_BUTTON_RIGHT_THUMB 44 | #define GLFW_GAMEPAD_BUTTON_RIGHT_THUMB 10 45 | #endif 46 | #ifndef GLFW_GAMEPAD_BUTTON_DPAD_UP 47 | #define GLFW_GAMEPAD_BUTTON_DPAD_UP 11 48 | #endif 49 | #ifndef GLFW_GAMEPAD_BUTTON_DPAD_RIGHT 50 | #define GLFW_GAMEPAD_BUTTON_DPAD_RIGHT 12 51 | #endif 52 | #ifndef GLFW_GAMEPAD_BUTTON_DPAD_DOWN 53 | #define GLFW_GAMEPAD_BUTTON_DPAD_DOWN 13 54 | #endif 55 | #ifndef GLFW_GAMEPAD_BUTTON_DPAD_LEFT 56 | #define GLFW_GAMEPAD_BUTTON_DPAD_LEFT 14 57 | #endif 58 | #ifndef GLFW_JOYSTICK_1 59 | #define GLFW_JOYSTICK_1 0 60 | #endif 61 | #ifndef GLFW_GAMEPAD_AXIS_LEFT_X 62 | #define GLFW_GAMEPAD_AXIS_LEFT_X 0 63 | #endif 64 | #ifndef GLFW_GAMEPAD_AXIS_LEFT_Y 65 | #define GLFW_GAMEPAD_AXIS_LEFT_Y 1 66 | #endif 67 | #ifndef GLFW_GAMEPAD_AXIS_RIGHT_X 68 | #define GLFW_GAMEPAD_AXIS_RIGHT_X 2 69 | #endif 70 | #ifndef GLFW_GAMEPAD_AXIS_RIGHT_Y 71 | #define GLFW_GAMEPAD_AXIS_RIGHT_Y 3 72 | #endif 73 | #ifndef GLFW_GAMEPAD_AXIS_LEFT_TRIGGER 74 | #define GLFW_GAMEPAD_AXIS_LEFT_TRIGGER 4 75 | #endif 76 | #ifndef GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER 77 | #define GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER 5 78 | #endif 79 | #ifndef GLFW_GAMEPAD_AXIS_LAST 80 | #define GLFW_GAMEPAD_AXIS_LAST GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER 81 | #endif 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /src/ofxImGui.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Todo: try to detect the best settings from the OF compiler flags 4 | 5 | #include "ofxImGuiConstants.h" 6 | #include "imgui.h" 7 | #include "Gui.h" 8 | //#include "ImHelpers.h" // Note: not included anymore by default, include it manually if you need it ! 9 | -------------------------------------------------------------------------------- /src/ofxImGuiConstants.h: -------------------------------------------------------------------------------- 1 | // This file will set all macro defines for ofxImGui. 2 | // You can modify it to quickly suit your needs 3 | // But it's recommended to rather overr-de them using project-scope compiler defines. 4 | 5 | //#pragma once 6 | 7 | // Ensures they are always set (Only set if not forced by user). 8 | 9 | // Flags that you can set : 10 | // #define OFXIMGUI_FORCE_OF_BACKEND --> force-use the simpler OF-based backend 11 | // #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 0|1 --> disable imgui glfw backend modification to allow multiple contexts, for using imgui with multiple ofAppBaseWindows 12 | // #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP 0|1 --> Disable modifications to imgui_impl_glfw, disabling support for using ofxImGui in a multi-windowed-ofApp with viewports enabled. 13 | 14 | // Grab ofConstants 15 | #include "ofConstants.h" 16 | 17 | // OFXIMGUI_DEBUG 18 | #ifndef OFXIMGUI_DEBUG 19 | // Uncomment to enable debugging by default 20 | // Prefer defining it in your project macros. 21 | //#define OFXIMGUI_DEBUG 22 | #endif 23 | 24 | // Additional debug flag 25 | #ifdef OFXIMGUI_DEBUG 26 | // Uncomment to enable by default 27 | //#define OFXIMGUI_DEBUG_MACROS 28 | #else 29 | // Force-disable if debug not set 30 | #undef OFXIMGUI_DEBUG_MACROS 31 | #endif 32 | 33 | // Helper for printing debug messages (only when DEBUG is on) 34 | #ifdef OFXIMGUI_DEBUG_MACROS 35 | #define PRAGMA_MESSAGE(x) _Pragma(#x) 36 | #define OFXIMGUI_COMPILER_MESSAGE(X) PRAGMA_MESSAGE(message X) 37 | #else 38 | #define OFXIMGUI_COMPILER_MESSAGE(X) 39 | #endif 40 | 41 | // Platform backend selection 42 | #if !defined(OFXIMGUI_FORCE_OF_BACKEND) 43 | 44 | // Vulkan support ? 45 | #if defined (OF_TARGET_API_VULKAN) && FALSE // tmp disabled, doesn't work either. Maybe rather implement OF backend with vulkan support 46 | #define OFXIMGUI_LOADED_BACKEND "Vulkan" 47 | #define OFXIMGUI_BACKEND_VULKAN 48 | // Warn Vulkan users 49 | #error "Sorry, there's no tested support for Vulkan yet while it should be very easy to implement" 50 | // See https://github.com/ocornut/imgui/blob/master/backends/imgui_impl_vulkan.h or ImGui_ImplGlfw_InitForVulkan 51 | 52 | // Global condition for GLES platforms. Todo: Check if there are no false positives ? 53 | #elif defined(TARGET_OPENGLES) && !defined(TARGET_GLFW_WINDOW) && FALSE // tmp disabled, doesn't work either. Now we use the OF backend with gles support 54 | #define OFXIMGUI_LOADED_BACKEND "GLES" 55 | #define OFXIMGUI_BACKEND_GLES 56 | #warning "The GLES backend is an ancient relic, proceed with caution." 57 | //#include "EngineOpenGLES.h" 58 | 59 | // Platforms where GLFW is default don't define TARGET_GLFW_WINDOW, so we have to explictly add them 60 | #elif defined(TARGET_GLFW_WINDOW) || (!defined(TARGET_OPENGLES) && (defined(TARGET_LINUX) || defined(TARGET_OSX) || defined(TARGET_WIN32))) 61 | OFXIMGUI_COMPILER_MESSAGE("ofxImGui is compiling with the GLFW platform backend.") 62 | //#include "EngineGLFW.h" 63 | #define OFXIMGUI_LOADED_BACKEND "GLFW" 64 | #define OFXIMGUI_BACKEND_GLFW 65 | #endif 66 | #endif 67 | 68 | // Default backend : openframeworks 69 | #ifndef OFXIMGUI_LOADED_BACKEND 70 | OFXIMGUI_COMPILER_MESSAGE("ofxImGui is compiling with the default openFrameworks backend.") 71 | #define OFXIMGUI_LOADED_BACKEND "OpenFrameworks" 72 | #define OFXIMGUI_BACKEND_OPENFRAMEWORKS 73 | #endif 74 | 75 | // Renderer selection 76 | // - - - - - - - - - - 77 | // GL ES 78 | #if defined(TARGET_OPENGLES) 79 | #define OFXIMGUI_RENDERER_GLES 80 | OFXIMGUI_COMPILER_MESSAGE("ofxImGui is compiling with GL ES renderer support.") 81 | 82 | // Specialisations 83 | // Todo: remove these ? GLES1 is available on all OF gles platforms, so no differenciation is needed 84 | //#ifdef TARGET_RASPBERRY_PI 85 | // #define OFXIMGUI_RENDERER_GLES_1 86 | //#else 87 | // #define OFXIMGUI_RENDERER_GLES_2 88 | //#endif 89 | // Vulkan renderer ? 90 | #elif defined (OF_TARGET_API_VULKAN) 91 | #error "Sorry, ofxImGui doesn't support Vulkan yet. Some works have been done in the past, and ImGui supports it, if you have OF+Vulkan, feel free to have a look or ask questions." 92 | // GL SL (default) 93 | #else 94 | #define OFXIMGUI_RENDERER_GLSL 95 | OFXIMGUI_COMPILER_MESSAGE("ofxImGui is compiling with GL SL renderer support.") 96 | #endif 97 | 98 | // Sanitize backend specific flags 99 | // - - - - - - - - - - - - - - - - 100 | // Sanitize GLFW callback flags which allow interfacing GLFW in different ways. 101 | #ifdef OFXIMGUI_BACKEND_GLFW 102 | // Wondering what all these settings are ? The easiest way is to add `gui.drawOfxImGuiDebugWindow()` to your ofApp and follow instructions ! 103 | 104 | // Retro-compatibility with ±2023 develop versions until commit #9bfb15e 105 | #if INTERCEPT_GLFW_CALLBACKS == 1 106 | // Both 3 used to be enabled with this flag 107 | #ifndef OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS 108 | #define OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS 1 109 | #endif 110 | #ifndef OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 111 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 1 112 | #endif 113 | #ifndef OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP 114 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP 1 115 | #endif 116 | #endif 117 | 118 | // Enabled by default (glfw event binding is more advanced then the ofevents, imgui works beter like this) 119 | #if !defined(OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS) || OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS != 0 120 | #define OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS 1 121 | #endif 122 | 123 | // Bind to GLFW ? 124 | #if OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS == 1 125 | OFXIMGUI_COMPILER_MESSAGE("ofxImGui is binding window events by replacing some OF's GLFW listeners.") 126 | // Shorthand compiler flag 127 | #ifdef OFXIMGUI_GLFW_FIX_MULTICONTEXT 128 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 0 129 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP 1 130 | #else 131 | #if !defined(OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP) || OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP != 0 132 | // You can toggle these lines to change the default value (disabled by default) 133 | //#define OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 1 134 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 0 135 | #endif 136 | 137 | // Enable Multi-context support by default 138 | #if !defined(OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP) || OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP != 0 139 | // You can toggle these lines to change the default value (enabled by default) 140 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP 1 141 | //#define OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP 0 142 | #endif 143 | #endif 144 | // Bind to openFrameworks ? 145 | #else 146 | OFXIMGUI_COMPILER_MESSAGE("ofxImGui is binding window events by listening to the OpenFrameworks events.") 147 | // Sanitize / disable some flags 148 | #ifdef OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS 149 | #undef OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS 150 | #endif 151 | #define OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS 0 152 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 0 153 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP 0 154 | #endif 155 | 156 | // OF Backend 157 | #else 158 | // Disable some GLFW backend related flags 159 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP 0 160 | #define OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP 0 161 | #undef OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS 162 | #endif 163 | 164 | // Prevent using this flag in code 165 | #undef OFXIMGUI_GLFW_FIX_MULTICONTEXT 166 | 167 | // Touch events support ? 168 | // - - - - - - - - - - - - - - - - 169 | // Todo: add explicit compiler flag so devices such as Windows/Linux with TouchScreens can use it too ? 170 | #if defined(TARGET_OF_IOS) || defined(TARGET_ANDROID) 171 | #define OFXIMGUI_TOUCH_EVENTS 172 | #endif 173 | -------------------------------------------------------------------------------- /src/ofxImGuiLoggerChannel.cpp: -------------------------------------------------------------------------------- 1 | #include "ofxImGuiLoggerChannel.h" 2 | 3 | //-------------------------------------------------------------- 4 | 5 | ImGuiTextBuffer& ofxImGui::LoggerChannel::getBuffer(){ 6 | static ImGuiTextBuffer sLogBuffer; // static log buffer for logger channel 7 | return sLogBuffer; 8 | }; 9 | 10 | //-------------------------------------------------------------- 11 | void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, const std::string & message ){ 12 | getBuffer().appendf( "[%s] %s: %s\n", ofGetLogLevelName( level, true ).c_str(), module.c_str(), message.c_str() ); 13 | } 14 | 15 | void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, const char* format, ... ){ 16 | va_list args; 17 | va_start( args, format ); 18 | log( level, module, format, args ); 19 | va_end( args ); 20 | } 21 | 22 | void ofxImGui::LoggerChannel::log( ofLogLevel level, const std::string & module, const char* format, va_list args ){ 23 | getBuffer().appendf( "[%s] %s: ", ofGetLogLevelName( level, true ).c_str(), module.c_str() ); 24 | getBuffer().appendfv( format, args ); 25 | } 26 | 27 | 28 | //-------------------------------------------------------------- 29 | -------------------------------------------------------------------------------- /src/ofxImGuiLoggerChannel.h: -------------------------------------------------------------------------------- 1 | #ifndef GUARD_IM_GUI_LOGGER_CHANNEL 2 | #define GUARD_IM_GUI_LOGGER_CHANNEL 3 | #include "imgui.h" 4 | #include "ofLog.h" 5 | 6 | namespace ofxImGui { 7 | 8 | /// \brief A logger channel that logs its messages to the console. 9 | class LoggerChannel : public ofBaseLoggerChannel 10 | { 11 | public: 12 | 13 | static ImGuiTextBuffer & getBuffer(); 14 | 15 | /// \brief Destroy the console logger channel. 16 | virtual ~LoggerChannel(){}; 17 | void log( ofLogLevel level, const std::string & module, const std::string & message ); 18 | void log( ofLogLevel level, const std::string & module, const char* format, ... ) OF_PRINTF_ATTR( 4, 5 ); 19 | void log( ofLogLevel level, const std::string & module, const char* format, va_list args ); 20 | }; 21 | 22 | } // end namespace ofxImGui 23 | 24 | #endif // IM_GUI_LOGGER_CHANNEL --------------------------------------------------------------------------------