window.dox 55 KB

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