window.dox 50 KB

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