MoveWin Pt1
This commit is contained in:
71
Osmium.cpp
71
Osmium.cpp
@@ -1,16 +1,15 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include <imgui_impl_glfw.h>
|
#include <imgui_impl_glfw.h>
|
||||||
#include <imgui_impl_opengl3.h>
|
#include <imgui_impl_opengl3.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
std::cout << "Hello working!" << std::endl;
|
std::cout << "Hello working!" << std::endl;
|
||||||
|
static bool dragging_window = false;
|
||||||
|
static ImVec2 move_offset;
|
||||||
|
|
||||||
|
|
||||||
glfwInit();
|
glfwInit();
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||||
@@ -18,9 +17,7 @@ int main(int argc, char **argv) {
|
|||||||
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
|
||||||
|
// make the window
|
||||||
|
|
||||||
//make the window
|
|
||||||
GLFWwindow *window = glfwCreateWindow(640, 480, "OpenGL Demo", NULL, NULL);
|
GLFWwindow *window = glfwCreateWindow(640, 480, "OpenGL Demo", NULL, NULL);
|
||||||
if (!window) {
|
if (!window) {
|
||||||
|
|
||||||
@@ -29,52 +26,62 @@ int main(int argc, char **argv) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
//d
|
// d
|
||||||
|
|
||||||
//load graphics
|
// load graphics
|
||||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||||
std::cerr << "Failed to initialize OpenGL loader!" << std::endl;
|
std::cerr << "Failed to initialize OpenGL loader!" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
glViewport(0, 0, 640, 480);
|
glViewport(0, 0, 640, 480);
|
||||||
//d
|
// d
|
||||||
|
|
||||||
//now make ImGui
|
// now make ImGui
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
(void)io;
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
ImGui_ImplOpenGL3_Init("#version 130");
|
ImGui_ImplOpenGL3_Init("#version 130");
|
||||||
///im a dumbass
|
/// im a dumbass
|
||||||
///d
|
///
|
||||||
|
|
||||||
|
// program
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//program
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
|
||||||
glClearColor(1.0f,.5f,.2f, 1.0f);
|
glClearColor(1.0f, .5f, .2f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
ImGui::BeginMainMenuBar();
|
ImGui::BeginMainMenuBar();
|
||||||
|
ImVec2 mouse_pos = ImGui::GetMousePos();
|
||||||
|
ImVec2 window_pos = ImGui::GetWindowPos();
|
||||||
|
|
||||||
|
if (ImGui::IsMouseDown(0) && ImGui::IsItemHovered()) {
|
||||||
|
|
||||||
|
if (!dragging_window) {
|
||||||
|
dragging_window = true;
|
||||||
|
move_offset = ImVec2(mouse_pos.x - window_pos.x,
|
||||||
|
mouse_pos.y - window_pos.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int new_x = static_cast<int>(mouse_pos.x - move_offset.x);
|
||||||
|
int new_y = static_cast<int>(mouse_pos.y - move_offset.y);
|
||||||
|
glfwSetWindowPos(window, new_x, new_y);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
dragging_window = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ImGui::BeginMenu("File")) {
|
if (ImGui::BeginMenu("File")) {
|
||||||
ImGui::MenuItem("Exit");
|
ImGui::MenuItem("Exit");
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
@@ -88,14 +95,10 @@ int main(int argc, char **argv) {
|
|||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user