Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <imgui.h>
- #include <imgui_impl_glfw.h>
- #include <imgui_impl_opengl3.h>
- #include <GLFW/glfw3.h>
- #include <cstdio>
- int main()
- {
- const GLFWerrorfun glfwErrorFun = [](int error, const char* description)
- {
- fprintf(stderr, "Glfw Error %d: %s\n", error, description);
- };
- ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
- // Setup
- glfwSetErrorCallback(glfwErrorFun);
- if (!glfwInit()) {
- return 1;
- }
- const char* glsl_version = "#version 130";
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
- GLFWwindow* window = glfwCreateWindow(640, 480, "Dear ImGui test", nullptr, nullptr);
- if (window == nullptr) {
- puts("Cannot create window. Exiting.");
- return 1;
- }
- glfwMakeContextCurrent(window);
- glfwSwapInterval(1); // Enable Vsync
- // Setup Dear ImGui context
- IMGUI_CHECKVERSION();
- ImGui::CreateContext();
- auto& io = ImGui::GetIO();
- ImGui::StyleColorsDark();
- ImGui_ImplGlfw_InitForOpenGL(window, true);
- ImGui_ImplOpenGL3_Init(glsl_version);
- while(!glfwWindowShouldClose(window)) {
- glfwPollEvents();
- // Start new DearImGui frame
- ImGui_ImplOpenGL3_NewFrame();
- ImGui_ImplGlfw_NewFrame();
- ImGui::NewFrame();
- ImGui::Begin("Modal test"); {
- ImGui::TextUnformatted("Click button to open modal");
- if (ImGui::Button("Here")) {
- ImGui::OpenPopup("Open modal");
- }
- }
- static bool theBooleans = false;
- if (ImGui::BeginPopupModal("Open modal", nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
- ImGui::TextUnformatted("wow");
- ImGui::MenuItem("outside BeginMenu", nullptr, false);
- if (ImGui::BeginMenu("options...")) {
- ImGui::MenuItem("(options)", nullptr, false, false);
- if (ImGui::MenuItem("inside BeginMenu", nullptr, theBooleans)) {
- theBooleans = !theBooleans;
- }
- ImGui::MenuItem("Inside BeginMenu 1", nullptr, false);
- ImGui::EndMenu();
- }
- ImGui::EndPopup();
- }
- ImGui::End();
- ImGui::Render();
- int display_w, display_h;
- glfwGetFramebufferSize(window, &display_w, &display_h);
- glViewport(0, 0, display_w, display_h);
- 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_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
- glfwSwapBuffers(window);
- }
- // Cleanup
- {
- ImGui_ImplOpenGL3_Shutdown();
- ImGui_ImplGlfw_Shutdown();
- ImGui::DestroyContext();
- glfwDestroyWindow(window);
- glfwTerminate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment