window.dox 54 KB

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