Updated some header comments and iOS documentation to better clarify high-dpi / retina support and screen-coordinate sizes versus pixel sizes.
authorAlex Szpakowski <slime73@gmail.com>
Thu, 31 Dec 2015 21:16:43 -0400
changeset 9995d79480c1e151
parent 9994 d3e4f7b44d4d
child 9996 11cba4a517a9
Updated some header comments and iOS documentation to better clarify high-dpi / retina support and screen-coordinate sizes versus pixel sizes.
WhatsNew.txt
docs/README-ios.md
include/SDL_render.h
include/SDL_video.h
     1.1 --- a/WhatsNew.txt	Thu Dec 31 15:26:40 2015 -0400
     1.2 +++ b/WhatsNew.txt	Thu Dec 31 21:16:43 2015 -0400
     1.3 @@ -71,13 +71,13 @@
     1.4  
     1.5  iOS:
     1.6  * Added support for iOS 8
     1.7 +* The SDL_WINDOW_ALLOW_HIGHDPI window flag now enables high-dpi support, and SDL_GL_GetDrawableSize() or SDL_GetRendererOutputSize() gets the window resolution in pixels
     1.8 +* SDL_GetWindowSize() and display mode sizes are in the "DPI-independent points" / "screen coordinates" coordinate space rather than pixels (matches OS X behavior)
     1.9 +* Added native resolution support for the iPhone 6 Plus
    1.10  * Added support for MFi game controllers
    1.11  * Added support for the hint SDL_HINT_ACCELEROMETER_AS_JOYSTICK
    1.12  * Added sRGB OpenGL ES context support on iOS 7+
    1.13 -* Added native resolution support for the iPhone 6 Plus
    1.14  * Added support for SDL_DisableScreenSaver(), SDL_EnableScreenSaver() and the hint SDL_HINT_VIDEO_ALLOW_SCREENSAVER
    1.15 -* The SDL_WINDOW_ALLOW_HIGHDPI window flag now enables high-dpi support, and SDL_GL_GetDrawableSize() or SDL_GetRendererOutputSize() gets the window resolution in pixels
    1.16 -* SDL_GetWindowSize() and display mode sizes are in the "DPI-independent points" coordinate space rather than pixels (matches OS X behavior)
    1.17  * SDL_SysWMinfo now contains the OpenGL ES framebuffer and color renderbuffer objects used by the window's active GLES view
    1.18  * Fixed various rotation and orientation issues
    1.19  * Fixed memory leaks
     2.1 --- a/docs/README-ios.md	Thu Dec 31 15:26:40 2015 -0400
     2.2 +++ b/docs/README-ios.md	Thu Dec 31 21:16:43 2015 -0400
     2.3 @@ -47,17 +47,45 @@
     2.4  FIXME: This needs to be updated for the latest methods
     2.5  
     2.6  Here is the easiest method:
     2.7 -1.  Build the SDL libraries (libSDL.a and libSDLSimulator.a) and the iPhone SDL Application template.
     2.8 -2.  Install the iPhone SDL Application template by copying it to one of XCode's template directories.  I recommend creating a directory called "SDL" in "/Developer/Platforms/iOS.platform/Developer/Library/XCode/Project Templates/" and placing it there.
     2.9 +1.  Build the SDL library (libSDL2.a) and the iPhone SDL Application template.
    2.10 +2.  Install the iPhone SDL Application template by copying it to one of Xcode's template directories.  I recommend creating a directory called "SDL" in "/Developer/Platforms/iOS.platform/Developer/Library/Xcode/Project Templates/" and placing it there.
    2.11  3.  Start a new project using the template.  The project should be immediately ready for use with SDL.
    2.12  
    2.13  Here is a more manual method:
    2.14 -1.  Create a new iPhone view based application.
    2.15 -2.  Build the SDL static libraries (libSDL.a and libSDLSimulator.a) for iPhone and include them in your project.  XCode will ignore the library that is not currently of the correct architecture, hence your app will work both on iPhone and in the iPhone Simulator.
    2.16 +1.  Create a new iOS view based application.
    2.17 +2.  Build the SDL static library (libSDL2.a) for iOS and include them in your project.  Xcode will ignore the library that is not currently of the correct architecture, hence your app will work both on iOS and in the iOS Simulator.
    2.18  3.  Include the SDL header files in your project.
    2.19 -4.  Remove the ApplicationDelegate.h and ApplicationDelegate.m files -- SDL for iPhone provides its own UIApplicationDelegate.  Remove MainWindow.xib -- SDL for iPhone produces its user interface programmatically.
    2.20 -5.  Delete the contents of main.m and program your app as a regular SDL program instead.  You may replace main.m with your own main.c, but you must tell XCode not to use the project prefix file, as it includes Objective-C code.
    2.21 +4.  Remove the ApplicationDelegate.h and ApplicationDelegate.m files -- SDL for iOS provides its own UIApplicationDelegate.  Remove MainWindow.xib -- SDL for iOS produces its user interface programmatically.
    2.22 +5.  Delete the contents of main.m and program your app as a regular SDL program instead.  You may replace main.m with your own main.c, but you must tell Xcode not to use the project prefix file, as it includes Objective-C code.
    2.23  
    2.24 +==============================================================================
    2.25 +Notes -- Retina / High-DPI and window sizes
    2.26 +==============================================================================
    2.27 +
    2.28 +Window and display mode sizes in SDL are in "screen coordinates" (or "points",
    2.29 +in Apple's terminology) rather than in pixels. On iOS this means that a window
    2.30 +created on an iPhone 6 will have a size in screen cooordinates of 375 x 667,
    2.31 +rather than a size in pixels of 750 x 1334. All iOS apps are expected to
    2.32 +size their content based on screen coordinates / points rather than pixels,
    2.33 +as this allows different iOS devices to have different pixel densities
    2.34 +(Retina versus non-Retina screens, etc.) without apps caring too much.
    2.35 +
    2.36 +By default SDL will not use the full pixel density of the screen on
    2.37 +Retina/high-dpi capable devices. Use the SDL_WINDOW_ALLOW_HIGHDPI flag when
    2.38 +creating your window to enable high-dpi support.
    2.39 +
    2.40 +When high-dpi support is enabled, SDL_GetWindowSize and display mode sizes
    2.41 +will still be in "screen coordinates" rather than pixels, but the window will
    2.42 +have a much greater pixel density when the device supports it, and the
    2.43 +SDL_GL_GetDrawableSize or SDL_GetRendererOutputSize functions (depending on
    2.44 +whether raw OpenGL or the SDL_Render API is used) can be queried to determine
    2.45 +the size in pixels of the drawable screen framebuffer.
    2.46 +
    2.47 +Some OpenGL ES functions such as glViewport expect sizes in pixels rather than
    2.48 +sizes in screen coordinates. When doing 2D rendering with OpenGL ES, an
    2.49 +orthographic projection matrix using the size in screen coordinates
    2.50 +(SDL_GetWindowSize) can be used in order to display content at the same scale
    2.51 +no matter whether a Retina device is used or not.
    2.52  
    2.53  ==============================================================================
    2.54  Notes -- Application events
    2.55 @@ -203,7 +231,7 @@
    2.56  Game Center 
    2.57  ==============================================================================
    2.58  
    2.59 -Game Center integration requires that you break up your main loop in order to yield control back to the system. In other words, instead of running an endless main loop, you run each frame in a callback function, using:
    2.60 +Game Center integration might require that you break up your main loop in order to yield control back to the system. In other words, instead of running an endless main loop, you run each frame in a callback function, using:
    2.61  
    2.62      int SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
    2.63  
     3.1 --- a/include/SDL_render.h	Thu Dec 31 15:26:40 2015 -0400
     3.2 +++ b/include/SDL_render.h	Thu Dec 31 21:16:43 2015 -0400
     3.3 @@ -215,7 +215,7 @@
     3.4                                                  SDL_RendererInfo * info);
     3.5  
     3.6  /**
     3.7 - *  \brief Get the output size of a rendering context.
     3.8 + *  \brief Get the output size in pixels of a rendering context.
     3.9   */
    3.10  extern DECLSPEC int SDLCALL SDL_GetRendererOutputSize(SDL_Renderer * renderer,
    3.11                                                        int *w, int *h);
     4.1 --- a/include/SDL_video.h	Thu Dec 31 15:26:40 2015 -0400
     4.2 +++ b/include/SDL_video.h	Thu Dec 31 21:16:43 2015 -0400
     4.3 @@ -53,8 +53,8 @@
     4.4  typedef struct
     4.5  {
     4.6      Uint32 format;              /**< pixel format */
     4.7 -    int w;                      /**< width */
     4.8 -    int h;                      /**< height */
     4.9 +    int w;                      /**< width, in screen coordinates */
    4.10 +    int h;                      /**< height, in screen coordinates */
    4.11      int refresh_rate;           /**< refresh rate (or zero for unspecified) */
    4.12      void *driverdata;           /**< driver-specific data, initialize to 0 */
    4.13  } SDL_DisplayMode;
    4.14 @@ -143,7 +143,9 @@
    4.15      SDL_WINDOWEVENT_MOVED,          /**< Window has been moved to data1, data2
    4.16                                       */
    4.17      SDL_WINDOWEVENT_RESIZED,        /**< Window has been resized to data1xdata2 */
    4.18 -    SDL_WINDOWEVENT_SIZE_CHANGED,   /**< The window size has changed, either as a result of an API call or through the system or user changing the window size. */
    4.19 +    SDL_WINDOWEVENT_SIZE_CHANGED,   /**< The window size has changed, either as
    4.20 +                                         a result of an API call or through the
    4.21 +                                         system or user changing the window size. */
    4.22      SDL_WINDOWEVENT_MINIMIZED,      /**< Window has been minimized */
    4.23      SDL_WINDOWEVENT_MAXIMIZED,      /**< Window has been maximized */
    4.24      SDL_WINDOWEVENT_RESTORED,       /**< Window has been restored to normal size
    4.25 @@ -412,8 +414,8 @@
    4.26   *               ::SDL_WINDOWPOS_UNDEFINED.
    4.27   *  \param y     The y position of the window, ::SDL_WINDOWPOS_CENTERED, or
    4.28   *               ::SDL_WINDOWPOS_UNDEFINED.
    4.29 - *  \param w     The width of the window.
    4.30 - *  \param h     The height of the window.
    4.31 + *  \param w     The width of the window, in screen coordinates.
    4.32 + *  \param h     The height of the window, in screen coordinates.
    4.33   *  \param flags The flags for the window, a mask of any of the following:
    4.34   *               ::SDL_WINDOW_FULLSCREEN,    ::SDL_WINDOW_OPENGL,
    4.35   *               ::SDL_WINDOW_HIDDEN,        ::SDL_WINDOW_BORDERLESS,
    4.36 @@ -423,6 +425,12 @@
    4.37   *
    4.38   *  \return The id of the window created, or zero if window creation failed.
    4.39   *
    4.40 + *  If the window is created with the SDL_WINDOW_ALLOW_HIGHDPI flag, its size
    4.41 + *  in pixels may differ from its size in screen coordinates on platforms with
    4.42 + *  high-DPI support (e.g. iOS and Mac OS X). Use SDL_GetWindowSize to query the
    4.43 + *  size of the client area in screen coordinates, and SDL_GL_GetDrawableSize or
    4.44 + *  SDL_GetRendererOutputSize to query the drawable size in pixels.
    4.45 + *
    4.46   *  \sa SDL_DestroyWindow()
    4.47   */
    4.48  extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindow(const char *title,
    4.49 @@ -513,10 +521,10 @@
    4.50   *  \brief Set the position of a window.
    4.51   *
    4.52   *  \param window   The window to reposition.
    4.53 - *  \param x        The x coordinate of the window, ::SDL_WINDOWPOS_CENTERED, or
    4.54 -                    ::SDL_WINDOWPOS_UNDEFINED.
    4.55 - *  \param y        The y coordinate of the window, ::SDL_WINDOWPOS_CENTERED, or
    4.56 -                    ::SDL_WINDOWPOS_UNDEFINED.
    4.57 + *  \param x        The x coordinate of the window in screen coordinates, or
    4.58 + *                  ::SDL_WINDOWPOS_CENTERED or ::SDL_WINDOWPOS_UNDEFINED.
    4.59 + *  \param y        The y coordinate of the window in screen coordinates, or
    4.60 + *                  ::SDL_WINDOWPOS_CENTERED or ::SDL_WINDOWPOS_UNDEFINED.
    4.61   *
    4.62   *  \note The window coordinate origin is the upper left of the display.
    4.63   *
    4.64 @@ -529,8 +537,10 @@
    4.65   *  \brief Get the position of a window.
    4.66   *
    4.67   *  \param window   The window to query.
    4.68 - *  \param x        Pointer to variable for storing the x position, may be NULL
    4.69 - *  \param y        Pointer to variable for storing the y position, may be NULL
    4.70 + *  \param x        Pointer to variable for storing the x position, in screen
    4.71 + *                  coordinates. May be NULL.
    4.72 + *  \param y        Pointer to variable for storing the y position, in screen
    4.73 + *                  coordinates. May be NULL.
    4.74   *
    4.75   *  \sa SDL_SetWindowPosition()
    4.76   */
    4.77 @@ -541,12 +551,17 @@
    4.78   *  \brief Set the size of a window's client area.
    4.79   *
    4.80   *  \param window   The window to resize.
    4.81 - *  \param w        The width of the window, must be >0
    4.82 - *  \param h        The height of the window, must be >0
    4.83 + *  \param w        The width of the window, in screen coordinates. Must be >0.
    4.84 + *  \param h        The height of the window, in screen coordinates. Must be >0.
    4.85   *
    4.86   *  \note You can't change the size of a fullscreen window, it automatically
    4.87   *        matches the size of the display mode.
    4.88   *
    4.89 + *  The window size in screen coordinates may differ from the size in pixels, if
    4.90 + *  the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a platform with
    4.91 + *  high-dpi support (e.g. iOS or OS X). Use SDL_GL_GetDrawableSize or
    4.92 + *  SDL_GetRendererOutputSize to get the real client area size in pixels.
    4.93 + *
    4.94   *  \sa SDL_GetWindowSize()
    4.95   */
    4.96  extern DECLSPEC void SDLCALL SDL_SetWindowSize(SDL_Window * window, int w,
    4.97 @@ -556,8 +571,15 @@
    4.98   *  \brief Get the size of a window's client area.
    4.99   *
   4.100   *  \param window   The window to query.
   4.101 - *  \param w        Pointer to variable for storing the width, may be NULL
   4.102 - *  \param h        Pointer to variable for storing the height, may be NULL
   4.103 + *  \param w        Pointer to variable for storing the width, in screen
   4.104 + *                  coordinates. May be NULL.
   4.105 + *  \param h        Pointer to variable for storing the height, in screen
   4.106 + *                  coordinates. May be NULL.
   4.107 + *
   4.108 + *  The window size in screen coordinates may differ from the size in pixels, if
   4.109 + *  the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a platform with
   4.110 + *  high-dpi support (e.g. iOS or OS X). Use SDL_GL_GetDrawableSize or
   4.111 + *  SDL_GetRendererOutputSize to get the real client area size in pixels.
   4.112   *
   4.113   *  \sa SDL_SetWindowSize()
   4.114   */
   4.115 @@ -1009,11 +1031,12 @@
   4.116  extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_GetCurrentContext(void);
   4.117  
   4.118  /**
   4.119 - *  \brief Get the size of a window's underlying drawable (for use with glViewport).
   4.120 + *  \brief Get the size of a window's underlying drawable in pixels (for use
   4.121 + *         with glViewport).
   4.122   *
   4.123   *  \param window   Window from which the drawable size should be queried
   4.124 - *  \param w        Pointer to variable for storing the width, may be NULL
   4.125 - *  \param h        Pointer to variable for storing the height, may be NULL
   4.126 + *  \param w        Pointer to variable for storing the width in pixels, may be NULL
   4.127 + *  \param h        Pointer to variable for storing the height in pixels, may be NULL
   4.128   *
   4.129   * This may differ from SDL_GetWindowSize() if we're rendering to a high-DPI
   4.130   * drawable, i.e. the window was created with SDL_WINDOW_ALLOW_HIGHDPI on a