#include "imgui.h" #include "imgui_impl_glfw.h" #include "imgui_impl_opengl3.h" #include static void glfw_error_callback(int error, const char* description) { fprintf(stderr, "Glfw Error %d: %s\n", error, description); } int main(int, char**) { // Setup window glfwSetErrorCallback(glfw_error_callback); if (!glfwInit()) return -1; const char* glsl_version = "#version 130"; GLFWwindow* window = glfwCreateWindow(1280, 720, "Login Form", NULL, NULL); if (window == NULL) return -1; glfwMakeContextCurrent(window); glfwSwapInterval(1); // Enable vsync // Initialize OpenGL loader (GLAD in this case) if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { fprintf(stderr, "Failed to initialize OpenGL loader!\n"); return -1; } // Setup Dear ImGui context IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; // Setup Dear ImGui style ImGui::StyleColorsDark(); // Setup Platform/Renderer bindings ImGui_ImplGlfw_InitForOpenGL(window, true); ImGui_ImplOpenGL3_Init(glsl_version); char email[128] = ""; char password[128] = ""; bool show_login_window = true; while (!glfwWindowShouldClose(window)) { // Poll and handle events glfwPollEvents(); // Start the ImGui frame ImGui_ImplOpenGL3_NewFrame(); ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); if (show_login_window) { ImGui::Begin("Sign In", &show_login_window, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove); ImGui::SetWindowSize(ImVec2(400, 200)); ImGui::SetWindowPos(ImVec2((1280 - 400) / 2, (720 - 200) / 2)); ImGui::Text("Email"); ImGui::InputText("##email", email, IM_ARRAYSIZE(email)); ImGui::Text("Password"); ImGui::InputText("##password", password, IM_ARRAYSIZE(password), ImGuiInputTextFlags_Password); if (ImGui::Button("Sign in")) { // Handle sign in } ImGui::End(); } // Rendering ImGui::Render(); int display_w, display_h; glfwGetFramebufferSize(window, &display_w, &display_h); glViewport(0, 0, display_w, display_h); glClearColor(0.45f, 0.55f, 0.60f, 1.00f); glClear(GL_COLOR_BUFFER_BIT); ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); glfwSwapBuffers(window); } // Cleanup ImGui_ImplOpenGL3_Shutdown(); ImGui_ImplGlfw_Shutdown(); ImGui::DestroyContext(); glfwDestroyWindow(window); glfwTerminate(); return 0; }