Positioning mouse

is it somehow possible to position the mouse cursor somewhere on the
screen? i need this for looking around in a 3d environment (openGL) using
the mouse, as it is usually done in first person shooters. problem is, if
the mouse is not centered at the time my program starts, the view will not
be neutral but at some angle that corresponds to the current cursor
position. what would be the right way to solve this problem, i’m using the
mousemotion event to keep track of the cursor pos.

cheers
eik

SDL_WarpMouse

Name

SDL_WarpMouse – Set the position of the mouse cursor.

Synopsis

#include "SDL.h"void SDL_WarpMouse(Uint16 x, Uint16 y);

Description

Set the position of the mouse cursor (generates a mouse motion event).

See Also

SDL_MouseMotionEvent

is it somehow possible to position the mouse cursor somewhere on the
screen? i need this for looking around in a 3d environment (openGL) using
the mouse, as it is usually done in first person shooters. problem is, if
the mouse is not centered at the time my program starts, the view will not
be neutral but at some angle that corresponds to the current cursor
position. what would be the right way to solve this problem, i’m using the
mousemotion event to keep track of the cursor pos.

SDL_WarpMouse(x, y),

or

SDL_ShowCursor(SDL_DISABLE) with SDL_WM_GrabInput(SDL_GRAB_ON)

With the latter you will need to check the mouse’s relative position
during mouse motion events, since the absolute position will be useless.

–ryan.

SDL_WarpMouse(x, y),

or

SDL_ShowCursor(SDL_DISABLE) with SDL_WM_GrabInput(SDL_GRAB_ON)

With the latter you will need to check the mouse’s relative position
during mouse motion events, since the absolute position will be useless.

–ryan.

SDL_WarpMouse crashes every time i start my program, obviously it doesn’t
like to ccoperate with openGL.
SDL_WM_GrabInput does not do anything extraordinary, a mousemotion event
delivers the same values as it does without that command. i.e. the mouse
position doesn’t go off the screen, which was what i expected from your
hint. or did i get that wrong?

i could use glut for mouse motion, i’ve seen some code that does what i
want nicely, but a heterogenous control system isn’t what i really want to
do, especially since i don’t like glut too much.

eik

SDL_WarpMouse crashes every time i start my program, obviously it doesn’t
like to ccoperate with openGL.

It’s possible that it’s trying to draw a cursor on a non-existent screen
surface. Can you put together a minimal example that shows this problem?

Thanks!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

SDL_WarpMouse crashes every time i start my program, obviously it doesn’t
like to ccoperate with openGL.

It shouldn’t; it may be a bug in SDL (but you are probably better off with
the grabinput/hidecursor tactic.

SDL_WM_GrabInput does not do anything extraordinary, a mousemotion event
delivers the same values as it does without that command. i.e. the mouse
position doesn’t go off the screen, which was what i expected from your
hint. or did i get that wrong?

You have to hide the cursor too, like I said.

–ryan.