2025-07-15 03:08:42 +03:00
|
|
|
#include <glad/glad.h>
|
|
|
|
|
#include <GLFW/glfw3.h>
|
2025-07-15 20:25:08 +03:00
|
|
|
|
2025-07-15 19:43:51 +03:00
|
|
|
#include <imgui.h>
|
|
|
|
|
#include <imgui_impl_glfw.h>
|
|
|
|
|
#include <imgui_impl_opengl3.h>
|
2025-07-15 20:25:08 +03:00
|
|
|
#include <iostream>
|
2025-07-15 03:08:42 +03:00
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
std::cout << "Hello working!" << std::endl;
|
2025-07-15 20:42:47 +03:00
|
|
|
|
2025-07-15 19:43:51 +03:00
|
|
|
|
2025-07-15 03:08:42 +03:00
|
|
|
glfwInit();
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
2025-07-15 20:42:47 +03:00
|
|
|
//glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
2025-07-15 03:08:42 +03:00
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
|
|
2025-07-15 20:25:08 +03:00
|
|
|
// make the window
|
2025-07-15 03:08:42 +03:00
|
|
|
GLFWwindow *window = glfwCreateWindow(640, 480, "OpenGL Demo", NULL, NULL);
|
|
|
|
|
if (!window) {
|
|
|
|
|
|
|
|
|
|
std::cout << "Failed to create GLFW window." << std::endl;
|
|
|
|
|
glfwTerminate();
|
2025-07-15 20:09:48 +03:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
glfwMakeContextCurrent(window);
|
2025-07-15 20:25:08 +03:00
|
|
|
// d
|
2025-07-15 19:43:51 +03:00
|
|
|
|
2025-07-15 20:25:08 +03:00
|
|
|
// load graphics
|
2025-07-15 20:09:48 +03:00
|
|
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
|
|
|
std::cerr << "Failed to initialize OpenGL loader!" << std::endl;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
glViewport(0, 0, 640, 480);
|
2025-07-15 20:25:08 +03:00
|
|
|
// d
|
2025-07-15 19:43:51 +03:00
|
|
|
|
2025-07-15 20:25:08 +03:00
|
|
|
// now make ImGui
|
2025-07-15 20:09:48 +03:00
|
|
|
IMGUI_CHECKVERSION();
|
|
|
|
|
ImGui::CreateContext();
|
2025-07-15 20:25:08 +03:00
|
|
|
ImGuiIO &io = ImGui::GetIO();
|
|
|
|
|
(void)io;
|
2025-07-15 20:42:47 +03:00
|
|
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
2025-07-15 20:09:48 +03:00
|
|
|
ImGui::StyleColorsDark();
|
|
|
|
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
|
|
|
ImGui_ImplOpenGL3_Init("#version 130");
|
2025-07-15 20:25:08 +03:00
|
|
|
/// im a dumbass
|
|
|
|
|
///
|
2025-07-15 19:43:51 +03:00
|
|
|
|
2025-07-15 20:25:08 +03:00
|
|
|
// program
|
|
|
|
|
while (!glfwWindowShouldClose(window)) {
|
2025-07-15 20:42:47 +03:00
|
|
|
static bool dragging_window = false;
|
|
|
|
|
static double drag_start_mouse_x, drag_start_mouse_y;
|
|
|
|
|
static int drag_start_window_x,drag_start_window_y;
|
2025-07-15 03:08:42 +03:00
|
|
|
|
2025-07-15 20:25:08 +03:00
|
|
|
glClearColor(1.0f, .5f, .2f, 1.0f);
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2025-07-15 19:43:51 +03:00
|
|
|
|
2025-07-15 20:25:08 +03:00
|
|
|
glfwPollEvents();
|
2025-07-15 03:08:42 +03:00
|
|
|
|
2025-07-15 20:25:08 +03:00
|
|
|
ImGui_ImplOpenGL3_NewFrame();
|
|
|
|
|
ImGui_ImplGlfw_NewFrame();
|
|
|
|
|
ImGui::NewFrame();
|
2025-07-15 03:08:42 +03:00
|
|
|
|
2025-07-15 20:25:08 +03:00
|
|
|
ImGui::BeginMainMenuBar();
|
2025-07-15 03:08:42 +03:00
|
|
|
|
2025-07-15 20:42:47 +03:00
|
|
|
if (ImGui::IsItemHovered() && ImGui::IsMouseClicked(0)) {
|
|
|
|
|
dragging_window = true;
|
2025-07-15 03:08:42 +03:00
|
|
|
|
|
|
|
|
|
2025-07-15 20:42:47 +03:00
|
|
|
glfwGetCursorPos(window, &drag_start_mouse_x, &drag_start_mouse_y);
|
2025-07-15 20:09:48 +03:00
|
|
|
|
2025-07-15 20:42:47 +03:00
|
|
|
// Get window pos
|
|
|
|
|
glfwGetWindowPos(window, &drag_start_window_x, &drag_start_window_y);
|
2025-07-15 20:25:08 +03:00
|
|
|
}
|
2025-07-15 03:08:42 +03:00
|
|
|
|
2025-07-15 20:42:47 +03:00
|
|
|
if (dragging_window && ImGui::IsMouseDown(0)) {
|
|
|
|
|
double current_mouse_x, current_mouse_y;
|
|
|
|
|
glfwGetCursorPos(window, ¤t_mouse_x, ¤t_mouse_y);
|
|
|
|
|
|
2025-07-15 20:09:48 +03:00
|
|
|
|
2025-07-15 20:42:47 +03:00
|
|
|
double dx = current_mouse_x - drag_start_mouse_x;
|
|
|
|
|
double dy = current_mouse_y - drag_start_mouse_y;
|
2025-07-15 20:09:48 +03:00
|
|
|
|
2025-07-15 20:42:47 +03:00
|
|
|
// Move window
|
|
|
|
|
glfwSetWindowPos(window,
|
|
|
|
|
drag_start_window_x + static_cast<int>(dx),
|
|
|
|
|
drag_start_window_y + static_cast<int>(dy));
|
|
|
|
|
} else {
|
|
|
|
|
dragging_window = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Menu items
|
2025-07-15 20:09:48 +03:00
|
|
|
if (ImGui::BeginMenu("File")) {
|
2025-07-15 20:42:47 +03:00
|
|
|
if (ImGui::MenuItem("Exit")) {
|
|
|
|
|
glfwSetWindowShouldClose(window, true);
|
|
|
|
|
}
|
2025-07-15 20:09:48 +03:00
|
|
|
ImGui::EndMenu();
|
|
|
|
|
}
|
|
|
|
|
ImGui::EndMainMenuBar();
|
|
|
|
|
|
|
|
|
|
ImGui::Begin("Editor");
|
|
|
|
|
ImGui::Text("Hello from editor");
|
|
|
|
|
ImGui::End();
|
|
|
|
|
|
|
|
|
|
ImGui::Render();
|
|
|
|
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
|
|
|
glfwSwapBuffers(window);
|
2025-07-15 03:08:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glfwDestroyWindow(window);
|
|
|
|
|
glfwTerminate();
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|