basic imgui integration
This commit is contained in:
@@ -4,3 +4,6 @@
|
||||
[submodule "lib/easyloggingpp"]
|
||||
path = lib/easyloggingpp
|
||||
url = git@github.com:amrayn/easyloggingpp.git
|
||||
[submodule "lib/imgui"]
|
||||
path = lib/imgui
|
||||
url = git@github.com:ocornut/imgui.git
|
||||
|
||||
@@ -11,10 +11,23 @@ include_directories("src/")
|
||||
include_directories("gl/include")
|
||||
include_directories("lib/easyloggingpp/src")
|
||||
add_subdirectory(lib/glm EXCLUDE_FROM_ALL)
|
||||
include_directories("lib/imgui")
|
||||
include_directories("lib/imgui/backends")
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(src/animation)
|
||||
add_subdirectory(src/demo)
|
||||
|
||||
set(SOURCE
|
||||
${SOURCE}
|
||||
${CMAKE_SOURCE_DIR}/lib/imgui/imgui.cpp
|
||||
${CMAKE_SOURCE_DIR}/lib/imgui/imgui_demo.cpp
|
||||
${CMAKE_SOURCE_DIR}/lib/imgui/imgui_draw.cpp
|
||||
${CMAKE_SOURCE_DIR}/lib/imgui/imgui_tables.cpp
|
||||
${CMAKE_SOURCE_DIR}/lib/imgui/imgui_widgets.cpp
|
||||
${CMAKE_SOURCE_DIR}/lib/imgui/backends/imgui_impl_glfw.cpp
|
||||
${CMAKE_SOURCE_DIR}/lib/imgui/backends/imgui_impl_opengl3.cpp
|
||||
)
|
||||
|
||||
add_executable(demo main.cpp gl/src/glad.c ${SOURCE} lib/easyloggingpp/src/easylogging++.cc)
|
||||
target_link_libraries(demo glfw OpenGL::GL)
|
||||
Submodule
+1
Submodule lib/imgui added at 04689979b4
@@ -1,5 +1,9 @@
|
||||
#include <memory>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
|
||||
#include "peripherals_glfw.h"
|
||||
#include "demo/demo_engine.h"
|
||||
#include "timer.h"
|
||||
@@ -208,8 +212,49 @@ int main() {
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplGlfw_InitForOpenGL(((peripherals_glfw*)&peripherals)->get_window(), true);
|
||||
ImGui_ImplOpenGL3_Init("#version 150");
|
||||
|
||||
timer timer1;
|
||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||
bool show_demo_window = false;
|
||||
bool show_another_window = false;
|
||||
|
||||
while (!peripherals.should_close() && timer1.seconds_since_start() < DEMO_LENGTH_IN_SECONDS) {
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
double elapsedSeconds = timer1.seconds_since_start();
|
||||
bigSphere->mesh_ = mesh_generator::extrude(mesh_generator::sphere(50, 50), {200, 201, 100, 101, 400, 401}, 0.05,
|
||||
(int) ((sin(elapsedSeconds) + 0.5) * 40));
|
||||
@@ -231,6 +276,9 @@ int main() {
|
||||
demoPartClear.process(demoPartClear.normalizeTime(elapsedSeconds));
|
||||
demoPartScene.process(demoPartScene.normalizeTime(elapsedSeconds));
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
peripherals.swap_buffers();
|
||||
peripherals.poll_events();
|
||||
}
|
||||
|
||||
@@ -72,4 +72,8 @@ bool peripherals_glfw::should_close() {
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
GLFWwindow *peripherals_glfw::get_window() const {
|
||||
return window;
|
||||
}
|
||||
|
||||
END_NAMESPACE
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
void swap_buffers() override;
|
||||
void poll_events() override;
|
||||
bool should_close() override;
|
||||
GLFWwindow* get_window() const;
|
||||
|
||||
::GLFWwindow *window;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user