medfall

A super great game engine
Log | Files | Refs

commit 7bf0b4948668bf68b80c04ae821f8001193aa6f2
parent 785071ed64125f0506ab20129836569eedc4af12
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue Aug 29 00:26:01 +0100

Centre cursor on window focus

Diffstat:
gl.cc | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/gl.cc b/gl.cc @@ -112,6 +112,12 @@ static void glfw_error_callback( int code, const char * message ) { WARN( "GLFW error {}: {}", code, message ); } +static void glfw_focus_callback( GLFWwindow * window, int focused ) { + if( focused == GLFW_TRUE ) { + glfwSetCursorPos( window, window_size.x / 2, window_size.y / 2 ); + } +} + GLFWwindow * gl_init( WindowType window_type ) { glfwSetErrorCallback( glfw_error_callback ); @@ -170,10 +176,11 @@ GLFWwindow * gl_init( WindowType window_type ) { monitor_left + mode->width / 2 - total_width / 2, monitor_top + mode->height / 2 - total_height / 2 ); - glfwSetCursorPos( window, width / 2, height / 2 ); - window_size = v2u32( checked_cast< u32 >( width ), checked_cast< u32 >( height ) ); + glfwSetCursorPos( window, width / 2, height / 2 ); + glfwSetWindowFocusCallback( window, glfw_focus_callback ); + glfwMakeContextCurrent( window ); if( gladLoadGLLoader( ( GLADloadproc ) glfwGetProcAddress ) != 1 ) {