monitor.dox 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*!
  2. @page monitor_guide Monitor guide
  3. @tableofcontents
  4. This guide introduces the monitor related functions of GLFW. For details on
  5. a specific function in this category, see the @ref monitor. There are also
  6. guides for the other areas of GLFW.
  7. - @ref intro_guide
  8. - @ref window_guide
  9. - @ref context_guide
  10. - @ref vulkan_guide
  11. - @ref input_guide
  12. @section monitor_object Monitor objects
  13. A monitor object represents a currently connected monitor and is represented as
  14. a pointer to the [opaque](https://en.wikipedia.org/wiki/Opaque_data_type) type
  15. @ref GLFWmonitor. Monitor objects cannot be created or destroyed by the
  16. application and retain their addresses until the monitors they represent are
  17. disconnected or until the library is [terminated](@ref intro_init_terminate).
  18. Each monitor has a current video mode, a list of supported video modes,
  19. a virtual position, a human-readable name, an estimated physical size and
  20. a gamma ramp. One of the monitors is the primary monitor.
  21. The virtual position of a monitor is in
  22. [screen coordinates](@ref coordinate_systems) and, together with the current
  23. video mode, describes the viewports that the connected monitors provide into the
  24. virtual desktop that spans them.
  25. To see how GLFW views your monitor setup and its available video modes, run the
  26. `monitors` test program.
  27. @subsection monitor_monitors Retrieving monitors
  28. The primary monitor is returned by @ref glfwGetPrimaryMonitor. It is the user's
  29. preferred monitor and is usually the one with global UI elements like task bar
  30. or menu bar.
  31. @code
  32. GLFWmonitor* primary = glfwGetPrimaryMonitor();
  33. @endcode
  34. You can retrieve all currently connected monitors with @ref glfwGetMonitors.
  35. See the reference documentation for the lifetime of the returned array.
  36. @code
  37. int count;
  38. GLFWmonitor** monitors = glfwGetMonitors(&count);
  39. @endcode
  40. The primary monitor is always the first monitor in the returned array, but other
  41. monitors may be moved to a different index when a monitor is connected or
  42. disconnected.
  43. @subsection monitor_event Monitor configuration changes
  44. If you wish to be notified when a monitor is connected or disconnected, set
  45. a monitor callback.
  46. @code
  47. glfwSetMonitorCallback(monitor_callback);
  48. @endcode
  49. The callback function receives the handle for the monitor that has been
  50. connected or disconnected and the event that occurred.
  51. @code
  52. void monitor_callback(GLFWmonitor* monitor, int event)
  53. {
  54. if (event == GLFW_CONNECTED)
  55. {
  56. // The monitor was connected
  57. }
  58. else if (event == GLFW_DISCONNECTED)
  59. {
  60. // The monitor was disconnected
  61. }
  62. }
  63. @endcode
  64. If a monitor is disconnected, all windows that are full screen on it will be
  65. switched to windowed mode before the callback is called. Only @ref
  66. glfwGetMonitorName and @ref glfwGetMonitorUserPointer will return useful values
  67. for a disconnected monitor and only before the monitor callback returns.
  68. @section monitor_properties Monitor properties
  69. Each monitor has a current video mode, a list of supported video modes,
  70. a virtual position, a content scale, a human-readable name, a user pointer, an
  71. estimated physical size and a gamma ramp.
  72. @subsection monitor_modes Video modes
  73. GLFW generally does a good job selecting a suitable video mode when you create
  74. a full screen window, change its video mode or make a windowed one full
  75. screen, but it is sometimes useful to know exactly which video modes are
  76. supported.
  77. Video modes are represented as @ref GLFWvidmode structures. You can get an
  78. array of the video modes supported by a monitor with @ref glfwGetVideoModes.
  79. See the reference documentation for the lifetime of the returned array.
  80. @code
  81. int count;
  82. GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
  83. @endcode
  84. To get the current video mode of a monitor call @ref glfwGetVideoMode. See the
  85. reference documentation for the lifetime of the returned pointer.
  86. @code
  87. const GLFWvidmode* mode = glfwGetVideoMode(monitor);
  88. @endcode
  89. The resolution of a video mode is specified in
  90. [screen coordinates](@ref coordinate_systems), not pixels.
  91. @subsection monitor_size Physical size
  92. The physical size of a monitor in millimetres, or an estimation of it, can be
  93. retrieved with @ref glfwGetMonitorPhysicalSize. This has no relation to its
  94. current _resolution_, i.e. the width and height of its current
  95. [video mode](@ref monitor_modes).
  96. @code
  97. int width_mm, height_mm;
  98. glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm);
  99. @endcode
  100. While this can be used to calculate the raw DPI of a monitor, this is often not
  101. useful. Instead use the [monitor content scale](@ref monitor_scale) and
  102. [window content scale](@ref window_scale) to scale your content.
  103. @subsection monitor_scale Content scale
  104. The content scale for a monitor can be retrieved with @ref
  105. glfwGetMonitorContentScale.
  106. @code
  107. float xscale, yscale;
  108. glfwGetMonitorContentScale(monitor, &xscale, &yscale);
  109. @endcode
  110. The content scale is the ratio between the current DPI and the platform's
  111. default DPI. This is especially important for text and any UI elements. If the
  112. pixel dimensions of your UI scaled by this look appropriate on your machine then
  113. it should appear at a reasonable size on other machines regardless of their DPI
  114. and scaling settings. This relies on the system DPI and scaling settings being
  115. somewhat correct.
  116. The content scale may depend on both the monitor resolution and pixel density
  117. and on user settings. It may be very different from the raw DPI calculated from
  118. the physical size and current resolution.
  119. @subsection monitor_pos Virtual position
  120. The position of the monitor on the virtual desktop, in
  121. [screen coordinates](@ref coordinate_systems), can be retrieved with @ref
  122. glfwGetMonitorPos.
  123. @code
  124. int xpos, ypos;
  125. glfwGetMonitorPos(monitor, &xpos, &ypos);
  126. @endcode
  127. @subsection monitor_workarea Work area
  128. The area of a monitor not occupied by global task bars or menu bars is the work
  129. area. This is specified in [screen coordinates](@ref coordinate_systems) and
  130. can be retrieved with @ref glfwGetMonitorWorkarea.
  131. @code
  132. int xpos, ypos, width, height;
  133. glfwGetMonitorWorkarea(monitor, &xpos, &ypos, &width, &height);
  134. @endcode
  135. @subsection monitor_name Human-readable name
  136. The human-readable, UTF-8 encoded name of a monitor is returned by @ref
  137. glfwGetMonitorName. See the reference documentation for the lifetime of the
  138. returned string.
  139. @code
  140. const char* name = glfwGetMonitorName(monitor);
  141. @endcode
  142. Monitor names are not guaranteed to be unique. Two monitors of the same model
  143. and make may have the same name. Only the monitor handle is guaranteed to be
  144. unique, and only until that monitor is disconnected.
  145. @subsection monitor_userptr User pointer
  146. Each monitor has a user pointer that can be set with @ref
  147. glfwSetMonitorUserPointer and queried with @ref glfwGetMonitorUserPointer. This
  148. can be used for any purpose you need and will not be modified by GLFW. The
  149. value will be kept until the monitor is disconnected or until the library is
  150. terminated.
  151. The initial value of the pointer is `NULL`.
  152. @subsection monitor_gamma Gamma ramp
  153. The gamma ramp of a monitor can be set with @ref glfwSetGammaRamp, which accepts
  154. a monitor handle and a pointer to a @ref GLFWgammaramp structure.
  155. @code
  156. GLFWgammaramp ramp;
  157. unsigned short red[256], green[256], blue[256];
  158. ramp.size = 256;
  159. ramp.red = red;
  160. ramp.green = green;
  161. ramp.blue = blue;
  162. for (i = 0; i < ramp.size; i++)
  163. {
  164. // Fill out gamma ramp arrays as desired
  165. }
  166. glfwSetGammaRamp(monitor, &ramp);
  167. @endcode
  168. The gamma ramp data is copied before the function returns, so there is no need
  169. to keep it around once the ramp has been set.
  170. It is recommended that your gamma ramp have the same size as the current gamma
  171. ramp for that monitor.
  172. The current gamma ramp for a monitor is returned by @ref glfwGetGammaRamp. See
  173. the reference documentation for the lifetime of the returned structure.
  174. @code
  175. const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor);
  176. @endcode
  177. If you wish to set a regular gamma ramp, you can have GLFW calculate it for you
  178. from the desired exponent with @ref glfwSetGamma, which in turn calls @ref
  179. glfwSetGammaRamp with the resulting ramp.
  180. @code
  181. glfwSetGamma(monitor, 1.0);
  182. @endcode
  183. To experiment with gamma correction via the @ref glfwSetGamma function, run the
  184. `gamma` test program.
  185. @note The software controlled gamma ramp is applied _in addition_ to the
  186. hardware gamma correction, which today is usually an approximation of sRGB
  187. gamma. This means that setting a perfectly linear ramp, or gamma 1.0, will
  188. produce the default (usually sRGB-like) behavior.
  189. */