window.dox 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. /*!
  2. @page window_guide Window guide
  3. @tableofcontents
  4. This guide introduces the window related functions of GLFW. For details on
  5. a specific function in this category, see the @ref window. There are also
  6. guides for the other areas of GLFW.
  7. - @ref intro_guide
  8. - @ref context_guide
  9. - @ref vulkan_guide
  10. - @ref monitor_guide
  11. - @ref input_guide
  12. @section window_object Window objects
  13. The @ref GLFWwindow object encapsulates both a window and a context. They are
  14. created with @ref glfwCreateWindow and destroyed with @ref glfwDestroyWindow, or
  15. @ref glfwTerminate, if any remain. As the window and context are inseparably
  16. linked, the object pointer is used as both a context and window handle.
  17. To see the event stream provided to the various window related callbacks, run
  18. the `events` test program.
  19. @subsection window_creation Window creation
  20. A window and its OpenGL or OpenGL ES context are created with @ref
  21. glfwCreateWindow, which returns a handle to the created window object. For
  22. example, this creates a 640 by 480 windowed mode window:
  23. @code
  24. GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);
  25. @endcode
  26. If window creation fails, `NULL` will be returned, so it is necessary to check
  27. the return value.
  28. The window handle is passed to all window related functions and is provided to
  29. along with all input events, so event handlers can tell which window received
  30. the event.
  31. @subsubsection window_full_screen Full screen windows
  32. To create a full screen window, you need to specify which monitor the window
  33. should use. In most cases, the user's primary monitor is a good choice.
  34. For more information about retrieving monitors, see @ref monitor_monitors.
  35. @code
  36. GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", glfwGetPrimaryMonitor(), NULL);
  37. @endcode
  38. Full screen windows cover the entire display area of a monitor, have no border
  39. or decorations.
  40. Windowed mode windows can be made full screen by setting a monitor with @ref
  41. glfwSetWindowMonitor, and full screen ones can be made windowed by unsetting it
  42. with the same function.
  43. Each field of the @ref GLFWvidmode structure corresponds to a function parameter
  44. or window hint and combine to form the _desired video mode_ for that window.
  45. The supported video mode most closely matching the desired video mode will be
  46. set for the chosen monitor as long as the window has input focus. For more
  47. information about retrieving video modes, see @ref monitor_modes.
  48. Video mode field | Corresponds to
  49. ---------------- | --------------
  50. GLFWvidmode.width | `width` parameter of @ref glfwCreateWindow
  51. GLFWvidmode.height | `height` parameter of @ref glfwCreateWindow
  52. GLFWvidmode.redBits | @ref GLFW_RED_BITS hint
  53. GLFWvidmode.greenBits | @ref GLFW_GREEN_BITS hint
  54. GLFWvidmode.blueBits | @ref GLFW_BLUE_BITS hint
  55. GLFWvidmode.refreshRate | @ref GLFW_REFRESH_RATE hint
  56. Once you have a full screen window, you can change its resolution, refresh rate
  57. and monitor with @ref glfwSetWindowMonitor. If you only need change its
  58. resolution you can also call @ref glfwSetWindowSize. In all cases, the new
  59. video mode will be selected the same way as the video mode chosen by @ref
  60. glfwCreateWindow. If the window has an OpenGL or OpenGL ES context, it will be
  61. unaffected.
  62. By default, the original video mode of the monitor will be restored and the
  63. window iconified if it loses input focus, to allow the user to switch back to
  64. the desktop. This behavior can be disabled with the
  65. [GLFW_AUTO_ICONIFY](@ref GLFW_AUTO_ICONIFY_hint) window hint, for example if you
  66. wish to simultaneously cover multiple monitors with full screen windows.
  67. If a monitor is disconnected, all windows that are full screen on that monitor
  68. will be switched to windowed mode. See @ref monitor_event for more information.
  69. @subsubsection window_windowed_full_screen "Windowed full screen" windows
  70. If the closest match for the desired video mode is the current one, the video
  71. mode will not be changed, making window creation faster and application
  72. switching much smoother. This is sometimes called _windowed full screen_ or
  73. _borderless full screen_ window and counts as a full screen window. To create
  74. such a window, request the current video mode.
  75. @code
  76. const GLFWvidmode* mode = glfwGetVideoMode(monitor);
  77. glfwWindowHint(GLFW_RED_BITS, mode->redBits);
  78. glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
  79. glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
  80. glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
  81. GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "My Title", monitor, NULL);
  82. @endcode
  83. This also works for windowed mode windows that are made full screen.
  84. @code
  85. const GLFWvidmode* mode = glfwGetVideoMode(monitor);
  86. glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
  87. @endcode
  88. Note that @ref glfwGetVideoMode returns the _current_ video mode of a monitor,
  89. so if you already have a full screen window on that monitor that you want to
  90. make windowed full screen, you need to have saved the desktop resolution before.
  91. @subsection window_destruction Window destruction
  92. When a window is no longer needed, destroy it with @ref glfwDestroyWindow.
  93. @code
  94. glfwDestroyWindow(window);
  95. @endcode
  96. Window destruction always succeeds. Before the actual destruction, all
  97. callbacks are removed so no further events will be delivered for the window.
  98. All windows remaining when @ref glfwTerminate is called are destroyed as well.
  99. When a full screen window is destroyed, the original video mode of its monitor
  100. is restored, but the gamma ramp is left untouched.
  101. @subsection window_hints Window creation hints
  102. There are a number of hints that can be set before the creation of a window and
  103. context. Some affect the window itself, others affect the framebuffer or
  104. context. These hints are set to their default values each time the library is
  105. initialized with @ref glfwInit. Integer value hints can be set individually
  106. with @ref glfwWindowHint and string value hints with @ref glfwWindowHintString.
  107. You can reset all at once to their defaults with @ref glfwDefaultWindowHints.
  108. Some hints are platform specific. These are always valid to set on any
  109. platform but they will only affect their specific platform. Other platforms
  110. will ignore them. Setting these hints requires no platform specific headers or
  111. calls.
  112. @note Window hints need to be set before the creation of the window and context
  113. you wish to have the specified attributes. They function as additional
  114. arguments to @ref glfwCreateWindow.
  115. @subsubsection window_hints_hard Hard and soft constraints
  116. Some window hints are hard constraints. These must match the available
  117. capabilities _exactly_ for window and context creation to succeed. Hints
  118. that are not hard constraints are matched as closely as possible, but the
  119. resulting context and framebuffer may differ from what these hints requested.
  120. The following hints are always hard constraints:
  121. - @ref GLFW_STEREO
  122. - @ref GLFW_DOUBLEBUFFER
  123. - [GLFW_CLIENT_API](@ref GLFW_CLIENT_API_hint)
  124. - [GLFW_CONTEXT_CREATION_API](@ref GLFW_CONTEXT_CREATION_API_hint)
  125. The following additional hints are hard constraints when requesting an OpenGL
  126. context, but are ignored when requesting an OpenGL ES context:
  127. - [GLFW_OPENGL_FORWARD_COMPAT](@ref GLFW_OPENGL_FORWARD_COMPAT_hint)
  128. - [GLFW_OPENGL_PROFILE](@ref GLFW_OPENGL_PROFILE_hint)
  129. @subsubsection window_hints_wnd Window related hints
  130. @anchor GLFW_RESIZABLE_hint
  131. __GLFW_RESIZABLE__ specifies whether the windowed mode window will be resizable
  132. _by the user_. The window will still be resizable using the @ref
  133. glfwSetWindowSize function. Possible values are `GLFW_TRUE` and `GLFW_FALSE`.
  134. This hint is ignored for full screen and undecorated windows.
  135. @anchor GLFW_VISIBLE_hint
  136. __GLFW_VISIBLE__ specifies whether the windowed mode window will be initially
  137. visible. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This hint is
  138. ignored for full screen windows.
  139. @anchor GLFW_DECORATED_hint
  140. __GLFW_DECORATED__ specifies whether the windowed mode window will have window
  141. decorations such as a border, a close widget, etc. An undecorated window will
  142. not be resizable by the user but will still allow the user to generate close
  143. events on some platforms. Possible values are `GLFW_TRUE` and `GLFW_FALSE`.
  144. This hint is ignored for full screen windows.
  145. @anchor GLFW_FOCUSED_hint
  146. __GLFW_FOCUSED__ specifies whether the windowed mode window will be given input
  147. focus when created. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This
  148. hint is ignored for full screen and initially hidden windows.
  149. @anchor GLFW_AUTO_ICONIFY_hint
  150. __GLFW_AUTO_ICONIFY__ specifies whether the full screen window will
  151. automatically iconify and restore the previous video mode on input focus loss.
  152. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This hint is ignored for
  153. windowed mode windows.
  154. @anchor GLFW_FLOATING_hint
  155. __GLFW_FLOATING__ specifies whether the windowed mode window will be floating
  156. above other regular windows, also called topmost or always-on-top. This is
  157. intended primarily for debugging purposes and cannot be used to implement proper
  158. full screen windows. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This
  159. hint is ignored for full screen windows.
  160. @anchor GLFW_MAXIMIZED_hint
  161. __GLFW_MAXIMIZED__ specifies whether the windowed mode window will be maximized
  162. when created. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This hint is
  163. ignored for full screen windows.
  164. @anchor GLFW_CENTER_CURSOR_hint
  165. __GLFW_CENTER_CURSOR__ specifies whether the cursor should be centered over
  166. newly created full screen windows. Possible values are `GLFW_TRUE` and
  167. `GLFW_FALSE`. This hint is ignored for windowed mode windows.
  168. @anchor GLFW_TRANSPARENT_FRAMEBUFFER_hint
  169. __GLFW_TRANSPARENT_FRAMEBUFFER__ specifies whether the window framebuffer will
  170. be transparent. If enabled and supported by the system, the window framebuffer
  171. alpha channel will be used to combine the framebuffer with the background. This
  172. does not affect window decorations. Possible values are `GLFW_TRUE` and
  173. `GLFW_FALSE`.
  174. @anchor GLFW_FOCUS_ON_SHOW_hint
  175. __GLFW_FOCUS_ON_SHOW__ specifies whether the window will be given input
  176. focus when @ref glfwShowWindow is called. Possible values are `GLFW_TRUE` and
  177. `GLFW_FALSE`.
  178. @anchor GLFW_SCALE_TO_MONITOR
  179. __GLFW_SCALE_TO_MONITOR__ specified whether the window content area should be
  180. resized based on the [monitor content scale](@ref monitor_scale) of any monitor
  181. it is placed on. This includes the initial placement when the window is
  182. created. Possible values are `GLFW_TRUE` and `GLFW_FALSE`.
  183. This hint only has an effect on platforms where screen coordinates and pixels
  184. always map 1:1 such as Windows and X11. On platforms like macOS the resolution
  185. of the framebuffer is changed independently of the window size.
  186. @anchor GLFW_MOUSE_PASSTHROUGH_hint
  187. __GLFW_MOUSE_PASSTHROUGH__ specifies whether the window is transparent to mouse
  188. input, letting any mouse events pass through to whatever window is behind it.
  189. This is only supported for undecorated windows. Decorated windows with this
  190. enabled will behave differently between platforms. Possible values are
  191. `GLFW_TRUE` and `GLFW_FALSE`.
  192. @anchor GLFW_POSITION_X
  193. @anchor GLFW_POSITION_Y
  194. __GLFW_POSITION_X__ and __GLFW_POSITION_Y__ specify the desired initial position
  195. of the window. The window manager may modify or ignore these coordinates. If
  196. either or both of these hints are set to `GLFW_ANY_POSITION` then the window
  197. manager will position the window where it thinks the user will prefer it.
  198. Possible values are any valid screen coordinates and `GLFW_ANY_POSITION`.
  199. @subsubsection window_hints_fb Framebuffer related hints
  200. @anchor GLFW_RED_BITS
  201. @anchor GLFW_GREEN_BITS
  202. @anchor GLFW_BLUE_BITS
  203. @anchor GLFW_ALPHA_BITS
  204. @anchor GLFW_DEPTH_BITS
  205. @anchor GLFW_STENCIL_BITS
  206. __GLFW_RED_BITS__, __GLFW_GREEN_BITS__, __GLFW_BLUE_BITS__, __GLFW_ALPHA_BITS__,
  207. __GLFW_DEPTH_BITS__ and __GLFW_STENCIL_BITS__ specify the desired bit depths of
  208. the various components of the default framebuffer. A value of `GLFW_DONT_CARE`
  209. means the application has no preference.
  210. @anchor GLFW_ACCUM_RED_BITS
  211. @anchor GLFW_ACCUM_GREEN_BITS
  212. @anchor GLFW_ACCUM_BLUE_BITS
  213. @anchor GLFW_ACCUM_ALPHA_BITS
  214. __GLFW_ACCUM_RED_BITS__, __GLFW_ACCUM_GREEN_BITS__, __GLFW_ACCUM_BLUE_BITS__ and
  215. __GLFW_ACCUM_ALPHA_BITS__ specify the desired bit depths of the various
  216. components of the accumulation buffer. A value of `GLFW_DONT_CARE` means the
  217. application has no preference.
  218. Accumulation buffers are a legacy OpenGL feature and should not be used in new
  219. code.
  220. @anchor GLFW_AUX_BUFFERS
  221. __GLFW_AUX_BUFFERS__ specifies the desired number of auxiliary buffers. A value
  222. of `GLFW_DONT_CARE` means the application has no preference.
  223. Auxiliary buffers are a legacy OpenGL feature and should not be used in new
  224. code.
  225. @anchor GLFW_STEREO
  226. __GLFW_STEREO__ specifies whether to use OpenGL stereoscopic rendering.
  227. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This is a hard constraint.
  228. @anchor GLFW_SAMPLES
  229. __GLFW_SAMPLES__ specifies the desired number of samples to use for
  230. multisampling. Zero disables multisampling. A value of `GLFW_DONT_CARE` means
  231. the application has no preference.
  232. @anchor GLFW_SRGB_CAPABLE
  233. __GLFW_SRGB_CAPABLE__ specifies whether the framebuffer should be sRGB capable.
  234. Possible values are `GLFW_TRUE` and `GLFW_FALSE`.
  235. @note __OpenGL:__ If enabled and supported by the system, the
  236. `GL_FRAMEBUFFER_SRGB` enable will control sRGB rendering. By default, sRGB
  237. rendering will be disabled.
  238. @note __OpenGL ES:__ If enabled and supported by the system, the context will
  239. always have sRGB rendering enabled.
  240. @anchor GLFW_DOUBLEBUFFER
  241. @anchor GLFW_DOUBLEBUFFER_hint
  242. __GLFW_DOUBLEBUFFER__ specifies whether the framebuffer should be double
  243. buffered. You nearly always want to use double buffering. This is a hard
  244. constraint. Possible values are `GLFW_TRUE` and `GLFW_FALSE`.
  245. @subsubsection window_hints_mtr Monitor related hints
  246. @anchor GLFW_REFRESH_RATE
  247. __GLFW_REFRESH_RATE__ specifies the desired refresh rate for full screen
  248. windows. A value of `GLFW_DONT_CARE` means the highest available refresh rate
  249. will be used. This hint is ignored for windowed mode windows.
  250. @subsubsection window_hints_ctx Context related hints
  251. @anchor GLFW_CLIENT_API_hint
  252. __GLFW_CLIENT_API__ specifies which client API to create the context for.
  253. Possible values are `GLFW_OPENGL_API`, `GLFW_OPENGL_ES_API` and `GLFW_NO_API`.
  254. This is a hard constraint.
  255. @anchor GLFW_CONTEXT_CREATION_API_hint
  256. __GLFW_CONTEXT_CREATION_API__ specifies which context creation API to use to
  257. create the context. Possible values are `GLFW_NATIVE_CONTEXT_API`,
  258. `GLFW_EGL_CONTEXT_API` and `GLFW_OSMESA_CONTEXT_API`. This is a hard
  259. constraint. If no client API is requested, this hint is ignored.
  260. An [extension loader library](@ref context_glext_auto) that assumes it knows
  261. which API was used to create the current context may fail if you change this
  262. hint. This can be resolved by having it load functions via @ref
  263. glfwGetProcAddress.
  264. @note @wayland The EGL API _is_ the native context creation API, so this hint
  265. will have no effect.
  266. @note @x11 On some Linux systems, creating contexts via both the native and EGL
  267. APIs in a single process will cause the application to segfault. Stick to one
  268. API or the other on Linux for now.
  269. @note __OSMesa:__ As its name implies, an OpenGL context created with OSMesa
  270. does not update the window contents when its buffers are swapped. Use OpenGL
  271. functions or the OSMesa native access functions @ref glfwGetOSMesaColorBuffer
  272. and @ref glfwGetOSMesaDepthBuffer to retrieve the framebuffer contents.
  273. @anchor GLFW_CONTEXT_VERSION_MAJOR_hint
  274. @anchor GLFW_CONTEXT_VERSION_MINOR_hint
  275. __GLFW_CONTEXT_VERSION_MAJOR__ and __GLFW_CONTEXT_VERSION_MINOR__ specify the
  276. client API version that the created context must be compatible with. The exact
  277. behavior of these hints depend on the requested client API.
  278. While there is no way to ask the driver for a context of the highest supported
  279. version, GLFW will attempt to provide this when you ask for a version 1.0
  280. context, which is the default for these hints.
  281. Do not confuse these hints with @ref GLFW_VERSION_MAJOR and @ref
  282. GLFW_VERSION_MINOR, which provide the API version of the GLFW header.
  283. @note __OpenGL:__ These hints are not hard constraints, but creation will fail
  284. if the OpenGL version of the created context is less than the one requested. It
  285. is therefore perfectly safe to use the default of version 1.0 for legacy code
  286. and you will still get backwards-compatible contexts of version 3.0 and above
  287. when available.
  288. @note __OpenGL ES:__ These hints are not hard constraints, but creation will
  289. fail if the OpenGL ES version of the created context is less than the one
  290. requested. Additionally, OpenGL ES 1.x cannot be returned if 2.0 or later was
  291. requested, and vice versa. This is because OpenGL ES 3.x is backward compatible
  292. with 2.0, but OpenGL ES 2.0 is not backward compatible with 1.x.
  293. @note @macos The OS only supports core profile contexts for OpenGL versions 3.2
  294. and later. Before creating an OpenGL context of version 3.2 or later you must
  295. set the [GLFW_OPENGL_PROFILE](@ref GLFW_OPENGL_PROFILE_hint) hint accordingly.
  296. OpenGL 3.0 and 3.1 contexts are not supported at all on macOS.
  297. @anchor GLFW_OPENGL_FORWARD_COMPAT_hint
  298. __GLFW_OPENGL_FORWARD_COMPAT__ specifies whether the OpenGL context should be
  299. forward-compatible, i.e. one where all functionality deprecated in the requested
  300. version of OpenGL is removed. This must only be used if the requested OpenGL
  301. version is 3.0 or above. If OpenGL ES is requested, this hint is ignored.
  302. Forward-compatibility is described in detail in the
  303. [OpenGL Reference Manual](https://www.opengl.org/registry/).
  304. @anchor GLFW_CONTEXT_DEBUG_hint
  305. @anchor GLFW_OPENGL_DEBUG_CONTEXT_hint
  306. __GLFW_CONTEXT_DEBUG__ specifies whether the context should be created in debug
  307. mode, which may provide additional error and diagnostic reporting functionality.
  308. Possible values are `GLFW_TRUE` and `GLFW_FALSE`.
  309. Debug contexts for OpenGL and OpenGL ES are described in detail by the
  310. [GL_KHR_debug](https://www.khronos.org/registry/OpenGL/extensions/KHR/KHR_debug.txt)
  311. extension.
  312. @note `GLFW_CONTEXT_DEBUG` is the new name introduced in GLFW 3.4. The older
  313. `GLFW_OPENGL_DEBUG_CONTEXT` name is also available for compatibility.
  314. @anchor GLFW_OPENGL_PROFILE_hint
  315. __GLFW_OPENGL_PROFILE__ specifies which OpenGL profile to create the context
  316. for. Possible values are one of `GLFW_OPENGL_CORE_PROFILE` or
  317. `GLFW_OPENGL_COMPAT_PROFILE`, or `GLFW_OPENGL_ANY_PROFILE` to not request
  318. a specific profile. If requesting an OpenGL version below 3.2,
  319. `GLFW_OPENGL_ANY_PROFILE` must be used. If OpenGL ES is requested, this hint
  320. is ignored.
  321. OpenGL profiles are described in detail in the
  322. [OpenGL Reference Manual](https://www.opengl.org/registry/).
  323. @anchor GLFW_CONTEXT_ROBUSTNESS_hint
  324. __GLFW_CONTEXT_ROBUSTNESS__ specifies the robustness strategy to be used by the
  325. context. This can be one of `GLFW_NO_RESET_NOTIFICATION` or
  326. `GLFW_LOSE_CONTEXT_ON_RESET`, or `GLFW_NO_ROBUSTNESS` to not request
  327. a robustness strategy.
  328. @anchor GLFW_CONTEXT_RELEASE_BEHAVIOR_hint
  329. __GLFW_CONTEXT_RELEASE_BEHAVIOR__ specifies the release behavior to be
  330. used by the context. Possible values are one of `GLFW_ANY_RELEASE_BEHAVIOR`,
  331. `GLFW_RELEASE_BEHAVIOR_FLUSH` or `GLFW_RELEASE_BEHAVIOR_NONE`. If the
  332. behavior is `GLFW_ANY_RELEASE_BEHAVIOR`, the default behavior of the context
  333. creation API will be used. If the behavior is `GLFW_RELEASE_BEHAVIOR_FLUSH`,
  334. the pipeline will be flushed whenever the context is released from being the
  335. current one. If the behavior is `GLFW_RELEASE_BEHAVIOR_NONE`, the pipeline will
  336. not be flushed on release.
  337. Context release behaviors are described in detail by the
  338. [GL_KHR_context_flush_control](https://www.opengl.org/registry/specs/KHR/context_flush_control.txt)
  339. extension.
  340. @anchor GLFW_CONTEXT_NO_ERROR_hint
  341. __GLFW_CONTEXT_NO_ERROR__ specifies whether errors should be generated by the
  342. context. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. If enabled,
  343. situations that would have generated errors instead cause undefined behavior.
  344. The no error mode for OpenGL and OpenGL ES is described in detail by the
  345. [GL_KHR_no_error](https://www.opengl.org/registry/specs/KHR/no_error.txt)
  346. extension.
  347. @subsubsection window_hints_win32 Win32 specific hints
  348. @anchor GLFW_WIN32_KEYBOARD_MENU_hint
  349. __GLFW_WIN32_KEYBOARD_MENU__ specifies whether to allow access to the window
  350. menu via the Alt+Space and Alt-and-then-Space keyboard shortcuts. This is
  351. ignored on other platforms.
  352. @subsubsection window_hints_osx macOS specific hints
  353. @anchor GLFW_COCOA_RETINA_FRAMEBUFFER_hint
  354. __GLFW_COCOA_RETINA_FRAMEBUFFER__ specifies whether to use full resolution
  355. framebuffers on Retina displays. Possible values are `GLFW_TRUE` and
  356. `GLFW_FALSE`. This is ignored on other platforms.
  357. @anchor GLFW_COCOA_FRAME_NAME_hint
  358. __GLFW_COCOA_FRAME_NAME__ specifies the UTF-8 encoded name to use for autosaving
  359. the window frame, or if empty disables frame autosaving for the window. This is
  360. ignored on other platforms. This is set with @ref glfwWindowHintString.
  361. @anchor GLFW_COCOA_GRAPHICS_SWITCHING_hint
  362. __GLFW_COCOA_GRAPHICS_SWITCHING__ specifies whether to in Automatic Graphics
  363. Switching, i.e. to allow the system to choose the integrated GPU for the OpenGL
  364. context and move it between GPUs if necessary or whether to force it to always
  365. run on the discrete GPU. This only affects systems with both integrated and
  366. discrete GPUs. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. This is
  367. ignored on other platforms.
  368. Simpler programs and tools may want to enable this to save power, while games
  369. and other applications performing advanced rendering will want to leave it
  370. disabled.
  371. A bundled application that wishes to participate in Automatic Graphics Switching
  372. should also declare this in its `Info.plist` by setting the
  373. `NSSupportsAutomaticGraphicsSwitching` key to `true`.
  374. @subsubsection window_hints_x11 X11 specific window hints
  375. @anchor GLFW_X11_CLASS_NAME_hint
  376. @anchor GLFW_X11_INSTANCE_NAME_hint
  377. __GLFW_X11_CLASS_NAME__ and __GLFW_X11_INSTANCE_NAME__ specifies the desired
  378. ASCII encoded class and instance parts of the ICCCM `WM_CLASS` window property.
  379. These are set with @ref glfwWindowHintString.
  380. @subsubsection window_hints_wayland Wayland specific window hints
  381. @anchor GLFW_WAYLAND_APP_ID_hint
  382. __GLFW_WAYLAND_APP_ID__ specifies the Wayland app_id for a window, used
  383. by window managers to identify types of windows. This is set with
  384. @ref glfwWindowHintString.
  385. @subsubsection window_hints_values Supported and default values
  386. Window hint | Default value | Supported values
  387. ----------------------------- | --------------------------- | ----------------
  388. GLFW_RESIZABLE | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
  389. GLFW_VISIBLE | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
  390. GLFW_DECORATED | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
  391. GLFW_FOCUSED | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
  392. GLFW_AUTO_ICONIFY | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
  393. GLFW_FLOATING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  394. GLFW_MAXIMIZED | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  395. GLFW_CENTER_CURSOR | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
  396. GLFW_TRANSPARENT_FRAMEBUFFER | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  397. GLFW_FOCUS_ON_SHOW | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
  398. GLFW_SCALE_TO_MONITOR | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  399. GLFW_MOUSE_PASSTHROUGH | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  400. GLFW_POSITION_X | `GLFW_ANY_POSITION` | Any valid screen x-coordinate or `GLFW_ANY_POSITION`
  401. GLFW_POSITION_Y | `GLFW_ANY_POSITION` | Any valid screen y-coordinate or `GLFW_ANY_POSITION`
  402. GLFW_RED_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  403. GLFW_GREEN_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  404. GLFW_BLUE_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  405. GLFW_ALPHA_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  406. GLFW_DEPTH_BITS | 24 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  407. GLFW_STENCIL_BITS | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  408. GLFW_ACCUM_RED_BITS | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  409. GLFW_ACCUM_GREEN_BITS | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  410. GLFW_ACCUM_BLUE_BITS | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  411. GLFW_ACCUM_ALPHA_BITS | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  412. GLFW_AUX_BUFFERS | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  413. GLFW_SAMPLES | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  414. GLFW_REFRESH_RATE | `GLFW_DONT_CARE` | 0 to `INT_MAX` or `GLFW_DONT_CARE`
  415. GLFW_STEREO | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  416. GLFW_SRGB_CAPABLE | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  417. GLFW_DOUBLEBUFFER | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
  418. GLFW_CLIENT_API | `GLFW_OPENGL_API` | `GLFW_OPENGL_API`, `GLFW_OPENGL_ES_API` or `GLFW_NO_API`
  419. GLFW_CONTEXT_CREATION_API | `GLFW_NATIVE_CONTEXT_API` | `GLFW_NATIVE_CONTEXT_API`, `GLFW_EGL_CONTEXT_API` or `GLFW_OSMESA_CONTEXT_API`
  420. GLFW_CONTEXT_VERSION_MAJOR | 1 | Any valid major version number of the chosen client API
  421. GLFW_CONTEXT_VERSION_MINOR | 0 | Any valid minor version number of the chosen client API
  422. GLFW_CONTEXT_ROBUSTNESS | `GLFW_NO_ROBUSTNESS` | `GLFW_NO_ROBUSTNESS`, `GLFW_NO_RESET_NOTIFICATION` or `GLFW_LOSE_CONTEXT_ON_RESET`
  423. GLFW_CONTEXT_RELEASE_BEHAVIOR | `GLFW_ANY_RELEASE_BEHAVIOR` | `GLFW_ANY_RELEASE_BEHAVIOR`, `GLFW_RELEASE_BEHAVIOR_FLUSH` or `GLFW_RELEASE_BEHAVIOR_NONE`
  424. GLFW_OPENGL_FORWARD_COMPAT | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  425. GLFW_CONTEXT_DEBUG | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  426. GLFW_OPENGL_PROFILE | `GLFW_OPENGL_ANY_PROFILE` | `GLFW_OPENGL_ANY_PROFILE`, `GLFW_OPENGL_COMPAT_PROFILE` or `GLFW_OPENGL_CORE_PROFILE`
  427. GLFW_WIN32_KEYBOARD_MENU | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  428. GLFW_COCOA_RETINA_FRAMEBUFFER | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
  429. GLFW_COCOA_FRAME_NAME | `""` | A UTF-8 encoded frame autosave name
  430. GLFW_COCOA_GRAPHICS_SWITCHING | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
  431. GLFW_X11_CLASS_NAME | `""` | An ASCII encoded `WM_CLASS` class name
  432. GLFW_X11_INSTANCE_NAME | `""` | An ASCII encoded `WM_CLASS` instance name
  433. GLFW_WAYLAND_APP_ID | `""` | An ASCII encoded Wayland `app_id` name
  434. @section window_events Window event processing
  435. See @ref events.
  436. @section window_properties Window properties and events
  437. @subsection window_userptr User pointer
  438. Each window has a user pointer that can be set with @ref
  439. glfwSetWindowUserPointer and queried with @ref glfwGetWindowUserPointer. This
  440. can be used for any purpose you need and will not be modified by GLFW throughout
  441. the life-time of the window.
  442. The initial value of the pointer is `NULL`.
  443. @subsection window_close Window closing and close flag
  444. When the user attempts to close the window, for example by clicking the close
  445. widget or using a key chord like Alt+F4, the _close flag_ of the window is set.
  446. The window is however not actually destroyed and, unless you watch for this
  447. state change, nothing further happens.
  448. The current state of the close flag is returned by @ref glfwWindowShouldClose
  449. and can be set or cleared directly with @ref glfwSetWindowShouldClose. A common
  450. pattern is to use the close flag as a main loop condition.
  451. @code
  452. while (!glfwWindowShouldClose(window))
  453. {
  454. render(window);
  455. glfwSwapBuffers(window);
  456. glfwPollEvents();
  457. }
  458. @endcode
  459. If you wish to be notified when the user attempts to close a window, set a close
  460. callback.
  461. @code
  462. glfwSetWindowCloseCallback(window, window_close_callback);
  463. @endcode
  464. The callback function is called directly _after_ the close flag has been set.
  465. It can be used for example to filter close requests and clear the close flag
  466. again unless certain conditions are met.
  467. @code
  468. void window_close_callback(GLFWwindow* window)
  469. {
  470. if (!time_to_close)
  471. glfwSetWindowShouldClose(window, GLFW_FALSE);
  472. }
  473. @endcode
  474. @subsection window_size Window size
  475. The size of a window can be changed with @ref glfwSetWindowSize. For windowed
  476. mode windows, this sets the size, in
  477. [screen coordinates](@ref coordinate_systems) of the _content area_ or _content
  478. area_ of the window. The window system may impose limits on window size.
  479. @code
  480. glfwSetWindowSize(window, 640, 480);
  481. @endcode
  482. For full screen windows, the specified size becomes the new resolution of the
  483. window's desired video mode. The video mode most closely matching the new
  484. desired video mode is set immediately. The window is resized to fit the
  485. resolution of the set video mode.
  486. If you wish to be notified when a window is resized, whether by the user, the
  487. system or your own code, set a size callback.
  488. @code
  489. glfwSetWindowSizeCallback(window, window_size_callback);
  490. @endcode
  491. The callback function receives the new size, in screen coordinates, of the
  492. content area of the window when the window is resized.
  493. @code
  494. void window_size_callback(GLFWwindow* window, int width, int height)
  495. {
  496. }
  497. @endcode
  498. There is also @ref glfwGetWindowSize for directly retrieving the current size of
  499. a window.
  500. @code
  501. int width, height;
  502. glfwGetWindowSize(window, &width, &height);
  503. @endcode
  504. @note Do not pass the window size to `glViewport` or other pixel-based OpenGL
  505. calls. The window size is in screen coordinates, not pixels. Use the
  506. [framebuffer size](@ref window_fbsize), which is in pixels, for pixel-based
  507. calls.
  508. The above functions work with the size of the content area, but decorated
  509. windows typically have title bars and window frames around this rectangle. You
  510. can retrieve the extents of these with @ref glfwGetWindowFrameSize.
  511. @code
  512. int left, top, right, bottom;
  513. glfwGetWindowFrameSize(window, &left, &top, &right, &bottom);
  514. @endcode
  515. The returned values are the distances, in screen coordinates, from the edges of
  516. the content area to the corresponding edges of the full window. As they are
  517. distances and not coordinates, they are always zero or positive.
  518. @subsection window_fbsize Framebuffer size
  519. While the size of a window is measured in screen coordinates, OpenGL works with
  520. pixels. The size you pass into `glViewport`, for example, should be in pixels.
  521. On some machines screen coordinates and pixels are the same, but on others they
  522. will not be. There is a second set of functions to retrieve the size, in
  523. pixels, of the framebuffer of a window.
  524. If you wish to be notified when the framebuffer of a window is resized, whether
  525. by the user or the system, set a size callback.
  526. @code
  527. glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
  528. @endcode
  529. The callback function receives the new size of the framebuffer when it is
  530. resized, which can for example be used to update the OpenGL viewport.
  531. @code
  532. void framebuffer_size_callback(GLFWwindow* window, int width, int height)
  533. {
  534. glViewport(0, 0, width, height);
  535. }
  536. @endcode
  537. There is also @ref glfwGetFramebufferSize for directly retrieving the current
  538. size of the framebuffer of a window.
  539. @code
  540. int width, height;
  541. glfwGetFramebufferSize(window, &width, &height);
  542. glViewport(0, 0, width, height);
  543. @endcode
  544. The size of a framebuffer may change independently of the size of a window, for
  545. example if the window is dragged between a regular monitor and a high-DPI one.
  546. @subsection window_scale Window content scale
  547. The content scale for a window can be retrieved with @ref
  548. glfwGetWindowContentScale.
  549. @code
  550. float xscale, yscale;
  551. glfwGetWindowContentScale(window, &xscale, &yscale);
  552. @endcode
  553. The content scale is the ratio between the current DPI and the platform's
  554. default DPI. This is especially important for text and any UI elements. If the
  555. pixel dimensions of your UI scaled by this look appropriate on your machine then
  556. it should appear at a reasonable size on other machines regardless of their DPI
  557. and scaling settings. This relies on the system DPI and scaling settings being
  558. somewhat correct.
  559. On systems where each monitors can have its own content scale, the window
  560. content scale will depend on which monitor the system considers the window to be
  561. on.
  562. If you wish to be notified when the content scale of a window changes, whether
  563. because of a system setting change or because it was moved to a monitor with
  564. a different scale, set a content scale callback.
  565. @code
  566. glfwSetWindowContentScaleCallback(window, window_content_scale_callback);
  567. @endcode
  568. The callback function receives the new content scale of the window.
  569. @code
  570. void window_content_scale_callback(GLFWwindow* window, float xscale, float yscale)
  571. {
  572. set_interface_scale(xscale, yscale);
  573. }
  574. @endcode
  575. On platforms where pixels and screen coordinates always map 1:1, the window
  576. will need to be resized to appear the same size when it is moved to a monitor
  577. with a different content scale. To have this done automatically both when the
  578. window is created and when its content scale later changes, set the @ref
  579. GLFW_SCALE_TO_MONITOR window hint.
  580. @subsection window_sizelimits Window size limits
  581. The minimum and maximum size of the content area of a windowed mode window can
  582. be enforced with @ref glfwSetWindowSizeLimits. The user may resize the window
  583. to any size and aspect ratio within the specified limits, unless the aspect
  584. ratio is also set.
  585. @code
  586. glfwSetWindowSizeLimits(window, 200, 200, 400, 400);
  587. @endcode
  588. To specify only a minimum size or only a maximum one, set the other pair to
  589. `GLFW_DONT_CARE`.
  590. @code
  591. glfwSetWindowSizeLimits(window, 640, 480, GLFW_DONT_CARE, GLFW_DONT_CARE);
  592. @endcode
  593. To disable size limits for a window, set them all to `GLFW_DONT_CARE`.
  594. The aspect ratio of the content area of a windowed mode window can be enforced
  595. with @ref glfwSetWindowAspectRatio. The user may resize the window freely
  596. unless size limits are also set, but the size will be constrained to maintain
  597. the aspect ratio.
  598. @code
  599. glfwSetWindowAspectRatio(window, 16, 9);
  600. @endcode
  601. The aspect ratio is specified as a numerator and denominator, corresponding to
  602. the width and height, respectively. If you want a window to maintain its
  603. current aspect ratio, use its current size as the ratio.
  604. @code
  605. int width, height;
  606. glfwGetWindowSize(window, &width, &height);
  607. glfwSetWindowAspectRatio(window, width, height);
  608. @endcode
  609. To disable the aspect ratio limit for a window, set both terms to
  610. `GLFW_DONT_CARE`.
  611. You can have both size limits and aspect ratio set for a window, but the results
  612. are undefined if they conflict.
  613. @subsection window_pos Window position
  614. By default, the window manager chooses the position of new windowed mode
  615. windows, based on its size and which monitor the user appears to be working on.
  616. This is most often the right choice. If you need to create a window at
  617. a specific position, you can set the desired position with the @ref
  618. GLFW_POSITION_X and @ref GLFW_POSITION_Y window hints.
  619. @code
  620. glfwWindowHint(GLFW_POSITION_X, 70);
  621. glfwWindowHint(GLFW_POSITION_Y, 83);
  622. @endcode
  623. To restore the previous behavior, set these hints to `GLFW_ANY_POSITION`.
  624. The position of a windowed mode window can be changed with @ref
  625. glfwSetWindowPos. This moves the window so that the upper-left corner of its
  626. content area has the specified [screen coordinates](@ref coordinate_systems).
  627. The window system may put limitations on window placement.
  628. @code
  629. glfwSetWindowPos(window, 100, 100);
  630. @endcode
  631. If you wish to be notified when a window is moved, whether by the user, the
  632. system or your own code, set a position callback.
  633. @code
  634. glfwSetWindowPosCallback(window, window_pos_callback);
  635. @endcode
  636. The callback function receives the new position, in screen coordinates, of the
  637. upper-left corner of the content area when the window is moved.
  638. @code
  639. void window_pos_callback(GLFWwindow* window, int xpos, int ypos)
  640. {
  641. }
  642. @endcode
  643. There is also @ref glfwGetWindowPos for directly retrieving the current position
  644. of the content area of the window.
  645. @code
  646. int xpos, ypos;
  647. glfwGetWindowPos(window, &xpos, &ypos);
  648. @endcode
  649. @subsection window_title Window title
  650. All GLFW windows have a title, although undecorated or full screen windows may
  651. not display it or only display it in a task bar or similar interface. You can
  652. set a UTF-8 encoded window title with @ref glfwSetWindowTitle.
  653. @code
  654. glfwSetWindowTitle(window, "My Window");
  655. @endcode
  656. The specified string is copied before the function returns, so there is no need
  657. to keep it around.
  658. As long as your source file is encoded as UTF-8, you can use any Unicode
  659. characters directly in the source.
  660. @code
  661. glfwSetWindowTitle(window, "ラストエグザイル");
  662. @endcode
  663. If you are using C++11 or C11, you can use a UTF-8 string literal.
  664. @code
  665. glfwSetWindowTitle(window, u8"This is always a UTF-8 string");
  666. @endcode
  667. @subsection window_icon Window icon
  668. Decorated windows have icons on some platforms. You can set this icon by
  669. specifying a list of candidate images with @ref glfwSetWindowIcon.
  670. @code
  671. GLFWimage images[2];
  672. images[0] = load_icon("my_icon.png");
  673. images[1] = load_icon("my_icon_small.png");
  674. glfwSetWindowIcon(window, 2, images);
  675. @endcode
  676. The image data is 32-bit, little-endian, non-premultiplied RGBA, i.e. eight bits
  677. per channel with the red channel first. The pixels are arranged canonically as
  678. sequential rows, starting from the top-left corner.
  679. To revert to the default window icon, pass in an empty image array.
  680. @code
  681. glfwSetWindowIcon(window, 0, NULL);
  682. @endcode
  683. @subsection window_monitor Window monitor
  684. Full screen windows are associated with a specific monitor. You can get the
  685. handle for this monitor with @ref glfwGetWindowMonitor.
  686. @code
  687. GLFWmonitor* monitor = glfwGetWindowMonitor(window);
  688. @endcode
  689. This monitor handle is one of those returned by @ref glfwGetMonitors.
  690. For windowed mode windows, this function returns `NULL`. This is how to tell
  691. full screen windows from windowed mode windows.
  692. You can move windows between monitors or between full screen and windowed mode
  693. with @ref glfwSetWindowMonitor. When making a window full screen on the same or
  694. on a different monitor, specify the desired monitor, resolution and refresh
  695. rate. The position arguments are ignored.
  696. @code
  697. const GLFWvidmode* mode = glfwGetVideoMode(monitor);
  698. glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
  699. @endcode
  700. When making the window windowed, specify the desired position and size. The
  701. refresh rate argument is ignored.
  702. @code
  703. glfwSetWindowMonitor(window, NULL, xpos, ypos, width, height, 0);
  704. @endcode
  705. This restores any previous window settings such as whether it is decorated,
  706. floating, resizable, has size or aspect ratio limits, etc.. To restore a window
  707. that was originally windowed to its original size and position, save these
  708. before making it full screen and then pass them in as above.
  709. @subsection window_iconify Window iconification
  710. Windows can be iconified (i.e. minimized) with @ref glfwIconifyWindow.
  711. @code
  712. glfwIconifyWindow(window);
  713. @endcode
  714. When a full screen window is iconified, the original video mode of its monitor
  715. is restored until the user or application restores the window.
  716. Iconified windows can be restored with @ref glfwRestoreWindow. This function
  717. also restores windows from maximization.
  718. @code
  719. glfwRestoreWindow(window);
  720. @endcode
  721. When a full screen window is restored, the desired video mode is restored to its
  722. monitor as well.
  723. If you wish to be notified when a window is iconified or restored, whether by
  724. the user, system or your own code, set an iconify callback.
  725. @code
  726. glfwSetWindowIconifyCallback(window, window_iconify_callback);
  727. @endcode
  728. The callback function receives changes in the iconification state of the window.
  729. @code
  730. void window_iconify_callback(GLFWwindow* window, int iconified)
  731. {
  732. if (iconified)
  733. {
  734. // The window was iconified
  735. }
  736. else
  737. {
  738. // The window was restored
  739. }
  740. }
  741. @endcode
  742. You can also get the current iconification state with @ref glfwGetWindowAttrib.
  743. @code
  744. int iconified = glfwGetWindowAttrib(window, GLFW_ICONIFIED);
  745. @endcode
  746. @subsection window_maximize Window maximization
  747. Windows can be maximized (i.e. zoomed) with @ref glfwMaximizeWindow.
  748. @code
  749. glfwMaximizeWindow(window);
  750. @endcode
  751. Full screen windows cannot be maximized and passing a full screen window to this
  752. function does nothing.
  753. Maximized windows can be restored with @ref glfwRestoreWindow. This function
  754. also restores windows from iconification.
  755. @code
  756. glfwRestoreWindow(window);
  757. @endcode
  758. If you wish to be notified when a window is maximized or restored, whether by
  759. the user, system or your own code, set a maximize callback.
  760. @code
  761. glfwSetWindowMaximizeCallback(window, window_maximize_callback);
  762. @endcode
  763. The callback function receives changes in the maximization state of the window.
  764. @code
  765. void window_maximize_callback(GLFWwindow* window, int maximized)
  766. {
  767. if (maximized)
  768. {
  769. // The window was maximized
  770. }
  771. else
  772. {
  773. // The window was restored
  774. }
  775. }
  776. @endcode
  777. You can also get the current maximization state with @ref glfwGetWindowAttrib.
  778. @code
  779. int maximized = glfwGetWindowAttrib(window, GLFW_MAXIMIZED);
  780. @endcode
  781. By default, newly created windows are not maximized. You can change this
  782. behavior by setting the [GLFW_MAXIMIZED](@ref GLFW_MAXIMIZED_hint) window hint
  783. before creating the window.
  784. @code
  785. glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
  786. @endcode
  787. @subsection window_hide Window visibility
  788. Windowed mode windows can be hidden with @ref glfwHideWindow.
  789. @code
  790. glfwHideWindow(window);
  791. @endcode
  792. This makes the window completely invisible to the user, including removing it
  793. from the task bar, dock or window list. Full screen windows cannot be hidden
  794. and calling @ref glfwHideWindow on a full screen window does nothing.
  795. Hidden windows can be shown with @ref glfwShowWindow.
  796. @code
  797. glfwShowWindow(window);
  798. @endcode
  799. By default, this function will also set the input focus to that window. Set
  800. the [GLFW_FOCUS_ON_SHOW](@ref GLFW_FOCUS_ON_SHOW_hint) window hint to change
  801. this behavior for all newly created windows, or change the behavior for an
  802. existing window with @ref glfwSetWindowAttrib.
  803. You can also get the current visibility state with @ref glfwGetWindowAttrib.
  804. @code
  805. int visible = glfwGetWindowAttrib(window, GLFW_VISIBLE);
  806. @endcode
  807. By default, newly created windows are visible. You can change this behavior by
  808. setting the [GLFW_VISIBLE](@ref GLFW_VISIBLE_hint) window hint before creating
  809. the window.
  810. @code
  811. glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
  812. @endcode
  813. Windows created hidden are completely invisible to the user until shown. This
  814. can be useful if you need to set up your window further before showing it, for
  815. example moving it to a specific location.
  816. @subsection window_focus Window input focus
  817. Windows can be given input focus and brought to the front with @ref
  818. glfwFocusWindow.
  819. @code
  820. glfwFocusWindow(window);
  821. @endcode
  822. Keep in mind that it can be very disruptive to the user when a window is forced
  823. to the top. For a less disruptive way of getting the user's attention, see
  824. [attention requests](@ref window_attention).
  825. If you wish to be notified when a window gains or loses input focus, whether by
  826. the user, system or your own code, set a focus callback.
  827. @code
  828. glfwSetWindowFocusCallback(window, window_focus_callback);
  829. @endcode
  830. The callback function receives changes in the input focus state of the window.
  831. @code
  832. void window_focus_callback(GLFWwindow* window, int focused)
  833. {
  834. if (focused)
  835. {
  836. // The window gained input focus
  837. }
  838. else
  839. {
  840. // The window lost input focus
  841. }
  842. }
  843. @endcode
  844. You can also get the current input focus state with @ref glfwGetWindowAttrib.
  845. @code
  846. int focused = glfwGetWindowAttrib(window, GLFW_FOCUSED);
  847. @endcode
  848. By default, newly created windows are given input focus. You can change this
  849. behavior by setting the [GLFW_FOCUSED](@ref GLFW_FOCUSED_hint) window hint
  850. before creating the window.
  851. @code
  852. glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
  853. @endcode
  854. @subsection window_attention Window attention request
  855. If you wish to notify the user of an event without interrupting, you can request
  856. attention with @ref glfwRequestWindowAttention.
  857. @code
  858. glfwRequestWindowAttention(window);
  859. @endcode
  860. The system will highlight the specified window, or on platforms where this is
  861. not supported, the application as a whole. Once the user has given it
  862. attention, the system will automatically end the request.
  863. @subsection window_refresh Window damage and refresh
  864. If you wish to be notified when the contents of a window is damaged and needs
  865. to be refreshed, set a window refresh callback.
  866. @code
  867. glfwSetWindowRefreshCallback(m_handle, window_refresh_callback);
  868. @endcode
  869. The callback function is called when the contents of the window needs to be
  870. refreshed.
  871. @code
  872. void window_refresh_callback(GLFWwindow* window)
  873. {
  874. draw_editor_ui(window);
  875. glfwSwapBuffers(window);
  876. }
  877. @endcode
  878. @note On compositing window systems such as Aero, Compiz or Aqua, where the
  879. window contents are saved off-screen, this callback might only be called when
  880. the window or framebuffer is resized.
  881. @subsection window_transparency Window transparency
  882. GLFW supports two kinds of transparency for windows; framebuffer transparency
  883. and whole window transparency. A single window may not use both methods. The
  884. results of doing this are undefined.
  885. Both methods require the platform to support it and not every version of every
  886. platform GLFW supports does this, so there are mechanisms to check whether the
  887. window really is transparent.
  888. Window framebuffers can be made transparent on a per-pixel per-frame basis with
  889. the [GLFW_TRANSPARENT_FRAMEBUFFER](@ref GLFW_TRANSPARENT_FRAMEBUFFER_hint)
  890. window hint.
  891. @code
  892. glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
  893. @endcode
  894. If supported by the system, the window content area will be composited with the
  895. background using the framebuffer per-pixel alpha channel. This requires desktop
  896. compositing to be enabled on the system. It does not affect window decorations.
  897. You can check whether the window framebuffer was successfully made transparent
  898. with the
  899. [GLFW_TRANSPARENT_FRAMEBUFFER](@ref GLFW_TRANSPARENT_FRAMEBUFFER_attrib)
  900. window attribute.
  901. @code
  902. if (glfwGetWindowAttrib(window, GLFW_TRANSPARENT_FRAMEBUFFER))
  903. {
  904. // window framebuffer is currently transparent
  905. }
  906. @endcode
  907. GLFW comes with an example that enabled framebuffer transparency called `gears`.
  908. The opacity of the whole window, including any decorations, can be set with @ref
  909. glfwSetWindowOpacity.
  910. @code
  911. glfwSetWindowOpacity(window, 0.5f);
  912. @endcode
  913. The opacity (or alpha) value is a positive finite number between zero and one,
  914. where 0 (zero) is fully transparent and 1 (one) is fully opaque. The initial
  915. opacity value for newly created windows is 1.
  916. The current opacity of a window can be queried with @ref glfwGetWindowOpacity.
  917. @code
  918. float opacity = glfwGetWindowOpacity(window);
  919. @endcode
  920. If the system does not support whole window transparency, this function always
  921. returns one.
  922. GLFW comes with a test program that lets you control whole window transparency
  923. at run-time called `window`.
  924. If you want to use either of these transparency methods to display a temporary
  925. overlay like for example a notification, the @ref GLFW_FLOATING and @ref
  926. GLFW_MOUSE_PASSTHROUGH window hints and attributes may be useful.
  927. @subsection window_attribs Window attributes
  928. Windows have a number of attributes that can be returned using @ref
  929. glfwGetWindowAttrib. Some reflect state that may change as a result of user
  930. interaction, (e.g. whether it has input focus), while others reflect inherent
  931. properties of the window (e.g. what kind of border it has). Some are related to
  932. the window and others to its OpenGL or OpenGL ES context.
  933. @code
  934. if (glfwGetWindowAttrib(window, GLFW_FOCUSED))
  935. {
  936. // window has input focus
  937. }
  938. @endcode
  939. The [GLFW_DECORATED](@ref GLFW_DECORATED_attrib),
  940. [GLFW_RESIZABLE](@ref GLFW_RESIZABLE_attrib),
  941. [GLFW_FLOATING](@ref GLFW_FLOATING_attrib),
  942. [GLFW_AUTO_ICONIFY](@ref GLFW_AUTO_ICONIFY_attrib) and
  943. [GLFW_FOCUS_ON_SHOW](@ref GLFW_FOCUS_ON_SHOW_attrib) window attributes can be
  944. changed with @ref glfwSetWindowAttrib.
  945. @code
  946. glfwSetWindowAttrib(window, GLFW_RESIZABLE, GLFW_FALSE);
  947. @endcode
  948. @subsubsection window_attribs_wnd Window related attributes
  949. @anchor GLFW_FOCUSED_attrib
  950. __GLFW_FOCUSED__ indicates whether the specified window has input focus. See
  951. @ref window_focus for details.
  952. @anchor GLFW_ICONIFIED_attrib
  953. __GLFW_ICONIFIED__ indicates whether the specified window is iconified.
  954. See @ref window_iconify for details.
  955. @anchor GLFW_MAXIMIZED_attrib
  956. __GLFW_MAXIMIZED__ indicates whether the specified window is maximized. See
  957. @ref window_maximize for details.
  958. @anchor GLFW_HOVERED_attrib
  959. __GLFW_HOVERED__ indicates whether the cursor is currently directly over the
  960. content area of the window, with no other windows between. See @ref
  961. cursor_enter for details.
  962. @anchor GLFW_VISIBLE_attrib
  963. __GLFW_VISIBLE__ indicates whether the specified window is visible. See @ref
  964. window_hide for details.
  965. @anchor GLFW_RESIZABLE_attrib
  966. __GLFW_RESIZABLE__ indicates whether the specified window is resizable _by the
  967. user_. This can be set before creation with the
  968. [GLFW_RESIZABLE](@ref GLFW_RESIZABLE_hint) window hint or after with @ref
  969. glfwSetWindowAttrib.
  970. @anchor GLFW_DECORATED_attrib
  971. __GLFW_DECORATED__ indicates whether the specified window has decorations such
  972. as a border, a close widget, etc. This can be set before creation with the
  973. [GLFW_DECORATED](@ref GLFW_DECORATED_hint) window hint or after with @ref
  974. glfwSetWindowAttrib.
  975. @anchor GLFW_AUTO_ICONIFY_attrib
  976. __GLFW_AUTO_ICONIFY__ indicates whether the specified full screen window is
  977. iconified on focus loss, a close widget, etc. This can be set before creation
  978. with the [GLFW_AUTO_ICONIFY](@ref GLFW_AUTO_ICONIFY_hint) window hint or after
  979. with @ref glfwSetWindowAttrib.
  980. @anchor GLFW_FLOATING_attrib
  981. __GLFW_FLOATING__ indicates whether the specified window is floating, also
  982. called topmost or always-on-top. This can be set before creation with the
  983. [GLFW_FLOATING](@ref GLFW_FLOATING_hint) window hint or after with @ref
  984. glfwSetWindowAttrib.
  985. @anchor GLFW_TRANSPARENT_FRAMEBUFFER_attrib
  986. __GLFW_TRANSPARENT_FRAMEBUFFER__ indicates whether the specified window has
  987. a transparent framebuffer, i.e. the window contents is composited with the
  988. background using the window framebuffer alpha channel. See @ref
  989. window_transparency for details.
  990. @anchor GLFW_FOCUS_ON_SHOW_attrib
  991. __GLFW_FOCUS_ON_SHOW__ specifies whether the window will be given input
  992. focus when @ref glfwShowWindow is called. This can be set before creation
  993. with the [GLFW_FOCUS_ON_SHOW](@ref GLFW_FOCUS_ON_SHOW_hint) window hint or
  994. after with @ref glfwSetWindowAttrib.
  995. @anchor GLFW_MOUSE_PASSTHROUGH_attrib
  996. __GLFW_MOUSE_PASSTHROUGH__ specifies whether the window is transparent to mouse
  997. input, letting any mouse events pass through to whatever window is behind it.
  998. This can be set before creation with the
  999. [GLFW_MOUSE_PASSTHROUGH](@ref GLFW_MOUSE_PASSTHROUGH_hint) window hint or after
  1000. with @ref glfwSetWindowAttrib. This is only supported for undecorated windows.
  1001. Decorated windows with this enabled will behave differently between platforms.
  1002. @subsubsection window_attribs_ctx Context related attributes
  1003. @anchor GLFW_CLIENT_API_attrib
  1004. __GLFW_CLIENT_API__ indicates the client API provided by the window's context;
  1005. either `GLFW_OPENGL_API`, `GLFW_OPENGL_ES_API` or `GLFW_NO_API`.
  1006. @anchor GLFW_CONTEXT_CREATION_API_attrib
  1007. __GLFW_CONTEXT_CREATION_API__ indicates the context creation API used to create
  1008. the window's context; either `GLFW_NATIVE_CONTEXT_API`, `GLFW_EGL_CONTEXT_API`
  1009. or `GLFW_OSMESA_CONTEXT_API`.
  1010. @anchor GLFW_CONTEXT_VERSION_MAJOR_attrib
  1011. @anchor GLFW_CONTEXT_VERSION_MINOR_attrib
  1012. @anchor GLFW_CONTEXT_REVISION_attrib
  1013. __GLFW_CONTEXT_VERSION_MAJOR__, __GLFW_CONTEXT_VERSION_MINOR__ and
  1014. __GLFW_CONTEXT_REVISION__ indicate the client API version of the window's
  1015. context.
  1016. @note Do not confuse these attributes with `GLFW_VERSION_MAJOR`,
  1017. `GLFW_VERSION_MINOR` and `GLFW_VERSION_REVISION` which provide the API version
  1018. of the GLFW header.
  1019. @anchor GLFW_OPENGL_FORWARD_COMPAT_attrib
  1020. __GLFW_OPENGL_FORWARD_COMPAT__ is `GLFW_TRUE` if the window's context is an
  1021. OpenGL forward-compatible one, or `GLFW_FALSE` otherwise.
  1022. @anchor GLFW_CONTEXT_DEBUG_attrib
  1023. @anchor GLFW_OPENGL_DEBUG_CONTEXT_attrib
  1024. __GLFW_CONTEXT_DEBUG__ is `GLFW_TRUE` if the window's context is in debug
  1025. mode, or `GLFW_FALSE` otherwise.
  1026. @par
  1027. This is the new name, introduced in GLFW 3.4. The older
  1028. `GLFW_OPENGL_DEBUG_CONTEXT` name is also available for compatibility.
  1029. @anchor GLFW_OPENGL_PROFILE_attrib
  1030. __GLFW_OPENGL_PROFILE__ indicates the OpenGL profile used by the context. This
  1031. is `GLFW_OPENGL_CORE_PROFILE` or `GLFW_OPENGL_COMPAT_PROFILE` if the context
  1032. uses a known profile, or `GLFW_OPENGL_ANY_PROFILE` if the OpenGL profile is
  1033. unknown or the context is an OpenGL ES context. Note that the returned profile
  1034. may not match the profile bits of the context flags, as GLFW will try other
  1035. means of detecting the profile when no bits are set.
  1036. @anchor GLFW_CONTEXT_RELEASE_BEHAVIOR_attrib
  1037. __GLFW_CONTEXT_RELEASE_BEHAVIOR__ indicates the release used by the context.
  1038. Possible values are one of `GLFW_ANY_RELEASE_BEHAVIOR`,
  1039. `GLFW_RELEASE_BEHAVIOR_FLUSH` or `GLFW_RELEASE_BEHAVIOR_NONE`. If the
  1040. behavior is `GLFW_ANY_RELEASE_BEHAVIOR`, the default behavior of the context
  1041. creation API will be used. If the behavior is `GLFW_RELEASE_BEHAVIOR_FLUSH`,
  1042. the pipeline will be flushed whenever the context is released from being the
  1043. current one. If the behavior is `GLFW_RELEASE_BEHAVIOR_NONE`, the pipeline will
  1044. not be flushed on release.
  1045. @anchor GLFW_CONTEXT_NO_ERROR_attrib
  1046. __GLFW_CONTEXT_NO_ERROR__ indicates whether errors are generated by the context.
  1047. Possible values are `GLFW_TRUE` and `GLFW_FALSE`. If enabled, situations that
  1048. would have generated errors instead cause undefined behavior.
  1049. @anchor GLFW_CONTEXT_ROBUSTNESS_attrib
  1050. __GLFW_CONTEXT_ROBUSTNESS__ indicates the robustness strategy used by the
  1051. context. This is `GLFW_LOSE_CONTEXT_ON_RESET` or `GLFW_NO_RESET_NOTIFICATION`
  1052. if the window's context supports robustness, or `GLFW_NO_ROBUSTNESS` otherwise.
  1053. @subsubsection window_attribs_fb Framebuffer related attributes
  1054. GLFW does not expose most attributes of the default framebuffer (i.e. the
  1055. framebuffer attached to the window) as these can be queried directly with either
  1056. OpenGL, OpenGL ES or Vulkan. The one exception is
  1057. [GLFW_DOUBLEBUFFER](@ref GLFW_DOUBLEBUFFER_attrib), as this is not provided by
  1058. OpenGL ES.
  1059. If you are using version 3.0 or later of OpenGL or OpenGL ES, the
  1060. `glGetFramebufferAttachmentParameteriv` function can be used to retrieve the
  1061. number of bits for the red, green, blue, alpha, depth and stencil buffer
  1062. channels. Otherwise, the `glGetIntegerv` function can be used.
  1063. The number of MSAA samples are always retrieved with `glGetIntegerv`. For
  1064. contexts supporting framebuffer objects, the number of samples of the currently
  1065. bound framebuffer is returned.
  1066. Attribute | glGetIntegerv | glGetFramebufferAttachmentParameteriv
  1067. ------------ | ----------------- | -------------------------------------
  1068. Red bits | `GL_RED_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE`
  1069. Green bits | `GL_GREEN_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE`
  1070. Blue bits | `GL_BLUE_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE`
  1071. Alpha bits | `GL_ALPHA_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE`
  1072. Depth bits | `GL_DEPTH_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE`
  1073. Stencil bits | `GL_STENCIL_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE`
  1074. MSAA samples | `GL_SAMPLES` | _Not provided by this function_
  1075. When calling `glGetFramebufferAttachmentParameteriv`, the red, green, blue and
  1076. alpha sizes are queried from the `GL_BACK_LEFT`, while the depth and stencil
  1077. sizes are queried from the `GL_DEPTH` and `GL_STENCIL` attachments,
  1078. respectively.
  1079. @anchor GLFW_DOUBLEBUFFER_attrib
  1080. __GLFW_DOUBLEBUFFER__ indicates whether the specified window is double-buffered
  1081. when rendering with OpenGL or OpenGL ES. This can be set before creation with
  1082. the [GLFW_DOUBLEBUFFER](@ref GLFW_DOUBLEBUFFER_hint) window hint.
  1083. @section buffer_swap Buffer swapping
  1084. GLFW windows are by default double buffered. That means that you have two
  1085. rendering buffers; a front buffer and a back buffer. The front buffer is
  1086. the one being displayed and the back buffer the one you render to.
  1087. When the entire frame has been rendered, it is time to swap the back and the
  1088. front buffers in order to display what has been rendered and begin rendering
  1089. a new frame. This is done with @ref glfwSwapBuffers.
  1090. @code
  1091. glfwSwapBuffers(window);
  1092. @endcode
  1093. Sometimes it can be useful to select when the buffer swap will occur. With the
  1094. function @ref glfwSwapInterval it is possible to select the minimum number of
  1095. monitor refreshes the driver should wait from the time @ref glfwSwapBuffers was
  1096. called before swapping the buffers:
  1097. @code
  1098. glfwSwapInterval(1);
  1099. @endcode
  1100. If the interval is zero, the swap will take place immediately when @ref
  1101. glfwSwapBuffers is called without waiting for a refresh. Otherwise at least
  1102. interval retraces will pass between each buffer swap. Using a swap interval of
  1103. zero can be useful for benchmarking purposes, when it is not desirable to
  1104. measure the time it takes to wait for the vertical retrace. However, a swap
  1105. interval of one lets you avoid tearing.
  1106. Note that this may not work on all machines, as some drivers have
  1107. user-controlled settings that override any swap interval the application
  1108. requests.
  1109. A context that supports either the `WGL_EXT_swap_control_tear` or the
  1110. `GLX_EXT_swap_control_tear` extension also accepts _negative_ swap intervals,
  1111. which allows the driver to swap immediately even if a frame arrives a little bit
  1112. late. This trades the risk of visible tears for greater framerate stability.
  1113. You can check for these extensions with @ref glfwExtensionSupported.
  1114. */