yj1214 wrote on Tuesday, September 15, 2015:
I’m trying to make my undecorated window movable and resizable but I can’t figure out how to make my window movable.
This is what I so far have,
CODE EDITED
#include <stdio.h>
#include <math.h>
#include <GL/gl.h>
#include "include/GLFW/glfw3.h"
void cursor_position_callback(GLFWwindow* window, double x, double y);
void mouse_button_callback(GLFWwindow *window, int button, int action, int mods);
int cp_x;
int cp_y;
int wrel_cpx;
int wrel_cpy;
int w_posx;
int w_posy;
int buttonEvent;
int main(){
glfwInit();
glfwWindowHint(GLFW_DECORATED, 0);
GLFWwindow *window = glfwCreateWindow(640, 480, "Undecorated Resizable", 0, 0);
glfwSetCursorPosCallback(window, cursor_position_callback);
glfwSetMouseButtonCallback(window, mouse_button_callback);
glfwMakeContextCurrent(window);
while(!glfwWindowShouldClose(window)){
if(buttonEvent == 1){
glfwSetWindowPos(window, wrel_cpx - cp_x, wrel_cpy - cp_y);
}
glfwSwapBuffers(window);
glfwWaitEvents();
}
return 0;
}
void cursor_position_callback(GLFWwindow* window, double x, double y){
glfwGetWindowPos(window, &w_posx, &w_posy);
wrel_cpx = cp_x + w_posx;
wrel_cpy = cp_y + w_posy;
cp_x = floor(x);
cp_y = floor(y);
}
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods){
if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS){
buttonEvent = 1;
}
if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_RELEASE){
buttonEvent = 0;
}
}
When I try to drag my window, it does absoutely nothing. Its position stays the same.
Could someone please help me?