HiDPI support on Mac OS X

Hi,

I’m facing a strange issue when testing the hg tip with the new
SDL_WINDOW_ALLOW_HIDPI support on my rMBP: although the window is sized
correctly, all SDL properties return incorrect values.

For instance, if I create a 800x600 window with the HIDPI flag, I receive a
1600x1200 window (which is expected), but SDL_GetWindowSize() still returns
800x600; mouse coordinates are limited to 800x600; SDL_GetDisplayBounds()
returns 1440x900 (instead of 2880x1800).

Is this a known issue? Is there anything I can do to help improve the
situation?

Thanks,
Stefanos

I think this is the expected behaviour - check out the bugzilla discussion where the feature was created: https://bugzilla.libsdl.org/show_bug.cgi?id=1934
Use SDL_GL_GetDrawableSize to get the pixel dimensions of the OpenGL drawable (for viewport setting, etc.)On 2013-10-03, at 7:35 PM, “Stefanos A.” wrote:

Hi,

I’m facing a strange issue when testing the hg tip with the new SDL_WINDOW_ALLOW_HIDPI support on my rMBP: although the window is sized correctly, all SDL properties return incorrect values.

For instance, if I create a 800x600 window with the HIDPI flag, I receive a 1600x1200 window (which is expected), but SDL_GetWindowSize() still returns 800x600; mouse coordinates are limited to 800x600; SDL_GetDisplayBounds() returns 1440x900 (instead of 2880x1800).

Is this a known issue? Is there anything I can do to help improve the situation?

Thanks,
Stefanos


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hmm, this fixes the glViewport() issue. However, now mouse coordinates no
longer correspond to the drawable size…

I guess it is by design that the mouse coordinates are specified in points
(as are the window coordinates). That said, is there any public API to map
mouse coordinates from points to pixels? There are applications that rely
on pixel-precise mouse input (e.g. for painting).

2013/10/4 Alex Szpakowski > I think this is the expected behaviour - check out the bugzilla discussion

where the feature was created:
https://bugzilla.libsdl.org/show_bug.cgi?id=1934
Use SDL_GL_GetDrawableSize to get the pixel dimensions of the OpenGL
drawable (for viewport setting, etc.)

On 2013-10-03, at 7:35 PM, “Stefanos A.” <@Stefanos_A> wrote:

Hi,

I’m facing a strange issue when testing the hg tip with the new
SDL_WINDOW_ALLOW_HIDPI support on my rMBP: although the window is sized
correctly, all SDL properties return incorrect values.

For instance, if I create a 800x600 window with the HIDPI flag, I receive
a 1600x1200 window (which is expected), but SDL_GetWindowSize() still
returns 800x600; mouse coordinates are limited to 800x600;
SDL_GetDisplayBounds() returns 1440x900 (instead of 2880x1800).

Is this a known issue? Is there anything I can do to help improve the
situation?

Thanks,
Stefanos


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hey Stephanos,

You can overcome this issue by using an event watcher, a callback
function that is automatically called when new events arrive. Use it
to check if the window has SDL_WINDOW_ALLOW_HIDPI and edit mouse
coordinates accordingly:


int MouseCoordinatesEventWatch(void *unused, SDL_Event* event) {
  SDL_Window* window;
  int window_flags;

  switch (event->type) {
    case SDL_MOUSEBUTTONDOWN:
    case SDL_MOUSEBUTTONUP:
     window = SDL_GetWindowFromID(event->windowID);
     if (SDL_GetWindowFlags(window) & SDL_WINDOW_ALLOW_HIDPI)) {
       event->button.x *= 2;
       event->button.y *= 2;
    }
    break;
  case SDL_MOUSEMOTION:
    window = SDL_GetWindowFromID(event->windowID);
    if (SDL_GetWindowFlags(window) & SDL_WINDOW_ALLOW_HIDPI)) {
      event->motion.x *= 2;
      event->motion.y *= 2;
    }
  } /* end switch */

}

int main()
{
  /*** initialization code ****/
  SDL_AddEventWatch(MouseCoordinatesEventWatch, NULL);

}

This will automatically adjust the mouse coordinates every time a new
mouse event arrives. Note two things:

  • This function handles cases where a window might not have the HiDPI
    flag. If you always use this flag, then
    you could remove this conditional code.
  • The ’ *= 2 ’ code is based on my observation of the window sizes /
    event coordinates. It might be different, though
  • This may not work well if you use SDL_RenderSetLogicalSize() — you
    need to test it to make sure it’s okay

– Aggelos KolaitisOn 10/4/13, Stefanos A. wrote:

Hmm, this fixes the glViewport() issue. However, now mouse coordinates no
longer correspond to the drawable size…

I guess it is by design that the mouse coordinates are specified in points
(as are the window coordinates). That said, is there any public API to map
mouse coordinates from points to pixels? There are applications that rely
on pixel-precise mouse input (e.g. for painting).

2013/10/4 Alex Szpakowski

I think this is the expected behaviour - check out the bugzilla
discussion
where the feature was created:
https://bugzilla.libsdl.org/show_bug.cgi?id=1934
Use SDL_GL_GetDrawableSize to get the pixel dimensions of the OpenGL
drawable (for viewport setting, etc.)

On 2013-10-03, at 7:35 PM, “Stefanos A.” wrote:

Hi,

I’m facing a strange issue when testing the hg tip with the new
SDL_WINDOW_ALLOW_HIDPI support on my rMBP: although the window is sized
correctly, all SDL properties return incorrect values.

For instance, if I create a 800x600 window with the HIDPI flag, I receive
a 1600x1200 window (which is expected), but SDL_GetWindowSize() still
returns 800x600; mouse coordinates are limited to 800x600;
SDL_GetDisplayBounds() returns 1440x900 (instead of 2880x1800).

Is this a known issue? Is there anything I can do to help improve the
situation?

Thanks,
Stefanos


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Why not use SDL_GL_GetDrawableSize / SDL_GetWindowSize instead of relying on a hard-coded 2x scale?On 2013-10-04, at 1:33 PM, Aggelos Kolaitis wrote:

Hey Stephanos,

You can overcome this issue by using an event watcher, a callback
function that is automatically called when new events arrive. Use it
to check if the window has SDL_WINDOW_ALLOW_HIDPI and edit mouse
coordinates accordingly:


> int MouseCoordinatesEventWatch(void *unused, SDL_Event* event) {
>  SDL_Window* window;
>  int window_flags;
> 
>  switch (event->type) {
>    case SDL_MOUSEBUTTONDOWN:
>    case SDL_MOUSEBUTTONUP:
>     window = SDL_GetWindowFromID(event->windowID);
>     if (SDL_GetWindowFlags(window) & SDL_WINDOW_ALLOW_HIDPI)) {
>       event->button.x *= 2;
>       event->button.y *= 2;
>    }
>    break;
>  case SDL_MOUSEMOTION:
>    window = SDL_GetWindowFromID(event->windowID);
>    if (SDL_GetWindowFlags(window) & SDL_WINDOW_ALLOW_HIDPI)) {
>      event->motion.x *= 2;
>      event->motion.y *= 2;
>    }
>  } /* end switch */
> 
> }
> 
> int main()
> {
>  /*** initialization code ****/
>  SDL_AddEventWatch(MouseCoordinatesEventWatch, NULL);
> 
> }
> 

This will automatically adjust the mouse coordinates every time a new
mouse event arrives. Note two things:

  • This function handles cases where a window might not have the HiDPI
    flag. If you always use this flag, then
    you could remove this conditional code.
  • The ’ *= 2 ’ code is based on my observation of the window sizes /
    event coordinates. It might be different, though
  • This may not work well if you use SDL_RenderSetLogicalSize() — you
    need to test it to make sure it’s okay

– Aggelos Kolaitis


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I added a note about this [2nd note]. Of course in a project environment SDL_GL_GetDrawableSize / SDL_GetWindowSize should be used. I didn’t do this for the sake of clarity of how event watchers work.

– Aggelos KolaitisOn Oct 4, 2013, at 7:36 PM, Alex Szpakowski wrote:

Why not use SDL_GL_GetDrawableSize / SDL_GetWindowSize instead of relying on a hard-coded 2x scale?

On 2013-10-04, at 1:33 PM, Aggelos Kolaitis <@Aggelos_Kolaitis> wrote:

Hey Stephanos,

You can overcome this issue by using an event watcher, a callback
function that is automatically called when new events arrive. Use it
to check if the window has SDL_WINDOW_ALLOW_HIDPI and edit mouse
coordinates accordingly:


>> int MouseCoordinatesEventWatch(void *unused, SDL_Event* event) {
>> SDL_Window* window;
>> int window_flags;
>> 
>> switch (event->type) {
>>   case SDL_MOUSEBUTTONDOWN:
>>   case SDL_MOUSEBUTTONUP:
>>    window = SDL_GetWindowFromID(event->windowID);
>>    if (SDL_GetWindowFlags(window) & SDL_WINDOW_ALLOW_HIDPI)) {
>>      event->button.x *= 2;
>>      event->button.y *= 2;
>>   }
>>   break;
>> case SDL_MOUSEMOTION:
>>   window = SDL_GetWindowFromID(event->windowID);
>>   if (SDL_GetWindowFlags(window) & SDL_WINDOW_ALLOW_HIDPI)) {
>>     event->motion.x *= 2;
>>     event->motion.y *= 2;
>>   }
>> } /* end switch */
>> 
>> }
>> 
>> int main()
>> {
>> /*** initialization code ****/
>> SDL_AddEventWatch(MouseCoordinatesEventWatch, NULL);
>> 
>> }
>> 

This will automatically adjust the mouse coordinates every time a new
mouse event arrives. Note two things:

  • This function handles cases where a window might not have the HiDPI
    flag. If you always use this flag, then
    you could remove this conditional code.
  • The ’ *= 2 ’ code is based on my observation of the window sizes /
    event coordinates. It might be different, though
  • This may not work well if you use SDL_RenderSetLogicalSize() — you
    need to test it to make sure it’s okay

– Aggelos Kolaitis


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org