Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL2 mouse grab is not working

Tags:

events

mouse

sdl

With SDL 1.2 I was using SDL_WM_GrabInput to center the (hidden) mouse on screen. This gave me unlimited turning freedom for a first person shooter. SDL2 no longer provides this function but has SDL_SetWindowGrab. This does not seem to be repositioning the mouse to the center of the screen after each loop (event read). I can turn the player around only 1 and a half times before the mouse has hit the edge of the window and will no longer produce xrel values. Is this a bug or is there another function I should be using?

like image 998
ste3e Avatar asked Oct 07 '22 21:10

ste3e


1 Answers

Give SDL_SetRelativeMouseMode() and SDL_GetRelativeMouseState() a try.

Alternatively recenter the mouse each frame yourself with SDL_WarpMouseInWindow().

like image 98
genpfault Avatar answered Oct 12 '22 11:10

genpfault