Hello to all, I jst finished to port my tiny 3d game under Linux. Here I
found some very strange problems wich I couldn’t solve yet.
I use SDL 1.2.11 under Linux SUSE 10.0 on Acer Aspire 3020 Laptop,
RadeonX700:
When the application starts if the mouse is hidden and happens to be over
the window then the xrel/yrel contain actually the absolute and not the
relative position of the mouse. If I start the application so that the mouse
happens to be outside of the window or the mouse is not hidden the problem
disappears. So the two condition must be met: mouse hidden + grab mouse
while the pointer is in the window.
Also I found in the documentation that:
“If the cursor is hidden (SDL_ShowCursor(0)) and the input is grabbed
(SDL_WM_GrabInput(SDL_GRAB_ON)), then the mouse will give relative motion
events even when the cursor reaches the edge of the screen. This is
currently only implemented on Windows and Linux/Unix-alikes.” ( see
http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fMouseMotionEvent )
Actually what happens, at least with my system, is that the documented
behaviour is valid only on Windows and not on Linux where the xrel and yrel
are clipped to zero. (by the way on windows if you move fast enough the
mouse outside of the window it looses the grab… )
My question is: does anybody ever experienced the same problem? am I missing
something? its really a bug? its a feature? its something connected to my X
server? …
Here comes a little program I did to replicate the same behaviour in a
scientific way
You can see that the behaviour always appears when the mouse is grabbed
meanwhile being in the window area AND its hidden.
As you can see from the program: s/h = show/hide the mouse, g/u =
grab/ungrab the mouse, any other key exits.
Notice that during the “strange” behaviour the absolute mouse position are
blocked for some reason to the maximum window’s-client-area value (even if
the mouse is actually moving…)
Well at least this is valid with my system… this is why I would like any
body to try it out…
// --------------------- starts weird.c -------------------------------
#include <SDL.h>
int main() {
if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) {
printf(“Unable to init SDL: %s\n”, SDL_GetError());
exit(1);
}
SDL_Surface * screen = SDL_SetVideoMode(400, 400,
SDL_GetVideoInfo()->vfmt->BitsPerPixel, 0 );
SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(0);
int gameover = 0;
while(!gameover) {
SDL_Event ev;
SDL_PumpEvents();
while ( SDL_PollEvent(&ev) ) {
switch (ev.type) {
case SDL_KEYDOWN:
if (ev.key.keysym.sym == SDLK_g) {
SDL_WM_GrabInput(SDL_GRAB_ON);
} else
if (ev.key.keysym.sym == SDLK_u)
SDL_WM_GrabInput(SDL_GRAB_OFF);
else
if (ev.key.keysym.sym == SDLK_h) {
SDL_ShowCursor(0);
} else
if (ev.key.keysym.sym == SDLK_s)
SDL_ShowCursor(1);
else
gameover = 1;
break;
case SDL_MOUSEMOTION:
printf("MOUSE MOTION abs=%d %d, rel=%d %d\n", ev.motion.x, ev.motion.y,
ev.motion.xrel, ev.motion.yrel);
break;
}
}
}
SDL_Quit();
return 0;
}
// --------------------- ends weird.c -------------------------------
I compile this way:
gcc -o weird.exe weird.c sdl-config --cflags
sdl-config --libs
-Wall -g
Thanks
Michele Bosi–
Email.it, the professional e-mail, gratis per te: http://www.email.it/f
Sponsor:
Refill s.r.l. - Cartucce compatibili e kit di ricarica per tutti i modelli
di stampante. Acquista al telefono o online: consegna in tutta Italia in 48
ore!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=5190&d=20061017