|
@@ -15,6 +15,60 @@
|
|
|
#include "vendor/glm/glm.hpp"
|
|
#include "vendor/glm/glm.hpp"
|
|
|
#include "vendor/glm/gtc/matrix_transform.hpp"
|
|
#include "vendor/glm/gtc/matrix_transform.hpp"
|
|
|
|
|
|
|
|
|
|
+#include "vendor/imgui/imgui.h"
|
|
|
|
|
+#include "vendor/imgui/imgui_impl_glfw.h"
|
|
|
|
|
+#include "vendor/imgui/imgui_impl_opengl3.h"
|
|
|
|
|
+
|
|
|
|
|
+void doImguiFrame(ImGuiIO& io)
|
|
|
|
|
+{
|
|
|
|
|
+ static bool show_demo_window = true;
|
|
|
|
|
+ static bool show_another_window = true;
|
|
|
|
|
+ static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
|
|
|
|
+
|
|
|
|
|
+ // 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 create 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 / io.Framerate, io.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();
|
|
|
|
|
+ //}
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
int main(void)
|
|
int main(void)
|
|
|
{
|
|
{
|
|
|
GLFWwindow* window = nullptr;
|
|
GLFWwindow* window = nullptr;
|
|
@@ -39,6 +93,24 @@ int main(void)
|
|
|
glfwMakeContextCurrent(window);
|
|
glfwMakeContextCurrent(window);
|
|
|
glfwSwapInterval(1);
|
|
glfwSwapInterval(1);
|
|
|
|
|
|
|
|
|
|
+ // 初始化 Imgui
|
|
|
|
|
+ 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 样式
|
|
|
|
|
+ ImGui::StyleColorsDark();
|
|
|
|
|
+
|
|
|
|
|
+ // Setup Platform/Renderer backends
|
|
|
|
|
+ ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
|
|
|
+#ifdef __EMSCRIPTEN__
|
|
|
|
|
+ ImGui_ImplGlfw_InstallEmscriptenCallbacks(window, "#canvas");
|
|
|
|
|
+#endif
|
|
|
|
|
+ const char* glsl_version = "#version 330 core";
|
|
|
|
|
+ ImGui_ImplOpenGL3_Init(glsl_version);
|
|
|
|
|
+
|
|
|
if (GLEW_OK != glewInit()) {
|
|
if (GLEW_OK != glewInit()) {
|
|
|
std::cout << "Error: glewInit Faild" << std::endl;
|
|
std::cout << "Error: glewInit Faild" << std::endl;
|
|
|
}
|
|
}
|
|
@@ -111,6 +183,8 @@ int main(void)
|
|
|
//glClear(GL_COLOR_BUFFER_BIT);
|
|
//glClear(GL_COLOR_BUFFER_BIT);
|
|
|
render.Clear();
|
|
render.Clear();
|
|
|
|
|
|
|
|
|
|
+ doImguiFrame(io);
|
|
|
|
|
+
|
|
|
va.Bind();
|
|
va.Bind();
|
|
|
ibo.Bind();
|
|
ibo.Bind();
|
|
|
|
|
|
|
@@ -125,6 +199,10 @@ int main(void)
|
|
|
//GL_CALL(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0));
|
|
//GL_CALL(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0));
|
|
|
render.Draw(va, ibo, shader);
|
|
render.Draw(va, ibo, shader);
|
|
|
|
|
|
|
|
|
|
+ // Rendering
|
|
|
|
|
+ ImGui::Render();
|
|
|
|
|
+ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
|
+
|
|
|
/* Swap front and back buffers */
|
|
/* Swap front and back buffers */
|
|
|
glfwSwapBuffers(window);
|
|
glfwSwapBuffers(window);
|
|
|
|
|
|