Skip to content

Commit ecf4218

Browse files
authored
Merge pull request #20 from iwatake2222/feature-#8-include_dear_imgui
Feature #8 include dear imgui
2 parents 0cbd182 + 6ec00c5 commit ecf4218

File tree

5 files changed

+124
-4
lines changed

5 files changed

+124
-4
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@
44
[submodule "desktop/test/third_party/googletest"]
55
path = desktop/test/third_party/googletest
66
url = https://github.com/google/googletest
7+
[submodule "desktop/third_party/imgui"]
8+
path = desktop/third_party/imgui
9+
url = https://github.com/ocornut/imgui

NOTICE.md

+31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
## Dear ImGui
2+
- https://github.com/ocornut/imgui
3+
- Copyright (c) 2014-2022 Omar Cornut
4+
- Licensed under the MIT License (MIT)
5+
- Modification: No
6+
- This project uses ImGui and contains source code of ImGui as git submodule
7+
8+
```
9+
The MIT License (MIT)
10+
11+
Copyright (c) 2014-2022 Omar Cornut
12+
13+
Permission is hereby granted, free of charge, to any person obtaining a copy
14+
of this software and associated documentation files (the "Software"), to deal
15+
in the Software without restriction, including without limitation the rights
16+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17+
copies of the Software, and to permit persons to whom the Software is
18+
furnished to do so, subject to the following conditions:
19+
20+
The above copyright notice and this permission notice shall be included in all
21+
copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29+
SOFTWARE.
30+
```
31+
132
## GLFW
233
- https://github.com/glfw/glfw
334
- Copyright (c) 2002-2006 Marcus Geelnard

desktop/CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ add_subdirectory("${GLEW_DIR}/build/cmake/" glew)
3333
target_link_libraries(${ProjectName} glew_s)
3434
target_include_directories(${ProjectName} PUBLIC "${GLEW_DIR}/include/")
3535

36+
# For ImGui (reference: example_glfw_opengl3/Makefile)
37+
set(IMGUI_DIR "${CMAKE_CURRENT_LIST_DIR}/third_party/imgui/")
38+
target_sources(${ProjectName} PRIVATE
39+
${IMGUI_DIR}/imgui.cpp
40+
${IMGUI_DIR}/imgui_demo.cpp
41+
${IMGUI_DIR}/imgui_draw.cpp
42+
${IMGUI_DIR}/imgui_tables.cpp
43+
${IMGUI_DIR}/imgui_widgets.cpp
44+
${IMGUI_DIR}/backends/imgui_impl_glfw.cpp
45+
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
46+
)
47+
target_include_directories(${ProjectName} PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends)
48+
3649
# Add test module
3750
option(BUILD_TESTS "BUILD_TESTS" ON)
3851
if (BUILD_TESTS)

desktop/main.cpp

+76-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ limitations under the License.
2222
#include <GL/glew.h> /* this must be before including glfw*/
2323
#include <GLFW/glfw3.h>
2424

25+
/* for ImGui */
26+
#include "imgui.h"
27+
#include "imgui_impl_glfw.h"
28+
#include "imgui_impl_opengl3.h"
29+
2530
/*** Macro ***/
2631
/* macro functions */
2732
#define RUN_CHECK(x) \
@@ -55,17 +60,84 @@ int main(int argc, char *argv[])
5560
/* Ensure not to miss input */
5661
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
5762

58-
/* Dark blue background */
59-
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
60-
63+
/* Initialize ImGui */
64+
/* imgui: Setup Dear ImGui context */
65+
IMGUI_CHECKVERSION();
66+
ImGui::CreateContext();
67+
ImGuiIO& io = ImGui::GetIO(); (void)io;
68+
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
69+
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
70+
71+
/* imgui: Setup Dear ImGui style */
72+
ImGui::StyleColorsDark();
73+
//ImGui::StyleColorsClassic();
74+
75+
/* imgui: Setup Platform/Renderer backends */
76+
ImGui_ImplGlfw_InitForOpenGL(window, true);
77+
ImGui_ImplOpenGL3_Init("#version 130");
78+
79+
/* imgui: state */
80+
bool show_demo_window = true;
81+
bool show_another_window = false;
82+
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
83+
84+
6185
/*** Start loop ***/
6286
while(1) {
87+
glfwPollEvents();
88+
89+
/* imgui: Start the Dear ImGui frame */
90+
ImGui_ImplOpenGL3_NewFrame();
91+
ImGui_ImplGlfw_NewFrame();
92+
ImGui::NewFrame();
93+
94+
// 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!).
95+
if (show_demo_window)
96+
ImGui::ShowDemoWindow(&show_demo_window);
97+
98+
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
99+
{
100+
static float f = 0.0f;
101+
static int counter = 0;
102+
103+
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
104+
105+
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
106+
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
107+
ImGui::Checkbox("Another Window", &show_another_window);
108+
109+
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
110+
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
111+
112+
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
113+
counter++;
114+
ImGui::SameLine();
115+
ImGui::Text("counter = %d", counter);
116+
117+
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
118+
ImGui::End();
119+
}
120+
121+
// 3. Show another simple window.
122+
if (show_another_window)
123+
{
124+
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)
125+
ImGui::Text("Hello from another window!");
126+
if (ImGui::Button("Close Me"))
127+
show_another_window = false;
128+
ImGui::End();
129+
}
130+
63131
/* Clear the screen */
132+
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
64133
glClear(GL_COLOR_BUFFER_BIT);
65134

135+
/* imgui: Rendering */
136+
ImGui::Render();
137+
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
138+
66139
/* Swap buffers */
67140
glfwSwapBuffers(window);
68-
glfwPollEvents();
69141

70142
/* Check if the ESC key was pressed or the window was closed */
71143
if (glfwWindowShouldClose(window) != 0 || glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {

desktop/third_party/imgui

Submodule imgui added at 512c54b

0 commit comments

Comments
 (0)