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