1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-02-07 04:30:08 +00:00
This commit is contained in:
Bruno Cabral 2025-10-08 16:14:51 +03:00 committed by GitHub
commit 73eb7d1a1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 1506 additions and 189 deletions

82
examples/CMakeLists.txt Normal file
View file

@ -0,0 +1,82 @@
add_subdirectory(example_null)
if ("glfw_opengl2" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_glfw_opengl2)
endif ()
if ("glfw_opengl3" IN_LIST SUPPORTED_BACKENDS
OR "glfw_opengl3_emscripten" IN_LIST SUPPORTED_BACKENDS
)
add_subdirectory(example_glfw_opengl3)
endif ()
if ("glfw_vulkan" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_glfw_vulkan)
endif ()
if ("sdl2_opengl2" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_sdl2_opengl2)
endif ()
if ("sdl2_opengl3" IN_LIST SUPPORTED_BACKENDS
OR "sdl2_opengl3_emscripten" IN_LIST SUPPORTED_BACKENDS
)
add_subdirectory(example_sdl2_opengl3)
endif ()
if ("sdl2_sdlrenderer2" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_sdl2_sdlrenderer2)
endif ()
if ("sdl2_vulkan" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_sdl2_vulkan)
endif ()
if ("sdl3_opengl3" IN_LIST SUPPORTED_BACKENDS
OR "sdl3_opengl3_emscripten" IN_LIST SUPPORTED_BACKENDS
)
add_subdirectory(example_sdl3_opengl3)
endif ()
if ("sdl3_sdlgpu3" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_sdl3_sdlgpu3)
endif ()
if ("sdl3_sdlrenderer3" IN_LIST SUPPORTED_BACKENDS
OR "sdl3_sdlrenderer3_emscripten" IN_LIST SUPPORTED_BACKENDS
)
add_subdirectory(example_sdl3_sdlrenderer3)
endif ()
if ("sdl3_vulkan" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_sdl3_vulkan)
endif ()
if ("allegro5" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_allegro5)
endif ()
if ("glut_opengl2" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_glut_opengl2)
endif ()
if ("android_opengl3" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_android_opengl3)
endif ()
if ("glfw_wgpu_emscripten" IN_LIST SUPPORTED_BACKENDS
OR "glfw_wgpu_dawn" IN_LIST SUPPORTED_BACKENDS
)
add_subdirectory(example_glfw_wgpu)
endif ()
if ("win32_directx9" IN_LIST SUPPORTED_BACKENDS
OR "win64_directx9" IN_LIST SUPPORTED_BACKENDS
)
add_subdirectory(example_win32_directx9)
endif ()
if ("win32_directx10" IN_LIST SUPPORTED_BACKENDS
OR "win64_directx10" IN_LIST SUPPORTED_BACKENDS
)
add_subdirectory(example_win32_directx10)
endif ()
if ("win32_directx11" IN_LIST SUPPORTED_BACKENDS
OR "win64_directx11" IN_LIST SUPPORTED_BACKENDS
)
add_subdirectory(example_win32_directx11)
endif ()
if ("win32_directx12" IN_LIST SUPPORTED_BACKENDS
OR "win64_directx12" IN_LIST SUPPORTED_BACKENDS
)
add_subdirectory(example_win32_directx12)
endif ()
if ("win32_opengl3" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_win32_opengl3)
endif ()
if ("win32_vulkan" IN_LIST SUPPORTED_BACKENDS)
add_subdirectory(example_win32_vulkan)
endif ()

View file

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.23)
project(example_allegro5)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui_alegro imgui::backend_allegro5)

View file

@ -165,7 +165,7 @@
<ClCompile Include="..\..\imgui_tables.cpp" />
<ClCompile Include="..\..\imgui_widgets.cpp" />
<ClCompile Include="..\..\backends\imgui_impl_allegro5.cpp" />
<ClCompile Include="imconfig_allegro5.h" />
<ClCompile Include="..\..\backends\imconfig_allegro5.h" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>

View file

@ -25,7 +25,7 @@
<ClCompile Include="..\..\backends\imgui_impl_allegro5.cpp">
<Filter>sources</Filter>
</ClCompile>
<ClCompile Include="imconfig_allegro5.h">
<ClCompile Include="..\..\backends\imconfig_allegro5.h">
<Filter>sources</Filter>
</ClCompile>
<ClCompile Include="..\..\imgui_tables.cpp">

View file

@ -1,11 +0,0 @@
//-----------------------------------------------------------------------------
// COMPILE-TIME OPTIONS FOR DEAR IMGUI ALLEGRO 5 EXAMPLE
// See imconfig.h for the full template
// Because Allegro doesn't support 16-bit vertex indices, we enable the compile-time option of imgui to use 32-bit indices
//-----------------------------------------------------------------------------
#pragma once
// Use 32-bit vertex indices because Allegro doesn't support 16-bit ones
// This allows us to avoid converting vertices format at runtime
#define ImDrawIdx int

View file

@ -1,40 +1,15 @@
cmake_minimum_required(VERSION 3.6)
cmake_minimum_required(VERSION 3.23)
project(example_android_opengl3)
project(ImGuiExample)
# find_package(imgui REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_library(${PROJECT_NAME} SHARED)
add_library(${CMAKE_PROJECT_NAME} SHARED
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui_demo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui_draw.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui_tables.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../imgui_widgets.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/imgui_impl_android.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../backends/imgui_impl_opengl3.cpp
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
)
target_sources(${PROJECT_NAME}
PUBLIC
FILE_SET HEADERS FILES ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.h
BASE_DIRS ${ANDROID_NDK}/sources/android/native_app_glue
PRIVATE
main.cpp ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
set(CMAKE_SHARED_LINKER_FLAGS
"${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate"
)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
IMGUI_IMPL_OPENGL_ES3
)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../..
${CMAKE_CURRENT_SOURCE_DIR}/../../backends
${ANDROID_NDK}/sources/android/native_app_glue
)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
android
EGL
GLESv3
log
)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_android_opengl3)

View file

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.23)
project(example_glfw_opengl2)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_glfw_opengl2)

View file

@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.23)
project(example_glfw_opengl3)
# find_package(imgui REQUIRED)
if (NOT HAS_IMGUI_EMSCRIPTEN)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_glfw_opengl3)
else ()
add_executable(example_glfw_opengl3_emscripten)
target_sources(example_glfw_opengl3_emscripten PRIVATE main.cpp)
target_link_libraries(example_glfw_opengl3_emscripten PRIVATE imgui::imgui imgui::backend_glfw_opengl3_emscripten)
target_link_options(example_glfw_opengl3_emscripten
PRIVATE
"--shell-file=${CMAKE_CURRENT_SOURCE_DIR}/../libs/emscripten/shell_minimal.html"
"-sMODULARIZE=0"
)
set_target_properties(example_glfw_opengl3_emscripten PROPERTIES OUTPUT_NAME "index")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
if (IMGUI_HTTP_PORT)
set(HTTP_PORT ${IMGUI_HTTP_PORT})
else ()
set(HTTP_PORT 8080)
endif ()
if (IMGUI_HTTP_ADDRESS)
set(HTTP_ADDRESS ${IMGUI_HTTP_ADDRESS})
else ()
set(HTTP_ADDRESS 127.0.0.1)
endif ()
add_custom_target(run_example_glfw_opengl3_emscripten
COMMAND python -m http.server -b ${HTTP_ADDRESS} -d $<TARGET_FILE_DIR:example_glfw_opengl3_emscripten> ${HTTP_PORT}
DEPENDS example_glfw_opengl3_emscripten
COMMENT "Run a python http.server in example_glfw_opengl3_emscripten location http://${HTTP_ADDRESS}:${HTTP_PORT}/"
USES_TERMINAL
)
endif ()

View file

@ -26,7 +26,7 @@
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
#ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#include "emscripten_mainloop_stub.h"
#endif
static void glfw_error_callback(int error, const char* description)

View file

@ -1,47 +1,11 @@
# Example usage:
# mkdir build
# cd build
# cmake -g "Visual Studio 14 2015" ..
cmake_minimum_required(VERSION 3.23)
project(example_glfw_vulkan)
cmake_minimum_required(VERSION 2.8)
project(imgui_example_glfw_vulkan C CXX)
# find_package(imgui REQUIRED)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
endif()
add_executable(${PROJECT_NAME})
set(CMAKE_CXX_STANDARD 11)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVK_PROTOTYPES")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_PROTOTYPES")
# GLFW
if(NOT GLFW_DIR)
set(GLFW_DIR ../../../glfw) # Set this to point to an up-to-date GLFW repo
endif()
option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" OFF)
option(GLFW_BUILD_TESTS "Build the GLFW test programs" OFF)
option(GLFW_BUILD_DOCS "Build the GLFW documentation" OFF)
option(GLFW_INSTALL "Generate installation target" OFF)
option(GLFW_DOCUMENT_INTERNALS "Include internals in documentation" OFF)
add_subdirectory(${GLFW_DIR} binary_dir EXCLUDE_FROM_ALL)
include_directories(${GLFW_DIR}/include)
# Dear ImGui
set(IMGUI_DIR ../../)
include_directories(${IMGUI_DIR} ${IMGUI_DIR}/backends ..)
# Libraries
find_package(Vulkan REQUIRED)
#find_library(VULKAN_LIBRARY
#NAMES vulkan vulkan-1)
#set(LIBRARIES "glfw;${VULKAN_LIBRARY}")
set(LIBRARIES "glfw;Vulkan::Vulkan")
# Use vulkan headers from glfw:
include_directories(${GLFW_DIR}/deps)
file(GLOB sources *.cpp)
add_executable(example_glfw_vulkan ${sources} ${IMGUI_DIR}/backends/imgui_impl_glfw.cpp ${IMGUI_DIR}/backends/imgui_impl_vulkan.cpp ${IMGUI_DIR}/imgui.cpp ${IMGUI_DIR}/imgui_draw.cpp ${IMGUI_DIR}/imgui_demo.cpp ${IMGUI_DIR}/imgui_tables.cpp ${IMGUI_DIR}/imgui_widgets.cpp)
target_link_libraries(example_glfw_vulkan ${LIBRARIES})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_compile_definitions(${PROJECT_NAME} PRIVATE "VK_PROTOTYPES")
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_glfw_vulkan)

View file

@ -1,117 +1,62 @@
# Building for desktop (WebGPU-native) with Dawn:
# 1. git clone https://github.com/google/dawn dawn
# 2. cmake -B build -DIMGUI_DAWN_DIR=dawn
# 3. cmake --build build
# 2. cd dawn
# command 3. will install at <dawn>/cmake-build-debug-clang/install, it takes a while
# 3. CC=clang CXX=clang++ cmake -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" -B cmake-build-debug-clang -S . -DDAWN_ENABLE_INSTALL=ON -DCMAKE_INSTALL_PREFIX=cmake-build-debug-clang/install -DBUILD_SAMPLES=OFF -DDAWN_FETCH_DEPENDENCIES=ON -DDAWN_USE_GLFW=ON -DDAWN_ENABLE_VULKAN=ON -DTINT_BUILD_CMD_TOOLS=OFF -DTINT_BUILD_TESTS=OFF -DDAWN_ENABLE_SPIRV_VALIDATION=OFF
# build ImGui with Dawn
# 4. cmake -B build -DDawn_DIR=<dawn>/cmake-build-debug-clang/install/lib/cmake/Dawn
# 5. cmake --build build --target example_glfw_wgpu_dawn
# The resulting binary will be found at one of the following locations:
# * build/Debug/example_glfw_wgpu[.exe]
# * build/example_glfw_wgpu[.exe]
# * build/Debug/example_glfw_wgpu_dawn[.exe]
# * build/example_glfw_wgpu_dawn[.exe]
# Building for Emscripten:
# 1. Install Emscripten SDK following the instructions: https://emscripten.org/docs/getting_started/downloads.html
# 2. Install Ninja build system
# 3. emcmake cmake -G Ninja -B build
# 3. cmake --build build
# 3. cmake --build build --target example_glfw_wgpu_emscripten
# 4. emrun build/index.html
cmake_minimum_required(VERSION 3.10.2)
project(imgui_example_glfw_wgpu C CXX)
cmake_minimum_required(VERSION 3.23)
project(example_glfw_wgpu)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
endif()
# find_package(imgui REQUIRED)
set(CMAKE_CXX_STANDARD 17) # Dawn requires C++17
if (HAS_IMGUI_DAWN AND 0) # example does not compile with latest Dawn
add_executable(example_glfw_wgpu_dawn)
# Dear ImGui
set(IMGUI_DIR ../../)
target_sources(example_glfw_wgpu_dawn PRIVATE main.cpp)
# Libraries
if(EMSCRIPTEN)
if(EMSCRIPTEN_VERSION VERSION_GREATER_EQUAL "3.1.57")
set(IMGUI_EMSCRIPTEN_GLFW3 "--use-port=contrib.glfw3" CACHE STRING "Choose between --use-port=contrib.glfw3 and -sUSE_GLFW=3 for GLFW implementation (default to --use-port=contrib.glfw3)")
else()
# cannot use contrib.glfw3 prior to 3.1.57
set(IMGUI_EMSCRIPTEN_GLFW3 "-sUSE_GLFW=3" CACHE STRING "Use -sUSE_GLFW=3 for GLFW implementation" FORCE)
endif()
set(LIBRARIES glfw)
add_compile_options(-sDISABLE_EXCEPTION_CATCHING=1 -DIMGUI_DISABLE_FILE_FUNCTIONS=1)
else()
# Dawn wgpu desktop
set(DAWN_FETCH_DEPENDENCIES ON)
set(IMGUI_DAWN_DIR CACHE PATH "Path to Dawn repository")
if (NOT IMGUI_DAWN_DIR)
message(FATAL_ERROR "Please specify the Dawn repository by setting IMGUI_DAWN_DIR")
endif()
target_link_libraries(example_glfw_wgpu_dawn PRIVATE imgui::imgui imgui::backend_glfw_wgpu_dawn)
endif ()
option(DAWN_FETCH_DEPENDENCIES "Use fetch_dawn_dependencies.py as an alternative to using depot_tools" ON)
if (HAS_IMGUI_EMSCRIPTEN)
add_executable(example_glfw_wgpu_emscripten)
# Dawn builds many things by default - disable things we don't need
option(DAWN_BUILD_SAMPLES "Enables building Dawn's samples" OFF)
option(TINT_BUILD_CMD_TOOLS "Build the Tint command line tools" OFF)
option(TINT_BUILD_DOCS "Build documentation" OFF)
option(TINT_BUILD_TESTS "Build tests" OFF)
if (NOT APPLE)
option(TINT_BUILD_MSL_WRITER "Build the MSL output writer" OFF)
endif()
if(WIN32)
option(TINT_BUILD_SPV_READER "Build the SPIR-V input reader" OFF)
option(TINT_BUILD_WGSL_READER "Build the WGSL input reader" ON)
option(TINT_BUILD_GLSL_WRITER "Build the GLSL output writer" OFF)
option(TINT_BUILD_GLSL_VALIDATOR "Build the GLSL output validator" OFF)
option(TINT_BUILD_SPV_WRITER "Build the SPIR-V output writer" OFF)
option(TINT_BUILD_WGSL_WRITER "Build the WGSL output writer" ON)
endif()
target_sources(example_glfw_wgpu_emscripten PRIVATE main.cpp)
add_subdirectory("${IMGUI_DAWN_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/dawn" EXCLUDE_FROM_ALL)
target_link_libraries(example_glfw_wgpu_emscripten PRIVATE imgui::imgui imgui::backend_glfw_wgpu_emscripten)
set(LIBRARIES webgpu_dawn webgpu_cpp webgpu_glfw glfw)
endif()
add_executable(example_glfw_wgpu
main.cpp
# backend files
${IMGUI_DIR}/backends/imgui_impl_glfw.cpp
${IMGUI_DIR}/backends/imgui_impl_wgpu.cpp
# Dear ImGui files
${IMGUI_DIR}/imgui.cpp
${IMGUI_DIR}/imgui_draw.cpp
${IMGUI_DIR}/imgui_demo.cpp
${IMGUI_DIR}/imgui_tables.cpp
${IMGUI_DIR}/imgui_widgets.cpp
)
IF(NOT EMSCRIPTEN)
target_compile_definitions(example_glfw_wgpu PUBLIC
"IMGUI_IMPL_WEBGPU_BACKEND_DAWN"
)
endif()
target_include_directories(example_glfw_wgpu PUBLIC
${IMGUI_DIR}
${IMGUI_DIR}/backends
)
target_link_libraries(example_glfw_wgpu PUBLIC ${LIBRARIES})
# Emscripten settings
if(EMSCRIPTEN)
if("${IMGUI_EMSCRIPTEN_GLFW3}" STREQUAL "--use-port=contrib.glfw3")
target_compile_options(example_glfw_wgpu PUBLIC
"${IMGUI_EMSCRIPTEN_GLFW3}"
set_target_properties(example_glfw_wgpu_emscripten PROPERTIES OUTPUT_NAME "index")
# copy our custom index.html to build directory
add_custom_command(TARGET example_glfw_wgpu_emscripten POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_LIST_DIR}/web/index.html" $<TARGET_FILE_DIR:example_glfw_wgpu_emscripten>
)
endif()
message(STATUS "Using ${IMGUI_EMSCRIPTEN_GLFW3} GLFW implementation")
target_link_options(example_glfw_wgpu PRIVATE
"-sUSE_WEBGPU=1"
"${IMGUI_EMSCRIPTEN_GLFW3}"
"-sWASM=1"
"-sALLOW_MEMORY_GROWTH=1"
"-sNO_EXIT_RUNTIME=0"
"-sASSERTIONS=1"
"-sDISABLE_EXCEPTION_CATCHING=1"
"-sNO_FILESYSTEM=1"
)
set_target_properties(example_glfw_wgpu PROPERTIES OUTPUT_NAME "index")
# copy our custom index.html to build directory
add_custom_command(TARGET example_glfw_wgpu POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_LIST_DIR}/web/index.html" $<TARGET_FILE_DIR:example_glfw_wgpu>
)
endif()
if (IMGUI_HTTP_PORT)
set(HTTP_PORT ${IMGUI_HTTP_PORT})
else ()
set(HTTP_PORT 8080)
endif ()
if (IMGUI_HTTP_ADDRESS)
set(HTTP_ADDRESS ${IMGUI_HTTP_ADDRESS})
else ()
set(HTTP_ADDRESS 127.0.0.1)
endif ()
add_custom_target(run_example_glfw_wgpu_emscripten
COMMAND python -m http.server -b ${HTTP_ADDRESS} -d $<TARGET_FILE_DIR:example_glfw_wgpu_emscripten> ${HTTP_PORT}
DEPENDS example_glfw_wgpu_emscripten
COMMENT "Run a python http.server in example_glfw_wgpu_emscripten location http://${HTTP_ADDRESS}:${HTTP_PORT}/"
USES_TERMINAL
)
endif ()

View file

@ -27,7 +27,7 @@
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
#ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#include "emscripten_mainloop_stub.h"
#endif
// Global WebGPU required states

View file

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.23)
project(example_glut_opengl2)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_glut_opengl2)

View file

@ -0,0 +1,9 @@
# Important: This is a "null backend" application, with no visible output or interaction!
# This is used for testing purpose and continuous integration, and has little use for end-user.
#
add_library(example_null STATIC)
target_sources(example_null PRIVATE main.cpp)
target_link_libraries(example_null PRIVATE imgui::imgui)

View file

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.23)
project(example_sdl2_opengl2)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_sdl2_opengl2)

View file

@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.23)
project(example_sdl2_opengl3)
# find_package(imgui REQUIRED)
if (NOT HAS_IMGUI_EMSCRIPTEN)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_sdl2_opengl3)
else ()
add_executable(example_sdl2_opengl3_emscripten)
target_sources(example_sdl2_opengl3_emscripten PRIVATE main.cpp)
target_link_libraries(example_sdl2_opengl3_emscripten PRIVATE imgui::imgui imgui::backend_sdl2_opengl3_emscripten)
target_link_options(example_sdl2_opengl3_emscripten
PRIVATE
"--shell-file=${CMAKE_CURRENT_SOURCE_DIR}/../libs/emscripten/shell_minimal.html"
"-sMODULARIZE=0"
)
set_target_properties(example_sdl2_opengl3_emscripten PROPERTIES OUTPUT_NAME "index")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
if (IMGUI_HTTP_PORT)
set(HTTP_PORT ${IMGUI_HTTP_PORT})
else ()
set(HTTP_PORT 8080)
endif ()
if (IMGUI_HTTP_ADDRESS)
set(HTTP_ADDRESS ${IMGUI_HTTP_ADDRESS})
else ()
set(HTTP_ADDRESS 127.0.0.1)
endif ()
add_custom_target(run_example_sdl2_opengl3_emscripten
COMMAND python -m http.server -b ${HTTP_ADDRESS} -d $<TARGET_FILE_DIR:example_sdl2_opengl3_emscripten> ${HTTP_PORT}
DEPENDS example_sdl2_opengl3_emscripten
COMMENT "Run a python http.server in example_sdl2_opengl3_emscripten location http://${HTTP_ADDRESS}:${HTTP_PORT}/"
USES_TERMINAL
)
endif ()

View file

@ -23,7 +23,7 @@
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
#ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#include "emscripten_mainloop_stub.h"
#endif
// Main code

View file

@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.23)
project(example_sdl2_sdlrenderer2)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_sdl2_sdlrenderer2)

View file

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.23)
project(example_sdl2_vulkan)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_sdl2_vulkan)

View file

@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.23)
project(example_sdl3_opengl3)
# find_package(imgui REQUIRED)
if (NOT HAS_IMGUI_EMSCRIPTEN)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_sdl3_opengl3)
else ()
add_executable(example_sdl3_opengl3_emscripten)
target_sources(example_sdl3_opengl3_emscripten PRIVATE main.cpp)
target_link_libraries(example_sdl3_opengl3_emscripten PRIVATE imgui::imgui imgui::backend_sdl3_opengl3_emscripten)
target_link_options(example_sdl3_opengl3_emscripten
PRIVATE
"--shell-file=${CMAKE_CURRENT_SOURCE_DIR}/../libs/emscripten/shell_minimal.html"
"-sMODULARIZE=0"
)
set_target_properties(example_sdl3_opengl3_emscripten PROPERTIES OUTPUT_NAME "index")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
if (IMGUI_HTTP_PORT)
set(HTTP_PORT ${IMGUI_HTTP_PORT})
else ()
set(HTTP_PORT 8080)
endif ()
if (IMGUI_HTTP_ADDRESS)
set(HTTP_ADDRESS ${IMGUI_HTTP_ADDRESS})
else ()
set(HTTP_ADDRESS 127.0.0.1)
endif ()
add_custom_target(run_example_sdl3_opengl3_emscripten
COMMAND python -m http.server -b ${HTTP_ADDRESS} -d $<TARGET_FILE_DIR:example_sdl3_opengl3_emscripten> ${HTTP_PORT}
DEPENDS example_sdl3_opengl3_emscripten
COMMENT "Run a python http.server in example_sdl3_opengl3_emscripten location http://${HTTP_ADDRESS}:${HTTP_PORT}/"
USES_TERMINAL
)
endif ()

View file

@ -36,7 +36,7 @@ EMS =
##---------------------------------------------------------------------
# ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
EMS += -s USE_SDL=2
EMS += -s USE_SDL=3
EMS += -s DISABLE_EXCEPTION_CATCHING=1
LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
@ -50,8 +50,9 @@ LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS
# Emscripten allows preloading a file or folder to be accessible at runtime.
# The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts"
# See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html
# (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
USE_FILE_SYSTEM ?= 0
# (Default value is 1. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.)
# Does not compile with USE_FILE_SYSTEM=0
USE_FILE_SYSTEM ?= 1
ifeq ($(USE_FILE_SYSTEM), 0)
LDFLAGS += -s NO_FILESYSTEM=1
CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS

View file

@ -19,7 +19,7 @@
#endif
#ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#include "emscripten_mainloop_stub.h"
#endif
// Main code

View file

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.23)
project(example_sdl3_sdlgpu3)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_sdl3_sdlgpu3)

View file

@ -20,7 +20,7 @@
// This example doesn't compile with Emscripten yet! Awaiting SDL3 support.
#ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#include "emscripten_mainloop_stub.h"
#endif
// Main code

View file

@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 3.23)
project(example_sdl3_sdlrenderer3)
# find_package(imgui REQUIRED)
if (NOT HAS_IMGUI_EMSCRIPTEN)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_sdl3_sdlrenderer3)
else ()
add_executable(example_sdl3_sdlrenderer3_emscripten)
target_sources(example_sdl3_sdlrenderer3_emscripten PRIVATE main.cpp)
target_link_libraries(example_sdl3_sdlrenderer3_emscripten PRIVATE imgui::imgui imgui::backend_sdl3_sdlrenderer3_emscripten)
target_link_options(example_sdl3_sdlrenderer3_emscripten
PRIVATE
"--shell-file=${CMAKE_CURRENT_SOURCE_DIR}/../libs/emscripten/shell_minimal.html"
"-sMODULARIZE=0"
)
set_target_properties(example_sdl3_sdlrenderer3_emscripten PROPERTIES OUTPUT_NAME "index")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
if (IMGUI_HTTP_PORT)
set(HTTP_PORT ${IMGUI_HTTP_PORT})
else ()
set(HTTP_PORT 8080)
endif ()
if (IMGUI_HTTP_ADDRESS)
set(HTTP_ADDRESS ${IMGUI_HTTP_ADDRESS})
else ()
set(HTTP_ADDRESS 127.0.0.1)
endif ()
add_custom_target(run_example_sdl3_sdlrenderer3_emscripten
COMMAND python -m http.server -b ${HTTP_ADDRESS} -d $<TARGET_FILE_DIR:example_sdl3_sdlrenderer3_emscripten> ${HTTP_PORT}
DEPENDS example_sdl3_sdlrenderer3_emscripten
COMMENT "Run a python http.server in example_sdl3_sdlrenderer3_emscripten location http://${HTTP_ADDRESS}:${HTTP_PORT}/"
USES_TERMINAL
)
endif ()

View file

@ -17,7 +17,7 @@
#include <SDL3/SDL.h>
#ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#include "emscripten_mainloop_stub.h"
#endif
// Main code

View file

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.23)
project(example_sdl3_vulkan)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_sdl3_vulkan)

View file

@ -23,7 +23,7 @@
// This example doesn't compile with Emscripten yet! Awaiting SDL3 support.
#ifdef __EMSCRIPTEN__
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#include "emscripten_mainloop_stub.h"
#endif
// Volk headers

View file

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.23)
project(example_win_directx10)
# find_package(imgui REQUIRED)
if (HAS_IMGUI_DIRECTX_10_X86)
add_executable(example_win32_directx10)
target_sources(example_win32_directx10 PRIVATE main.cpp)
target_link_libraries(example_win32_directx10 PRIVATE imgui::imgui imgui::backend_win32_directx10)
endif ()
if (HAS_IMGUI_DIRECTX_10_X64)
add_executable(example_win64_directx10)
target_sources(example_win64_directx10 PRIVATE main.cpp)
target_link_libraries(example_win64_directx10 PRIVATE imgui::imgui imgui::backend_win64_directx10)
endif ()

View file

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.23)
project(example_win_directx11)
# find_package(imgui REQUIRED)
if (HAS_IMGUI_DIRECTX_11_X86)
add_executable(example_win32_directx11)
target_sources(example_win32_directx11 PRIVATE main.cpp)
target_link_libraries(example_win32_directx11 PRIVATE imgui::imgui imgui::backend_win32_directx11)
endif ()
if (HAS_IMGUI_DIRECTX_11_X64)
add_executable(example_win64_directx11)
target_sources(example_win64_directx11 PRIVATE main.cpp)
target_link_libraries(example_win64_directx11 PRIVATE imgui::imgui imgui::backend_win64_directx11)
endif ()

View file

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.23)
project(example_win_directx12)
# find_package(imgui REQUIRED)
if (HAS_IMGUI_DIRECTX_12_X86)
add_executable(example_win32_directx12)
target_sources(example_win32_directx12 PRIVATE main.cpp)
target_link_libraries(example_win32_directx12 PRIVATE imgui::imgui imgui::backend_win32_directx12)
endif ()
if (HAS_IMGUI_DIRECTX_12_X64)
add_executable(example_win64_directx12)
target_sources(example_win64_directx12 PRIVATE main.cpp)
target_link_libraries(example_win64_directx12 PRIVATE imgui::imgui imgui::backend_win64_directx12)
endif ()

View file

@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.23)
project(example_win_directx9)
# find_package(imgui REQUIRED)
if (HAS_IMGUI_DIRECTX_9_X86)
add_executable(example_win32_directx9)
target_sources(example_win32_directx9 PRIVATE main.cpp)
target_link_libraries(example_win32_directx9 PRIVATE imgui::imgui imgui::backend_win32_directx9)
endif ()
if (HAS_IMGUI_DIRECTX_9_X64)
add_executable(example_win64_directx9)
target_sources(example_win64_directx9 PRIVATE main.cpp)
target_link_libraries(example_win64_directx9 PRIVATE imgui::imgui imgui::backend_win64_directx9)
endif ()

View file

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.23)
project(example_win32_opengl3)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_win32_opengl3)

View file

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.23)
project(example_win32_vulkan)
# find_package(imgui REQUIRED)
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui imgui::backend_win32_vulkan)

View file

@ -1,38 +0,0 @@
// What does this file solves?
// - Since Dear ImGui 1.00 we took pride that most of our examples applications had their entire
// main-loop inside the main() function. That's because:
// - It makes the examples easier to read, keeping the code sequential.
// - It permit the use of local variables, making it easier to try things and perform quick
// changes when someone needs to quickly test something (vs having to structure the example
// in order to pass data around). This is very important because people use those examples
// to craft easy-to-past repro when they want to discuss features or report issues.
// - It conveys at a glance that this is a no-BS framework, it won't take your main loop away from you.
// - It is generally nice and elegant.
// - However, comes Emscripten... it is a wonderful and magical tech but it requires a "main loop" function.
// - Only some of our examples would run on Emscripten. Typically the ones rendering with GL or WGPU ones.
// - I tried to refactor those examples but felt it was problematic that other examples didn't follow the
// same layout. Why would the SDL+GL example be structured one way and the SGL+DX11 be structured differently?
// Especially as we are trying hard to convey that using a Dear ImGui backend in an *existing application*
// should requires only a few dozens lines of code, and this should be consistent and symmetrical for all backends.
// - So the next logical step was to refactor all examples to follow that layout of using a "main loop" function.
// This worked, but it made us lose all the nice things we had...
// Since only about 4 examples really need to run with Emscripten, here's our solution:
// - Use some weird macros and capturing lambda to turn a loop in main() into a function.
// - Hide all that crap in this file so it doesn't make our examples unusually ugly.
// As a stance and principle of Dear ImGui development we don't use C++ headers and we don't
// want to suggest to the newcomer that we would ever use C++ headers as this would affect
// the initial judgment of many of our target audience.
// - Technique is based on this idea: https://github.com/ocornut/imgui/pull/2492/
// - The do { } while (0) is to allow our code calling continue in the main loop.
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <functional>
static std::function<void()> MainLoopForEmscriptenP;
static void MainLoopForEmscripten() { MainLoopForEmscriptenP(); }
#define EMSCRIPTEN_MAINLOOP_BEGIN MainLoopForEmscriptenP = [&]() { do
#define EMSCRIPTEN_MAINLOOP_END while (0); }; emscripten_set_main_loop(MainLoopForEmscripten, 0, true)
#else
#define EMSCRIPTEN_MAINLOOP_BEGIN
#define EMSCRIPTEN_MAINLOOP_END
#endif