41 glfwSetErrorCallback(glfw_error_callback);
46#if defined(IMGUI_IMPL_OPENGL_ES2)
48 const char* glsl_version =
"#version 100";
49 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
50 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
51 glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
52#elif defined(__APPLE__)
54 const char* glsl_version =
"#version 150";
55 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
56 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
57 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
58 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
61 const char* glsl_version =
"#version 130";
62 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
63 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
69 GLFWwindow* window = glfwCreateWindow(1280, 720,
"Dear ImGui GLFW+OpenGL3 example", NULL, NULL);
72 glfwMakeContextCurrent(window);
77 ImGui::CreateContext();
78 ImGuiIO& io = ImGui::GetIO(); (void)io;
79 io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
81 io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
82 io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
87 ImGui::StyleColorsDark();
91 ImGuiStyle& style = ImGui::GetStyle();
92 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
94 style.WindowRounding = 0.0f;
95 style.Colors[ImGuiCol_WindowBg].w = 1.0f;
99 ImGui_ImplGlfw_InitForOpenGL(window,
true);
100 ImGui_ImplOpenGL3_Init(glsl_version);
118 bool show_demo_window =
true;
119 bool show_another_window =
false;
120 ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
123 while (!glfwWindowShouldClose(window))
133 ImGui_ImplOpenGL3_NewFrame();
134 ImGui_ImplGlfw_NewFrame();
138 if (show_demo_window)
139 ImGui::ShowDemoWindow(&show_demo_window);
143 static float f = 0.0f;
144 static int counter = 0;
146 ImGui::Begin(
"Hello, world!");
148 ImGui::Text(
"This is some useful text.");
149 ImGui::Checkbox(
"Demo Window", &show_demo_window);
150 ImGui::Checkbox(
"Another Window", &show_another_window);
152 ImGui::SliderFloat(
"float", &f, 0.0f, 1.0f);
153 ImGui::ColorEdit3(
"clear color", (
float*)&clear_color);
155 if (ImGui::Button(
"Button"))
158 ImGui::Text(
"counter = %d", counter);
160 ImGui::Text(
"Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
165 if (show_another_window)
167 ImGui::Begin(
"Another Window", &show_another_window);
168 ImGui::Text(
"Hello from another window!");
169 if (ImGui::Button(
"Close Me"))
170 show_another_window =
false;
176 int display_w, display_h;
177 glfwGetFramebufferSize(window, &display_w, &display_h);
178 glViewport(0, 0, display_w, display_h);
179 glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
180 glClear(GL_COLOR_BUFFER_BIT);
181 ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
186 if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
188 GLFWwindow* backup_current_context = glfwGetCurrentContext();
189 ImGui::UpdatePlatformWindows();
190 ImGui::RenderPlatformWindowsDefault();
191 glfwMakeContextCurrent(backup_current_context);
194 glfwSwapBuffers(window);
198 ImGui_ImplOpenGL3_Shutdown();
199 ImGui_ImplGlfw_Shutdown();
200 ImGui::DestroyContext();
202 glfwDestroyWindow(window);
int imgui_main(int argc, char *argv[])
Definition imgui_main.h:38