1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-29 21:48:52 -05:00
glfw/docs/window.dox

902 lines
34 KiB
Plaintext
Raw Normal View History

2013-05-27 11:10:34 -04:00
/*!
2014-09-18 09:03:29 -04:00
@page window Window guide
2013-04-10 19:07:07 -04:00
@tableofcontents
2014-09-18 09:03:29 -04:00
This guide introduces the window related functions of GLFW. There are also
guides for the other areas of GLFW.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
- @ref intro
- @ref context
- @ref monitor
- @ref input
@section window_object Window objects
2013-04-10 19:07:07 -04:00
The @ref GLFWwindow object encapsulates both a window and a context. They are
2015-01-17 19:55:25 -05:00
created with @ref glfwCreateWindow and destroyed with @ref glfwDestroyWindow, or
@ref glfwTerminate, if any remain. As the window and context are inseparably
2013-05-27 11:10:34 -04:00
linked, the object pointer is used as both a context and window handle.
2013-04-10 19:07:07 -04:00
2015-01-11 12:25:54 -05:00
To see the event stream provided to the various window related callbacks, run
the `events` test program.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
@subsection window_creation Window creation
2013-07-07 06:06:59 -04:00
2014-09-18 09:03:29 -04:00
A window and its OpenGL or OpenGL ES context are created with @ref
glfwCreateWindow, which returns a handle to the created window object. For
example, this creates a 640 by 480 windowed mode window:
2013-07-07 06:06:59 -04:00
@code
GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);
2014-09-18 09:03:29 -04:00
@endcode
If window creation fails, `NULL` will be returned, so it is necessary to check
the return value.
The window handle is passed to all window related functions and is provided to
along with all input events, so event handlers can tell which window received
the event.
2013-07-07 06:06:59 -04:00
2014-10-02 11:35:10 -04:00
@subsubsection window_full_screen Full screen windows
2013-07-07 06:06:59 -04:00
To create a full screen window, you need to specify which monitor the window
2014-10-02 11:35:10 -04:00
should use. In most cases, the user's primary monitor is a good choice.
For more information about retrieving monitors, see @ref monitor_monitors.
2013-07-07 06:06:59 -04:00
@code
GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", glfwGetPrimaryMonitor(), NULL);
@endcode
Full screen windows cover the entire display area of a monitor, have no border
2014-10-02 11:35:10 -04:00
or decorations.
2014-10-07 13:23:35 -04:00
Each field of the @ref GLFWvidmode structure corresponds to a function parameter
or window hint and combine to form the _desired video mode_ for that window.
The supported video mode most closely matching the desired video mode will be
2015-01-17 19:55:25 -05:00
set for the chosen monitor as long as the window has input focus. For more
2014-10-07 13:23:35 -04:00
information about retrieving video modes, see @ref monitor_modes.
2014-10-02 11:35:10 -04:00
Video mode field | Corresponds to
----------------------- | ------------------------
GLFWvidmode.width | `width` parameter
GLFWvidmode.height | `height` parameter
GLFWvidmode.redBits | `GLFW_RED_BITS` hint
GLFWvidmode.greenBits | `GLFW_GREEN_BITS` hint
GLFWvidmode.blueBits | `GLFW_BLUE_BITS` hint
GLFWvidmode.refreshRate | `GLFW_REFRESH_RATE` hint
Once you have a full screen window, you can change its resolution with @ref
glfwSetWindowSize. The new video mode will be selected and set the same way as
the video mode chosen by @ref glfwCreateWindow.
By default, the original video mode of the monitor will be restored and the
window iconified if it loses input focus, to allow the user to switch back to
2014-10-07 13:23:35 -04:00
the desktop. This behavior can be disabled with the `GLFW_AUTO_ICONIFY` window
hint, for example if you wish to simultaneously cover multiple windows with full
screen windows.
2013-07-07 06:06:59 -04:00
2014-12-28 22:38:02 -05:00
2014-12-18 10:21:15 -05:00
@subsubsection window_windowed_full_screen "Windowed full screen" windows
If the closest match for the desired video mode is the current one, the video
mode will not be changed, making window creation faster and application
switching much smoother. This is sometimes called _windowed full screen_ or
_borderless full screen_ window and counts as a full screen window. To create
such a window, simply request the current video mode.
2014-10-02 11:35:10 -04:00
@code
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
glfwWindowHint(GLFW_GREEN_BITS, mode->greenBits);
glfwWindowHint(GLFW_BLUE_BITS, mode->blueBits);
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "My Title", monitor, NULL);
@endcode
2013-07-07 06:06:59 -04:00
2014-09-18 09:03:29 -04:00
@subsection window_destruction Window destruction
2013-07-07 06:06:59 -04:00
2014-09-18 09:03:29 -04:00
When a window is no longer needed, destroy it with @ref glfwDestroyWindow.
2013-07-07 06:06:59 -04:00
@code
glfwDestroyWindow(window);
@endcode
2014-09-18 09:03:29 -04:00
Window destruction always succeeds. Before the actual destruction, all
callbacks are removed so no further events will be delivered for the window.
2014-10-07 13:23:35 -04:00
All windows remaining when @ref glfwTerminate is called are destroyed as well.
2013-07-07 06:06:59 -04:00
2014-09-18 09:03:29 -04:00
When a full screen window is destroyed, the original video mode of its monitor
is restored, but the gamma ramp is left untouched.
2013-07-07 06:06:59 -04:00
2014-09-18 09:03:29 -04:00
@subsection window_hints Window creation hints
2013-04-10 19:07:07 -04:00
2013-05-27 11:10:34 -04:00
There are a number of hints that can be set before the creation of a window and
context. Some affect the window itself, others affect the framebuffer or
context. These hints are set to their default values each time the library is
initialized with @ref glfwInit, can be set individually with @ref glfwWindowHint
and reset all at once to their defaults with @ref glfwDefaultWindowHints.
2013-04-10 19:07:07 -04:00
2014-10-02 11:35:10 -04:00
Note that hints need to be set _before_ the creation of the window and context
2013-05-27 11:10:34 -04:00
you wish to have the specified attributes.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
@subsubsection window_hints_hard Hard and soft constraints
2013-04-10 19:07:07 -04:00
Some window hints are hard constraints. These must match the available
2014-10-02 11:35:10 -04:00
capabilities _exactly_ for window and context creation to succeed. Hints
2013-04-10 19:07:07 -04:00
that are not hard constraints are matched as closely as possible, but the
resulting context and framebuffer may differ from what these hints requested.
2013-04-10 19:07:07 -04:00
2014-04-23 07:30:11 -04:00
The following hints are always hard constraints:
2013-04-10 19:07:07 -04:00
- `GLFW_STEREO`
2014-04-24 13:21:10 -04:00
- `GLFW_DOUBLEBUFFER`
2013-04-10 19:07:07 -04:00
- `GLFW_CLIENT_API`
2014-04-23 07:30:11 -04:00
The following additional hints are hard constraints when requesting an OpenGL
context, but are ignored when requesting an OpenGL ES context:
2013-04-10 19:07:07 -04:00
- `GLFW_OPENGL_FORWARD_COMPAT`
- `GLFW_OPENGL_PROFILE`
2014-09-18 09:03:29 -04:00
@subsubsection window_hints_wnd Window related hints
2013-05-27 11:10:34 -04:00
2015-04-19 07:48:25 -04:00
`GLFW_RESIZABLE` specifies whether the windowed mode window will be resizable
2014-10-02 11:35:10 -04:00
_by the user_. The window will still be resizable using the @ref
glfwSetWindowSize function. This hint is ignored for full screen windows.
2013-05-27 11:10:34 -04:00
2015-04-19 07:48:25 -04:00
`GLFW_VISIBLE` specifies whether the windowed mode window will be initially
2014-09-18 09:03:29 -04:00
visible. This hint is ignored for full screen windows.
2013-05-27 11:10:34 -04:00
2015-04-19 07:48:25 -04:00
`GLFW_DECORATED` specifies whether the windowed mode window will have window
decorations such as a border, a close widget, etc. An undecorated window may
still allow the user to generate close events on some platforms. This hint is
ignored for full screen windows.
2015-04-19 07:48:25 -04:00
`GLFW_FOCUSED` specifies whether the windowed mode window will be given input
2014-09-18 09:03:29 -04:00
focus when created. This hint is ignored for full screen and initially hidden
windows.
2015-04-19 07:48:25 -04:00
`GLFW_AUTO_ICONIFY` specifies whether the full screen window will
2015-01-17 19:55:25 -05:00
automatically iconify and restore the previous video mode on input focus loss.
This hint is ignored for windowed mode windows.
2013-05-27 11:10:34 -04:00
2015-04-19 07:48:25 -04:00
`GLFW_FLOATING` specifies whether the windowed mode window will be floating
above other regular windows, also called topmost or always-on-top. This is
intended primarily for debugging purposes and cannot be used to implement proper
full screen windows. This hint is ignored for full screen windows.
2014-05-23 08:01:02 -04:00
2013-05-27 11:10:34 -04:00
2014-09-18 09:03:29 -04:00
@subsubsection window_hints_fb Framebuffer related hints
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_RED_BITS`, `GLFW_GREEN_BITS`, `GLFW_BLUE_BITS`, `GLFW_ALPHA_BITS`,
`GLFW_DEPTH_BITS` and `GLFW_STENCIL_BITS` specify the desired bit depths of the
various components of the default framebuffer. `GLFW_DONT_CARE` means the
application has no preference.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_ACCUM_RED_BITS`, `GLFW_ACCUM_GREEN_BITS`, `GLFW_ACCUM_BLUE_BITS` and
`GLFW_ACCUM_ALPHA_BITS` specify the desired bit depths of the various components
of the accumulation buffer. `GLFW_DONT_CARE` means the application has no
preference.
2014-10-07 17:37:59 -04:00
@par
Accumulation buffers are a legacy OpenGL feature and should not be used in new
code.
2014-04-23 07:30:11 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_AUX_BUFFERS` specifies the desired number of auxiliary buffers.
`GLFW_DONT_CARE` means the application has no preference.
2013-04-10 19:07:07 -04:00
2014-10-07 17:37:59 -04:00
@par
Auxiliary buffers are a legacy OpenGL feature and should not be used in new
code.
2014-04-23 07:30:11 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_STEREO` specifies whether to use stereoscopic rendering. This is a hard
constraint.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_SAMPLES` specifies the desired number of samples to use for multisampling.
Zero disables multisampling. `GLFW_DONT_CARE` means the application has no
preference.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_SRGB_CAPABLE` specifies whether the framebuffer should be sRGB capable.
If supported, the created context will provide `GL_ARB_framebuffer_sRGB` or
`GL_EXT_framebuffer_sRGB`.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_DOUBLEBUFFER` specifies whether the framebuffer should be double buffered.
You nearly always want to use double buffering. This is a hard constraint.
2014-04-24 13:21:10 -04:00
2013-05-30 14:42:50 -04:00
2014-09-18 09:03:29 -04:00
@subsubsection window_hints_mtr Monitor related hints
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_REFRESH_RATE` specifies the desired refresh rate for full screen windows.
2014-10-06 17:18:33 -04:00
If set to `GLFW_DONT_CARE`, the highest available refresh rate will be used.
This hint is ignored for windowed mode windows.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
@subsubsection window_hints_ctx Context related hints
`GLFW_CLIENT_API` specifies which client API to create the context for.
Possible values are `GLFW_OPENGL_API` and `GLFW_OPENGL_ES_API`. This is a hard
constraint.
`GLFW_CONTEXT_VERSION_MAJOR` and `GLFW_CONTEXT_VERSION_MINOR` specify the client
2014-10-07 13:23:35 -04:00
API version that the created context must be compatible with. The exact
behavior of these hints depend on the requested client API.
2013-04-10 19:07:07 -04:00
2014-12-16 19:31:36 -05:00
@par
__OpenGL:__ `GLFW_CONTEXT_VERSION_MAJOR` and `GLFW_CONTEXT_VERSION_MINOR` are not hard
2014-10-07 13:23:35 -04:00
constraints, but creation will fail if the OpenGL version of the created context
is less than the one requested. It is therefore perfectly safe to use the
default of version 1.0 for legacy code and you may still get
backwards-compatible contexts of version 3.0 and above when available.
2013-04-10 19:07:07 -04:00
2014-10-07 13:23:35 -04:00
@par
2013-04-10 19:07:07 -04:00
While there is no way to ask the driver for a context of the highest supported
2014-10-07 13:23:35 -04:00
version, GLFW will attempt to provide this when you ask for a version 1.0
context, which is the default for these hints.
2014-12-16 19:31:36 -05:00
@par
__OpenGL ES:__ `GLFW_CONTEXT_VERSION_MAJOR` and `GLFW_CONTEXT_VERSION_MINOR` are not hard
2014-10-07 13:23:35 -04:00
constraints, but creation will fail if the OpenGL ES version of the created
context is less than the one requested. Additionally, OpenGL ES 1.x cannot be
returned if 2.0 or later was requested, and vice versa. This is because OpenGL
2015-01-05 10:46:04 -05:00
ES 3.x is backward compatible with 2.0, but OpenGL ES 2.0 is not backward
2014-10-07 13:23:35 -04:00
compatible with 1.x.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_OPENGL_FORWARD_COMPAT` specifies whether the OpenGL context should be
forward-compatible, i.e. one where all functionality deprecated in the requested
version of OpenGL is removed. This may only be used if the requested OpenGL
2015-01-05 10:46:04 -05:00
version is 3.0 or above. If OpenGL ES is requested, this hint is ignored.
2013-04-10 19:07:07 -04:00
2014-10-07 17:37:59 -04:00
@par
2014-09-18 09:03:29 -04:00
Forward-compatibility is described in detail in the
2014-08-14 19:04:03 -04:00
[OpenGL Reference Manual](https://www.opengl.org/registry/).
2014-09-18 09:03:29 -04:00
`GLFW_OPENGL_DEBUG_CONTEXT` specifies whether to create a debug OpenGL context,
which may have additional error and performance issue reporting functionality.
If OpenGL ES is requested, this hint is ignored.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_OPENGL_PROFILE` specifies which OpenGL profile to create the context for.
Possible values are one of `GLFW_OPENGL_CORE_PROFILE` or
`GLFW_OPENGL_COMPAT_PROFILE`, or `GLFW_OPENGL_ANY_PROFILE` to not request
a specific profile. If requesting an OpenGL version below 3.2,
2015-03-10 14:50:48 -04:00
`GLFW_OPENGL_ANY_PROFILE` must be used. If OpenGL ES is requested,
2014-09-18 09:03:29 -04:00
this hint is ignored.
2013-04-10 19:07:07 -04:00
2014-10-07 17:37:59 -04:00
@par
2014-09-18 09:03:29 -04:00
OpenGL profiles are described in detail in the
2014-08-14 19:04:03 -04:00
[OpenGL Reference Manual](https://www.opengl.org/registry/).
2014-09-18 09:03:29 -04:00
`GLFW_CONTEXT_ROBUSTNESS` specifies the robustness strategy to be used by the
context. This can be one of `GLFW_NO_RESET_NOTIFICATION` or
2013-04-10 19:07:07 -04:00
`GLFW_LOSE_CONTEXT_ON_RESET`, or `GLFW_NO_ROBUSTNESS` to not request
a robustness strategy.
2014-09-18 09:03:29 -04:00
`GLFW_CONTEXT_RELEASE_BEHAVIOR` specifies the release behavior to be
used by the context. Possible values are one of `GLFW_ANY_RELEASE_BEHAVIOR`,
`GLFW_RELEASE_BEHAVIOR_FLUSH` or `GLFW_RELEASE_BEHAVIOR_NONE`. If the
behavior is `GLFW_ANY_RELEASE_BEHAVIOR`, the default behavior of the context
creation API will be used. If the behavior is `GLFW_RELEASE_BEHAVIOR_FLUSH`,
the pipeline will be flushed whenever the context is released from being the
current one. If the behavior is `GLFW_RELEASE_BEHAVIOR_NONE`, the pipeline will
not be flushed on release.
2014-10-07 17:37:59 -04:00
@par
2014-09-18 09:03:29 -04:00
Context release behaviors are described in detail by the
[GL_KHR_context_flush_control](https://www.opengl.org/registry/specs/KHR/context_flush_control.txt)
extension.
`GLFW_CONTEXT_NO_ERROR` specifies whether errors should be generated by the
context. If enabled, situations that would have generated errors instead cause
undefined behavior.
@par
The no error mode for OpenGL and OpenGL ES is described in detail by the
[GL_KHR_no_error](https://www.opengl.org/registry/specs/KHR/no_error.txt)
extension.
2015-10-27 16:11:36 -04:00
@note This hint is experimental in its current state. There are currently
(October 2015) no corresponding WGL or GLX extensions. That makes this hint
a [hard constraint](@ref window_hints_hard) for those backends, as creation will
fail if unsupported context flags are requested. Once the extensions are
available, they will be required and creation of `GL_KHR_no_error` contexts may
fail on early drivers where this flag is supported without those extensions
being listed.
2013-04-10 19:07:07 -04:00
2014-09-18 09:03:29 -04:00
@subsubsection window_hints_values Supported and default values
Window hint | Default value | Supported values
------------------------------- | --------------------------- | ----------------
2015-08-23 13:30:04 -04:00
`GLFW_RESIZABLE` | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
`GLFW_VISIBLE` | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
`GLFW_DECORATED` | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
`GLFW_FOCUSED` | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
`GLFW_AUTO_ICONIFY` | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
`GLFW_FLOATING` | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
2014-09-18 09:03:29 -04:00
`GLFW_RED_BITS` | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_GREEN_BITS` | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_BLUE_BITS` | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_ALPHA_BITS` | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_DEPTH_BITS` | 24 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_STENCIL_BITS` | 8 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_ACCUM_RED_BITS` | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_ACCUM_GREEN_BITS` | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_ACCUM_BLUE_BITS` | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_ACCUM_ALPHA_BITS` | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_AUX_BUFFERS` | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_SAMPLES` | 0 | 0 to `INT_MAX` or `GLFW_DONT_CARE`
`GLFW_REFRESH_RATE` | `GLFW_DONT_CARE` | 0 to `INT_MAX` or `GLFW_DONT_CARE`
2015-08-23 13:30:04 -04:00
`GLFW_STEREO` | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
`GLFW_SRGB_CAPABLE` | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
`GLFW_DOUBLEBUFFER` | `GLFW_TRUE` | `GLFW_TRUE` or `GLFW_FALSE`
2014-09-18 09:03:29 -04:00
`GLFW_CLIENT_API` | `GLFW_OPENGL_API` | `GLFW_OPENGL_API` or `GLFW_OPENGL_ES_API`
`GLFW_CONTEXT_VERSION_MAJOR` | 1 | Any valid major version number of the chosen client API
`GLFW_CONTEXT_VERSION_MINOR` | 0 | Any valid minor version number of the chosen client API
`GLFW_CONTEXT_ROBUSTNESS` | `GLFW_NO_ROBUSTNESS` | `GLFW_NO_ROBUSTNESS`, `GLFW_NO_RESET_NOTIFICATION` or `GLFW_LOSE_CONTEXT_ON_RESET`
`GLFW_CONTEXT_RELEASE_BEHAVIOR` | `GLFW_ANY_RELEASE_BEHAVIOR` | `GLFW_ANY_RELEASE_BEHAVIOR`, `GLFW_RELEASE_BEHAVIOR_FLUSH` or `GLFW_RELEASE_BEHAVIOR_NONE`
2015-08-23 13:30:04 -04:00
`GLFW_OPENGL_FORWARD_COMPAT` | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
`GLFW_OPENGL_DEBUG_CONTEXT` | `GLFW_FALSE` | `GLFW_TRUE` or `GLFW_FALSE`
2014-09-18 09:03:29 -04:00
`GLFW_OPENGL_PROFILE` | `GLFW_OPENGL_ANY_PROFILE` | `GLFW_OPENGL_ANY_PROFILE`, `GLFW_OPENGL_COMPAT_PROFILE` or `GLFW_OPENGL_CORE_PROFILE`
@section window_events Window event processing
2015-01-17 19:55:25 -05:00
See @ref events.
2014-09-18 09:03:29 -04:00
@section window_properties Window properties and events
@subsection window_userptr User pointer
Each window has a user pointer that can be set with @ref
glfwSetWindowUserPointer and fetched with @ref glfwGetWindowUserPointer. This
can be used for any purpose you need and will not be modified by GLFW throughout
the life-time of the window.
The initial value of the pointer is `NULL`.
2015-01-17 19:55:25 -05:00
@subsection window_close Window closing and close flag
2013-04-10 19:07:07 -04:00
When the user attempts to close the window, for example by clicking the close
2014-10-02 11:35:10 -04:00
widget or using a key chord like Alt+F4, the _close flag_ of the window is set.
2013-05-27 11:10:34 -04:00
The window is however not actually destroyed and, unless you watch for this
state change, nothing further happens.
The current state of the close flag is returned by @ref glfwWindowShouldClose
and can be set or cleared directly with @ref glfwSetWindowShouldClose. A common
pattern is to use the close flag as a main loop condition.
@code
while (!glfwWindowShouldClose(window))
{
render(window);
glfwSwapBuffers(window);
glfwPollEvents();
}
@endcode
2014-09-18 09:03:29 -04:00
If you wish to be notified when the user attempts to close a window, set a close
2014-10-02 11:35:10 -04:00
callback.
2013-05-27 11:10:34 -04:00
@code
glfwSetWindowCloseCallback(window, window_close_callback);
@endcode
2014-10-02 11:35:10 -04:00
The callback function is called directly _after_ the close flag has been set.
2014-09-18 09:03:29 -04:00
It can be used for example to filter close requests and clear the close flag
again unless certain conditions are met.
2013-05-27 11:10:34 -04:00
@code
void window_close_callback(GLFWwindow* window)
{
if (!time_to_close)
2015-08-23 13:30:04 -04:00
glfwSetWindowShouldClose(window, GLFW_FALSE);
2013-05-27 11:10:34 -04:00
}
@endcode
2015-01-17 19:55:25 -05:00
@subsection window_size Window size
2013-05-27 11:10:34 -04:00
The size of a window can be changed with @ref glfwSetWindowSize. For windowed
2014-10-07 17:37:59 -04:00
mode windows, this sets the size, in
[screen coordinates](@ref coordinate_systems) of the _client area_ or _content
area_ of the window. The window system may impose limits on window size.
2013-05-27 11:10:34 -04:00
@code
2014-10-02 11:35:10 -04:00
glfwSetWindowSize(window, 640, 480);
2013-05-27 11:10:34 -04:00
@endcode
2014-10-02 11:35:10 -04:00
For full screen windows, the specified size becomes the new resolution of the
window's *desired video mode*. The video mode most closely matching the new
desired video mode is set immediately. The window is resized to fit the
resolution of the set video mode.
2013-05-27 11:10:34 -04:00
If you wish to be notified when a window is resized, whether by the user or
2014-10-02 11:35:10 -04:00
the system, set a size callback.
2013-05-27 11:10:34 -04:00
@code
glfwSetWindowSizeCallback(window, window_size_callback);
@endcode
2014-10-07 17:37:59 -04:00
The callback function receives the new size, in screen coordinates, of the
client area of the window when it is resized.
2013-05-27 11:10:34 -04:00
@code
void window_size_callback(GLFWwindow* window, int width, int height)
{
}
@endcode
There is also @ref glfwGetWindowSize for directly retrieving the current size of
a window.
@code
int width, height;
glfwGetWindowSize(window, &width, &height);
2013-07-07 06:06:59 -04:00
@endcode
2014-04-23 07:30:11 -04:00
@note Do not pass the window size to `glViewport` or other pixel-based OpenGL
calls. The window size is in screen coordinates, not pixels. Use the
2014-09-18 09:03:29 -04:00
[framebuffer size](@ref window_fbsize), which is in pixels, for pixel-based
calls.
The above functions work with the size of the client area, but decorated windows
typically have title bars and window frames around this rectangle. You can
retrieve the extents of these with @ref glfwGetWindowFrameSize.
@code
int left, top, right, bottom;
glfwGetWindowFrameSize(window, &left, &top, &right, &bottom);
@endcode
The returned values are the distances, in screen coordinates, from the edges of
the client area to the corresponding edges of the full window. As they are
distances and not coordinates, they are always zero or positive.
2014-04-23 07:30:11 -04:00
2013-07-07 06:06:59 -04:00
2014-09-18 09:03:29 -04:00
@subsection window_fbsize Framebuffer size
2013-07-07 06:06:59 -04:00
While the size of a window is measured in screen coordinates, OpenGL works with
2014-10-07 17:37:59 -04:00
pixels. The size you pass into `glViewport`, for example, should be in pixels.
On some machines screen coordinates and pixels are the same, but on others they
will not be. There is a second set of functions to retrieve the size, in
pixels, of the framebuffer of a window.
2013-07-07 06:06:59 -04:00
If you wish to be notified when the framebuffer of a window is resized, whether
2014-10-02 11:35:10 -04:00
by the user or the system, set a size callback.
2013-07-07 06:06:59 -04:00
@code
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
@endcode
2014-09-18 09:03:29 -04:00
The callback function receives the new size of the framebuffer when it is
resized, which can for example be used to update the OpenGL viewport.
2013-07-07 06:06:59 -04:00
@code
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
@endcode
There is also @ref glfwGetFramebufferSize for directly retrieving the current
size of the framebuffer of a window.
@code
int width, height;
glfwGetFramebufferSize(window, &width, &height);
2013-05-27 11:10:34 -04:00
glViewport(0, 0, width, height);
@endcode
The size of a framebuffer may change independently of the size of a window, for
example if the window is dragged between a regular monitor and a high-DPI one.
2013-07-07 06:06:59 -04:00
2013-05-27 11:10:34 -04:00
@subsection window_sizelimits Window size limits
The minimum and maximum size of the client area of a windowed mode window can be
2015-10-19 10:01:42 -04:00
enforced with @ref glfwSetWindowSizeLimits. The user may resize the window to
any size and aspect ratio within the specified limits, unless the aspect ratio
is also set.
@code
glfwSetWindowSizeLimits(window, 200, 200, 400, 400);
@endcode
2015-10-19 10:01:42 -04:00
To specify only a minimum size or only a maximum one, set the other pair to
`GLFW_DONT_CARE`.
@code
2015-10-19 10:01:42 -04:00
glfwSetWindowSizeLimits(window, 640, 480, GLFW_DONT_CARE, GLFW_DONT_CARE);
@endcode
2015-10-19 10:01:42 -04:00
To disable size limits for a window, set them all to `GLFW_DONT_CARE`.
2015-10-19 10:01:42 -04:00
The aspect ratio of the client area of a windowed mode window can be enforced
with @ref glfwSetWindowAspectRatio. The user may resize the window freely
unless size limits are also set, but the size will be constrained to maintain
the aspect ratio.
@code
glfwSetWindowAspectRatio(window, 16, 9);
@endcode
2015-10-19 10:01:42 -04:00
The aspect ratio is specified as a numerator and denominator, corresponding to
the width and height, respectively. If you want a window to maintain its
current aspect ratio, simply use its current size as the ratio.
@code
2015-10-19 10:01:42 -04:00
int width, height;
glfwGetWindowSize(window, &width, &height);
glfwSetWindowAspectRatio(window, width, height);
@endcode
2015-10-19 10:01:42 -04:00
To disable the aspect ratio limit for a window, set both terms to
`GLFW_DONT_CARE`.
You can have both size limits and aspect ratio set for a window, but the results
are undefined if they conflict.
2015-01-17 19:55:25 -05:00
@subsection window_pos Window position
2013-05-27 11:10:34 -04:00
The position of a windowed-mode window can be changed with @ref
glfwSetWindowPos. This moves the window so that the upper-left corner of its
2014-10-07 17:37:59 -04:00
client area has the specified [screen coordinates](@ref coordinate_systems).
2015-01-05 10:46:04 -05:00
The window system may put limitations on window placement.
2013-05-27 11:10:34 -04:00
@code
glfwSetWindowPos(window, 100, 100);
@endcode
2014-09-18 09:03:29 -04:00
If you wish to be notified when a window is moved, whether by the user, system
2014-10-02 11:35:10 -04:00
or your own code, set a position callback.
2013-05-27 11:10:34 -04:00
@code
glfwSetWindowPosCallback(window, window_pos_callback);
@endcode
2014-09-18 09:03:29 -04:00
The callback function receives the new position of the upper-left corner of the
client area when the window is moved.
2013-05-27 11:10:34 -04:00
@code
2014-03-06 09:31:24 -05:00
void window_pos_callback(GLFWwindow* window, int xpos, int ypos)
2013-05-27 11:10:34 -04:00
{
}
@endcode
There is also @ref glfwGetWindowPos for directly retrieving the current position
of the client area of the window.
@code
int xpos, ypos;
glfwGetWindowPos(window, &xpos, &ypos);
@endcode
2015-01-17 19:55:25 -05:00
@subsection window_title Window title
2013-05-27 11:10:34 -04:00
All GLFW windows have a title, although undecorated or full screen windows may
2014-09-18 09:03:29 -04:00
not display it or only display it in a task bar or similar interface. You can
set a UTF-8 encoded window title with @ref glfwSetWindowTitle.
2013-05-27 11:10:34 -04:00
@code
glfwSetWindowTitle(window, "My Window");
@endcode
2014-09-18 09:03:29 -04:00
The specified string is copied before the function returns, so there is no need
to keep it around.
As long as your source file is encoded as UTF-8, you can use any Unicode
characters directly in the source.
@code
2015-10-17 21:26:27 -04:00
glfwSetWindowTitle(window, "星を追う子ども");
2014-09-18 09:03:29 -04:00
@endcode
2015-10-24 15:40:27 -04:00
If you are using C++11 or C11, you can use a UTF-8 string literal.
@code
glfwSetWindowTitle(window, u8"This is always a UTF-8 string");
@endcode
2014-09-18 09:03:29 -04:00
2015-01-17 19:55:25 -05:00
@subsection window_monitor Window monitor
2014-09-18 09:03:29 -04:00
Full screen windows are associated with a specific monitor. You can get the
handle for this monitor with @ref glfwGetWindowMonitor.
@code
GLFWmonitor* monitor = glfwGetWindowMonitor(window);
@endcode
This monitor handle is one of those returned by @ref glfwGetMonitors.
For windowed mode windows, this function returns `NULL`. This is the
recommended way to tell full screen windows from windowed mode windows.
2015-01-17 19:55:25 -05:00
@subsection window_iconify Window iconification
2014-09-18 09:03:29 -04:00
Windows can be iconified (i.e. minimized) with @ref glfwIconifyWindow.
@code
glfwIconifyWindow(window);
@endcode
When a full screen window is iconified, the original video mode of its monitor
is restored until the user or application restores the window.
Iconified windows can be restored with @ref glfwRestoreWindow.
@code
glfwRestoreWindow(window);
@endcode
When a full screen window is restored, the desired video mode is restored to its
monitor as well.
If you wish to be notified when a window is iconified or restored, whether by
2014-10-02 11:35:10 -04:00
the user, system or your own code, set a iconify callback.
2014-09-18 09:03:29 -04:00
@code
glfwSetWindowIconifyCallback(window, window_iconify_callback);
@endcode
The callback function receives changes in the iconification state of the window.
@code
void window_iconify_callback(GLFWwindow* window, int iconified)
{
if (iconified)
{
// The window was iconified
}
else
{
// The window was restored
}
}
@endcode
2015-01-05 10:46:04 -05:00
You can also get the current iconification state with @ref glfwGetWindowAttrib.
2014-09-18 09:03:29 -04:00
@code
int iconified = glfwGetWindowAttrib(window, GLFW_ICONIFIED);
@endcode
2015-01-17 19:55:25 -05:00
@subsection window_hide Window visibility
2014-09-18 09:03:29 -04:00
Windowed mode windows can be hidden with @ref glfwHideWindow.
@code
glfwHideWindow(window);
@endcode
This makes the window completely invisible to the user, including removing it
from the task bar, dock or window list. Full screen windows cannot be hidden
and calling @ref glfwHideWindow on a full screen window does nothing.
Hidden windows can be shown with @ref glfwShowWindow.
@code
glfwShowWindow(window);
@endcode
Windowed mode windows can be created initially hidden with the `GLFW_VISIBLE`
[window hint](@ref window_hints_wnd). Windows created hidden are completely
invisible to the user until shown. This can be useful if you need to set up
your window further before showing it, for example moving it to a specific
location.
2015-01-05 10:46:04 -05:00
You can also get the current visibility state with @ref glfwGetWindowAttrib.
2014-09-18 09:03:29 -04:00
@code
int visible = glfwGetWindowAttrib(window, GLFW_VISIBLE);
@endcode
2015-01-17 19:55:25 -05:00
@subsection window_focus Window input focus
2014-09-18 09:03:29 -04:00
2015-01-17 19:55:25 -05:00
If you wish to be notified when a window gains or loses input focus, whether by
2014-10-02 11:35:10 -04:00
the user, system or your own code, set a focus callback.
2014-09-18 09:03:29 -04:00
@code
glfwSetWindowFocusCallback(window, window_focus_callback);
@endcode
2015-01-17 19:55:25 -05:00
The callback function receives changes in the input focus state of the window.
2014-09-18 09:03:29 -04:00
@code
void window_focus_callback(GLFWwindow* window, int focused)
{
if (focused)
{
2015-01-17 19:55:25 -05:00
// The window gained input focus
2014-09-18 09:03:29 -04:00
}
else
{
2015-01-17 19:55:25 -05:00
// The window lost input focus
2014-09-18 09:03:29 -04:00
}
}
@endcode
2015-01-17 19:55:25 -05:00
You can also get the current input focus state with @ref glfwGetWindowAttrib.
2013-05-27 11:10:34 -04:00
@code
2014-09-18 09:03:29 -04:00
int focused = glfwGetWindowAttrib(window, GLFW_FOCUSED);
2013-05-27 11:10:34 -04:00
@endcode
2015-01-17 19:55:25 -05:00
@subsection window_refresh Window damage and refresh
2014-09-18 09:03:29 -04:00
If you wish to be notified when the contents of a window is damaged and needs
2014-10-02 11:35:10 -04:00
to be refreshed, set a window refresh callback.
2014-09-18 09:03:29 -04:00
@code
glfwSetWindowRefreshCallback(m_handle, window_refresh_callback);
@endcode
The callback function is called when the contents of the window needs to be
refreshed.
@code
void window_refresh_callback(GLFWwindow* window)
{
draw_editor_ui(window);
glfwSwapBuffers(window);
}
@endcode
@note On compositing window systems such as Aero, Compiz or Aqua, where the
2015-01-16 08:09:03 -05:00
window contents are saved off-screen, this callback might only be called when
the window or framebuffer is resized.
2014-09-18 09:03:29 -04:00
2015-01-17 19:55:25 -05:00
@subsection window_attribs Window attributes
2013-05-27 11:10:34 -04:00
Windows have a number of attributes that can be returned using @ref
glfwGetWindowAttrib. Some reflect state that may change during the lifetime of
the window, while others reflect the corresponding hints and are fixed at the
2014-09-18 09:03:29 -04:00
time of creation. Some are related to the actual window and others to its
context.
2013-05-27 11:10:34 -04:00
@code
if (glfwGetWindowAttrib(window, GLFW_FOCUSED))
{
// window has input focus
}
@endcode
2015-01-17 19:55:25 -05:00
@subsubsection window_attribs_wnd Window related attributes
2013-05-27 11:10:34 -04:00
2015-01-16 08:09:03 -05:00
`GLFW_FOCUSED` indicates whether the specified window has input focus. Initial
2015-01-17 19:55:25 -05:00
input focus is controlled by the [window hint](@ref window_hints_wnd) with the
same name.
2013-05-27 11:10:34 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_ICONIFIED` indicates whether the specified window is iconified, whether by
the user or with @ref glfwIconifyWindow.
2013-05-27 11:10:34 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_VISIBLE` indicates whether the specified window is visible. Window
visibility can be controlled with @ref glfwShowWindow and @ref glfwHideWindow
2015-01-16 08:09:03 -05:00
and initial visibility is controlled by the [window hint](@ref window_hints_wnd)
2014-09-18 09:03:29 -04:00
with the same name.
2013-05-27 11:10:34 -04:00
2014-10-02 11:35:10 -04:00
`GLFW_RESIZABLE` indicates whether the specified window is resizable _by the
2015-01-16 08:09:03 -05:00
user_. This is set on creation with the [window hint](@ref window_hints_wnd)
with the same name.
2013-05-27 11:10:34 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_DECORATED` indicates whether the specified window has decorations such as
2015-01-16 08:09:03 -05:00
a border, a close widget, etc. This is set on creation with the
[window hint](@ref window_hints_wnd) with the same name.
2013-05-27 11:10:34 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_FLOATING` indicates whether the specified window is floating, also called
topmost or always-on-top. This is controlled by the
2015-01-16 08:09:03 -05:00
[window hint](@ref window_hints_wnd) with the same name.
2014-05-23 08:01:02 -04:00
2013-05-27 11:10:34 -04:00
2015-01-17 19:55:25 -05:00
@subsubsection window_attribs_ctx Context related attributes
2013-05-27 11:10:34 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_CLIENT_API` indicates the client API provided by the window's context;
either `GLFW_OPENGL_API` or `GLFW_OPENGL_ES_API`.
2013-05-27 11:10:34 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_CONTEXT_VERSION_MAJOR`, `GLFW_CONTEXT_VERSION_MINOR` and
`GLFW_CONTEXT_REVISION` indicate the client API version of the window's context.
2013-05-27 11:10:34 -04:00
2015-08-23 13:30:04 -04:00
`GLFW_OPENGL_FORWARD_COMPAT` is `GLFW_TRUE` if the window's context is an OpenGL
forward-compatible one, or `GLFW_FALSE` otherwise.
2013-05-27 11:10:34 -04:00
2015-08-23 13:30:04 -04:00
`GLFW_OPENGL_DEBUG_CONTEXT` is `GLFW_TRUE` if the window's context is an OpenGL
debug context, or `GLFW_FALSE` otherwise.
2013-05-27 11:10:34 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_OPENGL_PROFILE` indicates the OpenGL profile used by the context. This is
`GLFW_OPENGL_CORE_PROFILE` or `GLFW_OPENGL_COMPAT_PROFILE` if the context uses
a known profile, or `GLFW_OPENGL_ANY_PROFILE` if the OpenGL profile is unknown
or the context is an OpenGL ES context. Note that the returned profile may not
match the profile bits of the context flags, as GLFW will try other means of
detecting the profile when no bits are set.
2013-05-27 11:10:34 -04:00
2014-09-18 09:03:29 -04:00
`GLFW_CONTEXT_ROBUSTNESS` indicates the robustness strategy used by the context.
This is `GLFW_LOSE_CONTEXT_ON_RESET` or `GLFW_NO_RESET_NOTIFICATION` if the
window's context supports robustness, or `GLFW_NO_ROBUSTNESS` otherwise.
2013-05-27 11:10:34 -04:00
@subsubsection window_attribs_fb Framebuffer related attributes
The attributes of the default framebuffer (i.e. the framebuffer attached to the
window) are not provided by this function but can be queried with both OpenGL
and OpenGL ES.
If you are using version 3.0 or later of OpenGL or OpenGL ES, the
`glGetFramebufferAttachmentParameteriv` function can be used to retrieve the
number of bits for the red, green, blue, alpha, depth and stencil buffer
channels. Otherwise, the `glGetIntegerv` function can be used.
The number of MSAA samples are always retrieved with `glGetIntegerv`. For
contexts supporting framebuffer objects, the number of samples of the currently
bound framebuffer is returned.
Attribute | glGetIntegerv | glGetFramebufferAttachmentParameteriv
------------ | ----------------- | -------------------------------------
Red bits | `GL_RED_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE`
Green bits | `GL_GREEN_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE`
Blue bits | `GL_BLUE_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE`
Alpha bits | `GL_ALPHA_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE`
Depth bits | `GL_DEPTH_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE`
Stencil bits | `GL_STENCIL_BITS` | `GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE`
MSAA samples | `GL_SAMPLES` | _Not provided by this function_
When calling `glGetFramebufferAttachmentParameteriv`, the red, green, blue and
alpha sizes can be queried from the `GL_BACK_LEFT`, while the depth and stencil
sizes can be queried from the `GL_DEPTH` and `GL_STENCIL` attachments,
respectively.
2015-01-17 19:55:25 -05:00
@section buffer_swap Buffer swapping
2013-05-27 11:10:34 -04:00
2014-04-24 13:21:10 -04:00
GLFW windows are by default double buffered. That means that you have two
2013-05-27 11:10:34 -04:00
rendering buffers; a front buffer and a back buffer. The front buffer is
the one being displayed and the back buffer the one you render to.
When the entire frame has been rendered, it is time to swap the back and the
front buffers in order to display what has been rendered and begin rendering
a new frame. This is done with @ref glfwSwapBuffers.
@code
glfwSwapBuffers(window);
@endcode
2013-04-10 19:07:07 -04:00
2013-05-27 11:10:34 -04:00
Sometimes it can be useful to select when the buffer swap will occur. With the
function @ref glfwSwapInterval it is possible to select the minimum number of
2014-09-18 09:03:29 -04:00
monitor refreshes the driver wait should from the time @ref glfwSwapBuffers was
called before swapping the buffers:
2013-04-10 19:07:07 -04:00
2013-05-27 11:10:34 -04:00
@code
glfwSwapInterval(1);
@endcode
2013-04-10 19:07:07 -04:00
2013-05-27 11:10:34 -04:00
If the interval is zero, the swap will take place immediately when @ref
glfwSwapBuffers is called without waiting for a refresh. Otherwise at least
interval retraces will pass between each buffer swap. Using a swap interval of
zero can be useful for benchmarking purposes, when it is not desirable to
measure the time it takes to wait for the vertical retrace. However, a swap
interval of one lets you avoid tearing.
2013-04-10 19:07:07 -04:00
2013-11-24 17:31:15 -05:00
Note that this may not work on all machines, as some drivers have
user-controlled settings that override any swap interval the application
requests.
2013-04-10 19:07:07 -04:00
*/