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