Why is getCursorPosition() double?

yj1214 wrote on Sunday, August 16, 2015:

I thought screen cooridinates don’t have decimal points…

This is my code,

    double x;
    double y;

	glfwGetCursorPos(window, &x, &y);

	printf("%d, %d", x, y);
	printf("\n");

And this is what I get,

0, 1082245120
0, 1082263552
0, 1082284032
0, 1082304512
0, 1082331136
0, 1082357760
0, 1082384384
0, 1082404864
0, 1082419200
0, 1082419200

What’s happening here? Why do I get zero for my x position?

arampl wrote on Sunday, August 16, 2015:

You are applying printf’s decimal integer formatting (%d) to the values of type “double”, thus getting weird result. Use %f instead.

To get integers floor the result.

Doubles are used because mouse presicion is much higher than screen.

yj1214 wrote on Monday, August 17, 2015:

Thanks that worked! but I have another question.

Is there way to get my cursor position relative to my monitor not window?

glfwGetCursorPos();

This function returns the position of my cursor relative to my window. But I need to get my cursor position relative to my monitor. I think SFML has this function but does GLFW have it too?

dougbinks wrote on Monday, August 17, 2015:

Use glfwGetWindowPos to get the position of the window and add this to the cursor position.

yj1214 wrote on Monday, August 17, 2015:

Thanks that works! but I have one last question…

Is there way to get my cursor position even if my cursor isn’t inside the window?

dougbinks wrote on Monday, August 17, 2015:

I think you can only get the cursor position inside the window if the cursor is displayed. To get unlimited virtual cursor position you need to call glfwSetInputMode with GLFW_CURSOR, GLFW_CURSOR_DISABLED