Mouse grabbing

Hello

How can i grab a mouse cursor in windowed SDL

application ? I looked through the SDL sources and found
XGrabPointer call only in DGA mode. I see a nice thing will
be to grab mouse in window while a game is started and
release it when a game is finished or paused.

Look at the source code to SDLdoom (available on the SDL download page:
http://www.devolution.com/~slouken/SDL/download.html
i_video.c shows the best way to implement mouse handling under SDL.

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

hi`

is

  • hide cursor
  • set videomode
  • grab input

the right way for a Heretic II alike game? (I mean, if I want to hide
the mouse cursor and use relative mouse coords) And if I am not in
fullscreen mode, will I have to warp the mouse or is this done by SDL.
If I have to warp the mouse, how can I tell whether I have to or not (I
don’t have to with DGA mouse in Fullscreen).

My problem at the moment is that the above combo still shows the mouse
cursor in the middle of the screen…

(if anyone is interested and willing to help me with UT & SDL, he/she
should check out the sdlUT module I finally imported [
https://sourceforge.net/project/?group_id=975 ])–
Daniel Vogel My opinions may have changed,
666 @ http://grafzahl.de but not the fact that I am right

  • hide cursor
  • set videomode
  • grab input

the right way for a Heretic II alike game?

Yes.

(I mean, if I want to hide
the mouse cursor and use relative mouse coords) And if I am not in
fullscreen mode, will I have to warp the mouse or is this done by SDL.
If I have to warp the mouse, how can I tell whether I have to or not (I
don’t have to with DGA mouse in Fullscreen).

Always warp the mouse. If you are in DGA mouse mode, it is almost zero
overhead, and if you are not, then you will need to warp the mouse to get
any sort of usable interface.

My problem at the moment is that the above combo still shows the mouse
cursor in the middle of the screen…

Can you write a small test program that reproduces this sequence?
Make sure you are also using the very latest SDL 1.1 snapshot.

See ya!
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

hi`

Sam Lantinga wrote:

Always warp the mouse. If you are in DGA mouse mode, it is almost zero
overhead, and if you are not, then you will need to warp the mouse to get
any sort of usable interface.

So I assume the relative movement the warping creates are somehow
filtered by SDL, right?

Can you write a small test program that reproduces this sequence?
Make sure you are also using the very latest SDL 1.1 snapshot.

I will try to write a test program that reproduces the error tomorrow.–
Daniel Vogel My opinions may have changed,
666 @ http://grafzahl.de but not the fact that I am right

hi`

Sam Lantinga wrote:

Always warp the mouse. If you are in DGA mouse mode, it is almost zero
overhead, and if you are not, then you will need to warp the mouse to get
any sort of usable interface.

So I assume the relative movement the warping creates are somehow
filtered by SDL, right?

No, check the SDL doom source code for the correct way of warping the
mouse. Essentially you ignore mouse motion with the absolute coordinates
of the location you warped to.

I will try to write a test program that reproduces the error tomorrow.

Great.
-Sam Lantinga (slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

hi`

Sam Lantinga wrote:

So I assume the relative movement the warping creates are somehow
filtered by SDL, right?

No, check the SDL doom source code for the correct way of warping the
mouse. Essentially you ignore mouse motion with the absolute coordinates
of the location you warped to.

okay, thanks. I didn’t get it working though, but I will figure it out
:wink:

I will try to write a test program that reproduces the error tomorrow.

Great.

Hmm, strange, a simple test program worked so I assured that I call
everything in the right order (added printfs) and it still shows the
cursor… This leads me to another question: Why do I have to link my
little test app with -lSDL -lpthread -lGL myself???–
Daniel Vogel My opinions may have changed,
666 @ http://grafzahl.de but not the fact that I am right
-------------- next part --------------
#include <SDL/SDL.h>

int main(int argc, char** argv)
{
// Init SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
fprintf(stderr,“Couldn’t initialize SDL: %s\n”,SDL_GetError());
exit( 1 );
}

atexit(SDL_Quit);

SDL_ShowCursor( 0 );

if ( SDL_SetVideoMode( 640, 480, 0, SDL_OPENGL | SDL_FULLSCREEN ) == NULL ) {
		fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
		SDL_Quit();
		exit(1);
}	

SDL_WM_GrabInput(SDL_GRAB_ON);

SDL_Delay(500);

return 0;

}

Hmm, strange, a simple test program worked so I assured that I call
everything in the right order (added printfs) and it still shows the
cursor…

Ahhhh… I think this is a bug in the X server.
Which video card and server do you have?

This leads me to another question: Why do I have to link my
little test app with -lSDL -lpthread -lGL myself???

Because pthread doesn’t work properly unless you link it with the main
executable, and GL programs don’t pick up the GL symbols if the library
is linked into SDL.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec

hi`

Sam Lantinga wrote:

Ahhhh… I think this is a bug in the X server.
Which video card and server do you have?

Riva TNT running 3.3.5

btw, if I run in windowed mode the cursor is hidden. ALT-ENTER should
switch to fullscreen mode, right? (it doesn’t work for me)

This leads me to another question: Why do I have to link my
little test app with -lSDL -lpthread -lGL myself???

Because pthread doesn’t work properly unless you link it with the main
executable, and GL programs don’t pick up the GL symbols if the library
is linked into SDL.

ah, thanks–
Daniel Vogel My opinions may have changed,
666 @ http://grafzahl.de but not the fact that I am right