├── .github └── workflows │ ├── linux.yml │ ├── macos.yml │ └── windows.yml ├── .gitignore ├── README.md ├── res └── example.png ├── src └── main.cpp └── xmake.lua /.github/workflows/linux.yml: -------------------------------------------------------------------------------- 1 | name: Linux 2 | 3 | on: 4 | pull_request: 5 | push: 6 | 7 | jobs: 8 | build: 9 | strategy: 10 | matrix: 11 | os: [ubuntu-latest] 12 | kind: [static, shared] 13 | 14 | runs-on: ${{ matrix.os }} 15 | 16 | steps: 17 | - uses: actions/checkout@v1 18 | - uses: xmake-io/github-action-setup-xmake@v1 19 | with: 20 | xmake-version: branch@dev 21 | 22 | - name: Installation 23 | run: | 24 | # TODO we will remove it later 25 | sudo apt-get install -y libgl1-mesa-dev libglu1-mesa-dev 26 | sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 60 27 | sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 60 28 | sudo update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-9 60 29 | sudo update-alternatives --set g++ /usr/bin/g++-9 30 | sudo update-alternatives --set gcc /usr/bin/gcc-9 31 | sudo update-alternatives --set cpp /usr/bin/cpp-9 32 | 33 | - name: Tests 34 | run: | 35 | xmake f -k ${{ matrix.kind }} -y -vD 36 | xmake -vD 37 | 38 | -------------------------------------------------------------------------------- /.github/workflows/macos.yml: -------------------------------------------------------------------------------- 1 | name: macOS 2 | 3 | on: 4 | pull_request: 5 | push: 6 | 7 | jobs: 8 | build: 9 | strategy: 10 | matrix: 11 | os: [macOS-latest] 12 | kind: [static, shared] 13 | 14 | runs-on: ${{ matrix.os }} 15 | 16 | steps: 17 | - uses: actions/checkout@v1 18 | - uses: xmake-io/github-action-setup-xmake@v1 19 | with: 20 | xmake-version: branch@dev 21 | 22 | - name: Tests 23 | run: | 24 | xmake f -k ${{ matrix.kind }} -y -vD 25 | xmake -vD 26 | 27 | -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | name: Windows 2 | 3 | on: 4 | pull_request: 5 | push: 6 | 7 | jobs: 8 | build: 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | os: [windows-latest] 13 | kind: [static, shared] 14 | 15 | runs-on: ${{ matrix.os }} 16 | 17 | steps: 18 | - uses: actions/checkout@v1 19 | - uses: xmake-io/github-action-setup-xmake@v1 20 | with: 21 | xmake-version: branch@dev 22 | 23 | - name: Tests 24 | run: | 25 | xmake f -k ${{ matrix.kind }} -y -vD 26 | xmake -vD 27 | 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xmake cache 2 | .xmake/ 3 | build/ 4 | 5 | # MacOS Cache 6 | .DS_Store 7 | 8 | 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🌱 ImGui Scaffold 2 | 3 | A minimal imgui project template 4 | 5 | ## 🦄 Usage 6 | 7 | Simply click the button below to get started: 8 | 9 | [![Use this template](https://img.shields.io/badge/use%20this%20template-brightgreen.svg?longCache=true&style=for-the-badge)](https://github.com/xmake-examples/imgui-scaffold/generate) 10 | 11 | ## 🔨 Development 12 | 13 | ### 📋 Requirements 14 | 15 | To setup and use the project you will need to have the following tools installed: 16 | - [Xmake](https://xmake.io/) 17 | 18 | ### ⬇️ Installation 19 | 20 | Clone the repository 21 | 22 | ```bash 23 | $ git clone https://github.com/xmake-examples/imgui-scaffold.git 24 | ``` 25 | 26 | Change the working directory to the newly cloned repository: 27 | 28 | ```bash 29 | $ cd imgui-scaffold 30 | ``` 31 | 32 | Run xmake to install the dependencies & build the project: 33 | 34 | ```bash 35 | $ xmake 36 | note: install or modify (m) these packages (pass -y to skip confirm)? 37 | in xmake-repo: 38 | -> imgui v1.85 39 | please input: y (y/n/m) 40 | 41 | => install imgui v1.85 .. ok 42 | [100%]: build ok! 43 | ``` 44 | 45 | Run the project after it has been built: 46 | 47 | ```bash 48 | $ xmake run 49 | ``` 50 | 51 | ![](res/example.png) 52 | -------------------------------------------------------------------------------- /res/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xmake-examples/imgui-scaffold/c450a10fb66301e9f3a80284ab169995d6b7a175/res/example.png -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | // Dear ImGui: standalone example application for GLFW + OpenGL 3, using programmable pipeline 2 | // (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) 3 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 4 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 5 | 6 | #include "imgui.h" 7 | #include "imgui_impl_glfw.h" 8 | #include "imgui_impl_opengl3.h" 9 | #include 10 | #if defined(IMGUI_IMPL_OPENGL_ES2) 11 | #include 12 | #endif 13 | #undef GLFW_INCLUDE_NONE 14 | #include // Will drag system OpenGL headers 15 | 16 | // [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers. 17 | // To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma. 18 | // Your own project should not be affected, as you are likely to link with a newer binary of GLFW that is adequate for your version of Visual Studio. 19 | #if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) 20 | #pragma comment(lib, "legacy_stdio_definitions") 21 | #endif 22 | 23 | static void glfw_error_callback(int error, const char* description) 24 | { 25 | fprintf(stderr, "Glfw Error %d: %s\n", error, description); 26 | } 27 | 28 | int main(int, char**) 29 | { 30 | // Setup window 31 | glfwSetErrorCallback(glfw_error_callback); 32 | if (!glfwInit()) 33 | return 1; 34 | 35 | // Decide GL+GLSL versions 36 | #if defined(IMGUI_IMPL_OPENGL_ES2) 37 | // GL ES 2.0 + GLSL 100 38 | const char* glsl_version = "#version 100"; 39 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 40 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 41 | glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); 42 | #elif defined(__APPLE__) 43 | // GL 3.2 + GLSL 150 44 | const char* glsl_version = "#version 150"; 45 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 46 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 47 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 48 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac 49 | #else 50 | // GL 3.0 + GLSL 130 51 | const char* glsl_version = "#version 130"; 52 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 53 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 54 | //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 55 | //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only 56 | #endif 57 | 58 | // Create window with graphics context 59 | GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", NULL, NULL); 60 | if (window == NULL) 61 | return 1; 62 | glfwMakeContextCurrent(window); 63 | glfwSwapInterval(1); // Enable vsync 64 | 65 | // Setup Dear ImGui context 66 | IMGUI_CHECKVERSION(); 67 | ImGui::CreateContext(); 68 | ImGuiIO& io = ImGui::GetIO(); (void)io; 69 | //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls 70 | //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls 71 | 72 | // Setup Dear ImGui style 73 | ImGui::StyleColorsDark(); 74 | //ImGui::StyleColorsClassic(); 75 | 76 | // Setup Platform/Renderer backends 77 | ImGui_ImplGlfw_InitForOpenGL(window, true); 78 | ImGui_ImplOpenGL3_Init(glsl_version); 79 | 80 | // Load Fonts 81 | // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. 82 | // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. 83 | // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). 84 | // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. 85 | // - Read 'docs/FONTS.md' for more instructions and details. 86 | // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! 87 | //io.Fonts->AddFontDefault(); 88 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); 89 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); 90 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); 91 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); 92 | //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); 93 | //IM_ASSERT(font != NULL); 94 | 95 | // Our state 96 | bool show_demo_window = true; 97 | bool show_another_window = false; 98 | ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); 99 | 100 | // Main loop 101 | while (!glfwWindowShouldClose(window)) 102 | { 103 | // Poll and handle events (inputs, window resize, etc.) 104 | // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. 105 | // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application. 106 | // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. 107 | // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. 108 | glfwPollEvents(); 109 | 110 | // Start the Dear ImGui frame 111 | ImGui_ImplOpenGL3_NewFrame(); 112 | ImGui_ImplGlfw_NewFrame(); 113 | ImGui::NewFrame(); 114 | 115 | // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). 116 | if (show_demo_window) 117 | ImGui::ShowDemoWindow(&show_demo_window); 118 | 119 | // 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window. 120 | { 121 | static float f = 0.0f; 122 | static int counter = 0; 123 | 124 | ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. 125 | 126 | ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) 127 | ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state 128 | ImGui::Checkbox("Another Window", &show_another_window); 129 | 130 | ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f 131 | ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color 132 | 133 | if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated) 134 | counter++; 135 | ImGui::SameLine(); 136 | ImGui::Text("counter = %d", counter); 137 | 138 | ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); 139 | ImGui::End(); 140 | } 141 | 142 | // 3. Show another simple window. 143 | if (show_another_window) 144 | { 145 | ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked) 146 | ImGui::Text("Hello from another window!"); 147 | if (ImGui::Button("Close Me")) 148 | show_another_window = false; 149 | ImGui::End(); 150 | } 151 | 152 | // Rendering 153 | ImGui::Render(); 154 | int display_w, display_h; 155 | glfwGetFramebufferSize(window, &display_w, &display_h); 156 | glViewport(0, 0, display_w, display_h); 157 | glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); 158 | glClear(GL_COLOR_BUFFER_BIT); 159 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 160 | 161 | glfwSwapBuffers(window); 162 | } 163 | 164 | // Cleanup 165 | ImGui_ImplOpenGL3_Shutdown(); 166 | ImGui_ImplGlfw_Shutdown(); 167 | ImGui::DestroyContext(); 168 | 169 | glfwDestroyWindow(window); 170 | glfwTerminate(); 171 | 172 | return 0; 173 | } 174 | -------------------------------------------------------------------------------- /xmake.lua: -------------------------------------------------------------------------------- 1 | add_rules("mode.debug", "mode.release") 2 | 3 | add_requires("imgui", {configs = {glfw_opengl3 = true}}) 4 | 5 | target("imgui-scaffold") 6 | set_kind("binary") 7 | add_files("src/*.cpp") 8 | add_packages("imgui") 9 | set_languages("c++14") 10 | 11 | -- 12 | -- If you want to known more usage about xmake, please see https://xmake.io 13 | -- 14 | -- ## FAQ 15 | -- 16 | -- You can enter the project directory firstly before building project. 17 | -- 18 | -- $ cd projectdir 19 | -- 20 | -- 1. How to build project? 21 | -- 22 | -- $ xmake 23 | -- 24 | -- 2. How to configure project? 25 | -- 26 | -- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release] 27 | -- 28 | -- 3. Where is the build output directory? 29 | -- 30 | -- The default output directory is `./build` and you can configure the output directory. 31 | -- 32 | -- $ xmake f -o outputdir 33 | -- $ xmake 34 | -- 35 | -- 4. How to run and debug target after building project? 36 | -- 37 | -- $ xmake run [targetname] 38 | -- $ xmake run -d [targetname] 39 | -- 40 | -- 5. How to install target to the system directory or other output directory? 41 | -- 42 | -- $ xmake install 43 | -- $ xmake install -o installdir 44 | -- 45 | -- 6. Add some frequently-used compilation flags in xmake.lua 46 | -- 47 | -- @code 48 | -- -- add debug and release modes 49 | -- add_rules("mode.debug", "mode.release") 50 | -- 51 | -- -- add macro defination 52 | -- add_defines("NDEBUG", "_GNU_SOURCE=1") 53 | -- 54 | -- -- set warning all as error 55 | -- set_warnings("all", "error") 56 | -- 57 | -- -- set language: c99, c++11 58 | -- set_languages("c99", "c++11") 59 | -- 60 | -- -- set optimization: none, faster, fastest, smallest 61 | -- set_optimize("fastest") 62 | -- 63 | -- -- add include search directories 64 | -- add_includedirs("/usr/include", "/usr/local/include") 65 | -- 66 | -- -- add link libraries and search directories 67 | -- add_links("tbox") 68 | -- add_linkdirs("/usr/local/lib", "/usr/lib") 69 | -- 70 | -- -- add system link libraries 71 | -- add_syslinks("z", "pthread") 72 | -- 73 | -- -- add compilation and link flags 74 | -- add_cxflags("-stdnolib", "-fno-strict-aliasing") 75 | -- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true}) 76 | -- 77 | -- @endcode 78 | -- 79 | 80 | --------------------------------------------------------------------------------