When I try to debug in Visual Studio 2022 as Release x64, I receive this error:
Obs.: idk where the code is getting the “GLFW.obj” object from
Build started…
1>------ Build started: Project: STReslo_ImGui_GLFW, Configuration: Release x64 ------
1>LINK : fatal error LNK1181: cannot open input file ‘D:\C++\STReslo_ImGui_GLFW\STReslo_ImGui_GLFW\GLFW.obj’
1>Done building project “STReslo_ImGui_GLFW.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Elapsed 00:00.177 ==========
Code:
#include <iostream>
#include <fstream>
#include <string>
//ImGui
#include "Imgui/imgui.h"
#include "Imgui/imgui_impl_glfw.h"
#include "Imgui/imgui_impl_opengl3.h"
//GLFW
#include "GLFW/glfw3.h"
const std::string filename = "login_data.json";
void SaveLoginData(const std::string& username, const std::string& password, bool rememberPassword) {
std::ofstream file(filename);
if (file.is_open()) {
file << username << std::endl;
if (rememberPassword) {
file << password << std::endl;
}
else {
file << " " << std::endl; // Save an empty line if not remembering password
}
file.close();
}
}
bool LoadLoginData(std::string& username, std::string& password) {
std::ifstream file(filename);
if (file.is_open()) {
std::getline(file, username);
std::getline(file, password);
file.close();
return true;
}
return false;
}
int main() {
// Initialize GLFW and OpenGL context
glfwInit();
GLFWwindow* window = glfwCreateWindow(400, 200, "Login Screen", NULL, NULL);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
// Setup ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
(void)io;
ImGui::StyleColorsDark();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 330 core");
char username[256] = { 0 };
char password[256] = { 0 };
bool rememberPassword = false;
bool loggedIn = false;
// Load login data if available
std::string loadedUsername, loadedPassword;
if (LoadLoginData(loadedUsername, loadedPassword)) {
rememberPassword = true;
strncpy_s(username, sizeof(username), loadedUsername.c_str(), _TRUNCATE);
strncpy_s(password, sizeof(password), loadedPassword.c_str(), _TRUNCATE);
}
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
// Start the ImGui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Create the login window
ImGui::Begin("Login");
ImGui::Text("Username:");
ImGui::InputText("##Username", username, sizeof(username));
ImGui::Text("Password:");
if (ImGui::Button("Show Password")) {
ImGui::InputText("##Password", password, sizeof(password));
}
else {
ImGui::InputText("##Password", password, sizeof(password), ImGuiInputTextFlags_Password);
}
ImGui::Checkbox("Remember Password", &rememberPassword);
if (ImGui::Button("Login")) {
// Perform login validation here (e.g., check username and password against a database)
if (strlen(username) > 0 && strlen(password) > 0) {
SaveLoginData(username, password, rememberPassword);
loggedIn = true;
}
}
ImGui::End();
// End the ImGui frame
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);
if (loggedIn) {
// Add your logic here for what to do after successful login
break; // Exit the loop after successful login for this example
}
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}