[SDL] Mouse relative position wrong values

Jeffrey Carpenter i8degrees at gmail.com
Mon Sep 22 15:24:34 PDT 2014


Heya,

You aren't using SDL2's "independent resolution scaling" AKA logical size viewport (SDL_SetLogicalSize & friends) by chance, are you? If so, perhaps it may be possible that it could be interfering with your results? (Pure speculation from me)

You can see how the values are adjusted to account for the feature in SDL_render.c:SDL_RendererEventWatch event handling for SDL_MOUSEMOTION, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONUP

I am on Mac OS X v10.9.4 and did not appear to exhibit the odd behavior you describe, given your test sample. My testing sample was this file: http://pastebin.com/D7Sr3UJq (built off SDL2 v2.0.3 framework bundle).

Cheers,
Jeffrey Carpenter
<i8degrees at gmail.com>

On 2014/09/ 21, at 12:13, Alexander Chaliovski <sabotage3d at gmail.com> wrote:

> Hello ,
> 
> I am getting weird mouse relative position with SDL 2.0.3 .
> The first mouse motion after the mouse click gives huge values after that the relative coords are correct is there a workaround or I have to calculate relative mouse coordinates myself ?
> I am testing the code under OSX and IOS . Or if there is a way to ignore the first event.
>  
> This is example code:
> 
> int x;
> int y;
> 
> SDL_Event evt;
> while(SDL_PollEvent(&evt))
> {
>     switch(evt.type)
>     {
>             
>         case SDL_MOUSEMOTION:
>                x = evt.motion.xrel
>                y = evt.motion.yrel
>             break;
>     }
> }
> 
> First two clicks on the screen.
> 
> INFO: x: -22, y: -354
> INFO: x: -184, y: 808
> 
> Thanks,
> Alex
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org




More information about the SDL mailing list