Skip to content

Commit

Permalink
Merge pull request #20 from iwatake2222/feature-#8-include_dear_imgui
Browse files Browse the repository at this point in the history
Feature #8 include dear imgui
  • Loading branch information
iwatake2222 authored Jan 6, 2022
2 parents 0cbd182 + 6ec00c5 commit ecf4218
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "desktop/test/third_party/googletest"]
path = desktop/test/third_party/googletest
url = https://github.com/google/googletest
[submodule "desktop/third_party/imgui"]
path = desktop/third_party/imgui
url = https://github.com/ocornut/imgui
31 changes: 31 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
## Dear ImGui
- https://github.com/ocornut/imgui
- Copyright (c) 2014-2022 Omar Cornut
- Licensed under the MIT License (MIT)
- Modification: No
- This project uses ImGui and contains source code of ImGui as git submodule

```
The MIT License (MIT)
Copyright (c) 2014-2022 Omar Cornut
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:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
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.
```

## GLFW
- https://github.com/glfw/glfw
- Copyright (c) 2002-2006 Marcus Geelnard
Expand Down
13 changes: 13 additions & 0 deletions desktop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ add_subdirectory("${GLEW_DIR}/build/cmake/" glew)
target_link_libraries(${ProjectName} glew_s)
target_include_directories(${ProjectName} PUBLIC "${GLEW_DIR}/include/")

# For ImGui (reference: example_glfw_opengl3/Makefile)
set(IMGUI_DIR "${CMAKE_CURRENT_LIST_DIR}/third_party/imgui/")
target_sources(${ProjectName} PRIVATE
${IMGUI_DIR}/imgui.cpp
${IMGUI_DIR}/imgui_demo.cpp
${IMGUI_DIR}/imgui_draw.cpp
${IMGUI_DIR}/imgui_tables.cpp
${IMGUI_DIR}/imgui_widgets.cpp
${IMGUI_DIR}/backends/imgui_impl_glfw.cpp
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
)
target_include_directories(${ProjectName} PUBLIC ${IMGUI_DIR} ${IMGUI_DIR}/backends)

# Add test module
option(BUILD_TESTS "BUILD_TESTS" ON)
if (BUILD_TESTS)
Expand Down
80 changes: 76 additions & 4 deletions desktop/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ limitations under the License.
#include <GL/glew.h> /* this must be before including glfw*/
#include <GLFW/glfw3.h>

/* for ImGui */
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"

/*** Macro ***/
/* macro functions */
#define RUN_CHECK(x) \
Expand Down Expand Up @@ -55,17 +60,84 @@ int main(int argc, char *argv[])
/* Ensure not to miss input */
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

/* Dark blue background */
glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

/* Initialize ImGui */
/* imgui: Setup Dear ImGui context */
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls

/* imgui: Setup Dear ImGui style */
ImGui::StyleColorsDark();
//ImGui::StyleColorsClassic();

/* imgui: Setup Platform/Renderer backends */
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 130");

/* imgui: state */
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);


/*** Start loop ***/
while(1) {
glfwPollEvents();

/* imgui: Start the Dear ImGui frame */
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();

// 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!).
if (show_demo_window)
ImGui::ShowDemoWindow(&show_demo_window);

// 2. Show a simple window that we create ourselves. We use a Begin/End pair to created a named window.
{
static float f = 0.0f;
static int counter = 0;

ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.

ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
ImGui::Checkbox("Another Window", &show_another_window);

ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color

if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
counter++;
ImGui::SameLine();
ImGui::Text("counter = %d", counter);

ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
}

// 3. Show another simple window.
if (show_another_window)
{
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)
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
ImGui::End();
}

/* Clear the screen */
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);

/* imgui: Rendering */
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

/* Swap buffers */
glfwSwapBuffers(window);
glfwPollEvents();

/* Check if the ESC key was pressed or the window was closed */
if (glfwWindowShouldClose(window) != 0 || glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
Expand Down
1 change: 1 addition & 0 deletions desktop/third_party/imgui
Submodule imgui added at 512c54

0 comments on commit ecf4218

Please sign in to comment.