├── .gitignore ├── .gitmodules ├── LICENSE.txt ├── CMakeLists.txt ├── libs └── CMakeLists.txt └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .vscode 3 | imgui.ini -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libs/imgui"] 2 | path = libs/imgui 3 | url = https://github.com/ocornut/imgui 4 | [submodule "libs/SDL"] 5 | path = libs/SDL 6 | url = https://github.com/libsdl-org/SDL 7 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020-2021 Pesc0 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 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16.3) 2 | 3 | project(imgui-cmake LANGUAGES C CXX) 4 | 5 | 6 | # Use OpenGLES instead of OpenGL. 7 | #set(USE_GLES ON) 8 | 9 | 10 | # ===== RASPBERRY SPECIFIC ===== 11 | 12 | # Enable if building for Raspberry. This will automatically use GLES instead of GL. 13 | #set(RASPBIAN ON) 14 | 15 | # Link against brcmGLESv2 instead of GLESv2. 16 | # Note that Broadcom drivers are NOT available on the 64-bit version of RaspberrypiOS (aarch64), they're only available on 32-bit (armv7l). 17 | #set(RPI_USE_BROADCOM_DRIVER ON) 18 | 19 | # Enable if your Raspberry supports NEON. Generally from Pi2 onwards this is supported. 20 | # This enables optimizations in the SDL library. 21 | #set(RPI_HAS_NEON ON) 22 | 23 | 24 | add_subdirectory("libs") 25 | 26 | 27 | #=================== EXAMPLE =================== 28 | 29 | if(BUILD_EXAMPLES) 30 | add_executable(example_sdl3_opengl3) 31 | target_sources(example_sdl3_opengl3 PUBLIC ${CMAKE_SOURCE_DIR}/libs/imgui/examples/example_sdl3_opengl3/main.cpp) 32 | target_link_libraries(example_sdl3_opengl3 IMGUI) 33 | set_target_properties(example_sdl3_opengl3 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 34 | endif() -------------------------------------------------------------------------------- /libs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | #=================== IMGUI =================== 4 | 5 | set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/imgui) 6 | add_library(IMGUI STATIC) 7 | 8 | target_sources( IMGUI 9 | PRIVATE 10 | ${IMGUI_DIR}/imgui_demo.cpp 11 | ${IMGUI_DIR}/imgui_draw.cpp 12 | ${IMGUI_DIR}/imgui_tables.cpp 13 | ${IMGUI_DIR}/imgui_widgets.cpp 14 | ${IMGUI_DIR}/imgui.cpp 15 | 16 | PRIVATE 17 | ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp 18 | ${IMGUI_DIR}/backends/imgui_impl_sdl3.cpp 19 | ) 20 | 21 | target_include_directories( IMGUI 22 | PUBLIC ${IMGUI_DIR} 23 | PUBLIC ${IMGUI_DIR}/backends 24 | PUBLIC ${SDL3_DIR}/include 25 | ) 26 | 27 | 28 | if(USE_GLES OR RASPBIAN) 29 | target_compile_definitions(IMGUI PUBLIC -DIMGUI_IMPL_OPENGL_ES2) 30 | 31 | if(RASPBIAN AND RPI_USE_BROADCOM_DRIVER) 32 | set(SDL_UNIX_CONSOLE_BUILD ON) # disable X11 and Wayland 33 | set(SDL_KMSDRM OFF) 34 | set(SDL_VULKAN OFF) 35 | set(SDL_RPI ON) 36 | 37 | target_link_directories(IMGUI PUBLIC /opt/vc/lib) 38 | target_link_libraries(IMGUI PUBLIC brcmGLESv2 brcmEGL) 39 | else() 40 | target_link_libraries(IMGUI PUBLIC GLESv2) 41 | endif() 42 | else() 43 | find_package(OpenGL REQUIRED) 44 | target_link_libraries(IMGUI PUBLIC ${OPENGL_LIBRARIES}) 45 | endif() 46 | 47 | 48 | 49 | #=================== SDL3 =================== 50 | 51 | if(RASPBIAN AND RPI_HAS_NEON) 52 | add_compile_options(-mfpu=neon) 53 | endif() 54 | 55 | set(SDL3_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SDL) 56 | add_subdirectory(${SDL3_DIR}) 57 | 58 | 59 | 60 | target_link_libraries(IMGUI PUBLIC SDL3-shared ${CMAKE_DL_LIBS}) 61 | 62 | 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # imgui-cmake 2 | 3 | Simple project with CMake files to build ImGui's example_sdl_opengl3 on multiple platforms. 4 | The main focus is RaspberryPi support, but this will work just fine on Windows, Mac and Linux. 5 | 6 | To test the example: 7 | ``` 8 | git clone https://github.com/Pesc0/imgui-cmake --recurse-submodules 9 | cd imgui-cmake 10 | #git submodule foreach git pull origin HEAD 11 | mkdir build && cd build 12 | cmake -D BUILD_EXAMPLES=ON .. 13 | cmake --build . -j4 14 | ./example_sdl3_opengl3 15 | ``` 16 | 17 | To add the library to your project simply add to your CMakeLists.txt: 18 | ``` 19 | add_subdirectory("path/to/imgui-cmake") 20 | target_link_libraries(YourTarget IMGUI) 21 | ``` 22 | 23 | 24 | ## Raspberry support 25 | 26 | ### Building 27 | You may need these dependencies: 28 | 29 | ``` 30 | sudo apt install libxext-dev libgles-dev libgles2-mesa-dev libgdm-dev libgbm-dev libdrm-dev libudev-dev libasound2-dev libdbus-1-dev 31 | ``` 32 | 33 | ### GPU acceleration 34 | Regarding graphics, to render on Raspberry we have different options: 35 | - No hardware acceleration, using the Mesa software renderer (slow) 36 | - With GPU acceleration, which can be achieved in two ways (text adapted from [here](https://discourse.libsdl.org/t/sdl2-performances-on-raspberrypi/22992)): 37 | 1. Use the old firmware-side Broadcom driver usually located in ```/opt/vc/lib```. This is an older driver that kind of works, but doesn’t integrate well with X11: you just get one fullscreen window, with or without X11. SDL has the rpi video backend for this driver. You may have to ```export SDL_VIDEODRIVER=rpi``` before running the executable to force SDL to use this backend, which doens't always get automatically selected. ```imgui-cmake``` builds SDL from source since the build in apt repos doesn't have the rpi backend compiled in (VIDEO_RPI option), although this may have been fixed in RaspberrypiOS. Note that Broadcom drivers are **not** available in the 64-bit version of RaspberrypiOS, only the 32-bit one. Broadcom drivers are no longer shipped in RaspberrypiOS: 38 | 39 | ``` 40 | git clone https://github.com/raspberrypi/userland 41 | cd userland 42 | # Build and install 43 | ./buildme 44 | 45 | # You may need to add the following to your shell env 46 | # export LD_LIBRARY_PATH=/opt/vc/lib:$LD_LIBRARY_PATH 47 | ``` 48 | 49 | 2. Use the new vc4 driver by Eric Anholt. Broadcom hired him to write an open source driver that uses open APIs (specifically: It’s a gallium driver). If you activate this driver (which deactivates the older driver), X11 itself and the x11 backend of SDL will get hardware acceleration. This works from X11, Wayland, or starting with SDL 2.0.6 there's a new KMSDRM driver which will make it possible to run SDL applications directly from the console with no display server. To activate this driver use the raspi-config program of the Raspbian distribution. Under “Advanced Options” -> “GL Driver” you can select the “GL (Full KMS)” option. 50 | 51 | It is also reccommended in the [old SDL Raspberry documentation](https://github.com/libsdl-org/SDL/blob/670db4d248d93963ef9d7e7c84daeaaa7e5ed36b/docs/README-raspberrypi.md) to assign 128MB of ram (or more) to the GPU. The document has been [removed](https://github.com/libsdl-org/SDL/commit/96414fa56a4c3e1e2b9d81a611365e1260013e7f) long ago. 52 | 53 | Additional video info 54 | - [here](https://pip.raspberrypi.com/categories/1259-audio-camera-and-display/documents/RP-004341-WP/Troubleshooting-KMS-HDMI-output.pdf) 55 | - [here](https://forums.raspberrypi.com/viewtopic.php?t=310315) 56 | - and [here](https://forums.raspberrypi.com/viewtopic.php?t=317511) 57 | 58 | It seems it is recommended on lower hardware (like the RPi 1 or Zero) to use the broadcom drivers for performance reasons, even if they are old/unsupported. 59 | 60 | If not using `raspi-config` you can manually edit `/boot/config.txt`: 61 | - Set `dtoverlay=vc4-kms-v3d` to select the VC4 KMS driver 62 | - Comment `#dtoverlay=vc4-kms-v3d` to select the broadcom diver 63 | - Do not use the Fake KMS (FKMS) driver. 64 | 65 | ### Compiler notes 66 | In old raspbian there's a bug with the latest versions of the gcc compiler: the `` file has been modified, and the `PATH_MAX` macro is missing. This causes an error when compiling some SDL files. Possible solutions are: 67 | - Use gcc-4.9 or an **earlier** version: when running cmake specify `-D CMAKE_C_COMPILER=gcc-4.9 -D CMAKE_CXX_COMPILER=g++-4.9`. This is not optimal since newer compilers tend to produce better code in general. 68 | - Add `#define PATH_MAX 4096` at the beginning of the broken SDL files, or add the same define in the compiler options, but this is not an elegant solution. 69 | - Use the new RaspberrypiOS, where this issue is not present. 70 | 71 | ### Expected performance 72 | On a Raspberry Pi 0-3 (VideoCore IV) the performance is around 100-130 fps at 1080p for the imgui demo. It can drop down to as low as 30 fps or even less if certain demanding features are being displayed. 73 | 74 | An example of such features is the colored buttons present in the demo under "layout & scrolling -> scrolling" 75 | --------------------------------------------------------------------------------