Moving undecorated window (GLFW)

I'm trying to solve this problem for about a week but I still can't figure out what the problem is.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void moveWindow(GLFWwindow *window){
    if(mousePressed()){
        int c_x, c_y;
        glfwGetCursorPos(window, &c_x, &c_y);
	int cp_x = floor(c_x);
	int cp_y = floor(c_y);

        int w_posx, w_posy;
	glfwGetWindowPos(window, &w_posx, &w_posy);
	int wrel_cpx = w_posx + cp_x;
	int wrel_cpy = w_posy + cp_y;

	glfwSetWindowPos(window, wrel_cpx - cp_x, wrel_cpy - cp_y);
    }
}



I want my window be able to move around when I drag with my mouse.

Can someone please tell me what I did wrong?
What's happening instead of intended result?
It doesn't move when I drag around.

It kind of works when I change my code to this,

glfwSetWindowPos(window, wrel_cpx, wrel_cpy);

But the problem is that the window always sets its position to my mouse's x y position.
It isn't "moving" because you're setting it to the same position it was at.

If wrel_cpx is w_posx + cp_x, then wrelcpx - cp_x is: w_posx + cp_x - cp_x or w_posx which is the x coordinate the window is already located at.
So do you know how to solve this? I can't figure out what to do...
You need to get relative cursor position compared to where it was last frame. You then take that offset and apply it to the new position for the window.

Here, you're just setting the window position to where it was previously. (Do the math in your head)
Topic archived. No new replies allowed.