mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-08-23 04:20:40 +02:00
331 lines
35 KiB
HTML
331 lines
35 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||
|
<meta name="generator" content="Doxygen 1.8.3.1"/>
|
||
|
<title>GLFW: Window handling guide</title>
|
||
|
<link href="tabs.css" rel="stylesheet" type="text/css"/>
|
||
|
<script type="text/javascript" src="jquery.js"></script>
|
||
|
<script type="text/javascript" src="dynsections.js"></script>
|
||
|
<link href="search/search.css" rel="stylesheet" type="text/css"/>
|
||
|
<script type="text/javascript" src="search/search.js"></script>
|
||
|
<script type="text/javascript">
|
||
|
$(document).ready(function() { searchBox.OnSelectItem(0); });
|
||
|
</script>
|
||
|
<link href="doxygen.css" rel="stylesheet" type="text/css" />
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||
|
<div id="titlearea">
|
||
|
<table cellspacing="0" cellpadding="0">
|
||
|
<tbody>
|
||
|
<tr style="height: 56px;">
|
||
|
<td style="padding-left: 0.5em;">
|
||
|
<div id="projectname">GLFW
|
||
|
 <span id="projectnumber">3.0.2</span>
|
||
|
</div>
|
||
|
<div id="projectbrief">A multi-platform library for OpenGL, window and input</div>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
<!-- end header part -->
|
||
|
<!-- Generated by Doxygen 1.8.3.1 -->
|
||
|
<script type="text/javascript">
|
||
|
var searchBox = new SearchBox("searchBox", "search",false,'Search');
|
||
|
</script>
|
||
|
<div id="navrow1" class="tabs">
|
||
|
<ul class="tablist">
|
||
|
<li><a href="index.html"><span>Main Page</span></a></li>
|
||
|
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
|
||
|
<li><a href="modules.html"><span>Modules</span></a></li>
|
||
|
<li><a href="annotated.html"><span>Data Structures</span></a></li>
|
||
|
<li><a href="files.html"><span>Files</span></a></li>
|
||
|
<li>
|
||
|
<div id="MSearchBox" class="MSearchBoxInactive">
|
||
|
<span class="left">
|
||
|
<img id="MSearchSelect" src="search/mag_sel.png"
|
||
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
||
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
||
|
alt=""/>
|
||
|
<input type="text" id="MSearchField" value="Search" accesskey="S"
|
||
|
onfocus="searchBox.OnSearchFieldFocus(true)"
|
||
|
onblur="searchBox.OnSearchFieldFocus(false)"
|
||
|
onkeyup="searchBox.OnSearchFieldChange(event)"/>
|
||
|
</span><span class="right">
|
||
|
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
|
||
|
</span>
|
||
|
</div>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<!-- window showing the filter options -->
|
||
|
<div id="MSearchSelectWindow"
|
||
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
||
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
||
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
||
|
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Pages</a></div>
|
||
|
|
||
|
<!-- iframe showing the search results (closed by default) -->
|
||
|
<div id="MSearchResultsWindow">
|
||
|
<iframe src="javascript:void(0)" frameborder="0"
|
||
|
name="MSearchResults" id="MSearchResults">
|
||
|
</iframe>
|
||
|
</div>
|
||
|
|
||
|
</div><!-- top -->
|
||
|
<div class="header">
|
||
|
<div class="headertitle">
|
||
|
<div class="title">Window handling guide </div> </div>
|
||
|
</div><!--header-->
|
||
|
<div class="contents">
|
||
|
<div class="toc"><h3>Table of Contents</h3>
|
||
|
<ul><li class="level1"><a href="#window_object">Window handles</a></li>
|
||
|
<li class="level1"><a href="#window_creation">Window creation</a></li>
|
||
|
<li class="level1"><a href="#window_destruction">Window destruction</a></li>
|
||
|
<li class="level1"><a href="#window_hints">Window creation hints</a><ul><li class="level2"><a href="#window_hints_hard">Hard and soft constraints</a></li>
|
||
|
<li class="level2"><a href="#window_hints_wnd">Window related hints</a></li>
|
||
|
<li class="level2"><a href="#window_hints_fb">Framebuffer related hints</a></li>
|
||
|
<li class="level2"><a href="#window_hints_ctx">Context related hints</a></li>
|
||
|
<li class="level2"><a href="#window_hints_values">Supported and default values</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="level1"><a href="#window_close">Window close flag</a></li>
|
||
|
<li class="level1"><a href="#window_size">Window size</a></li>
|
||
|
<li class="level1"><a href="#window_fbsize">Window framebuffer size</a></li>
|
||
|
<li class="level1"><a href="#window_pos">Window position</a></li>
|
||
|
<li class="level1"><a href="#window_title">Window title</a></li>
|
||
|
<li class="level1"><a href="#window_attribs">Window attributes</a><ul><li class="level2"><a href="#window_attribs_window">Window attributes</a></li>
|
||
|
<li class="level2"><a href="#window_attribs_context">Context attributes</a></li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
<li class="level1"><a href="#window_swap">Swapping buffers</a></li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<div class="textblock"><p>The primary purpose of GLFW is to provide a simple interface to window management and OpenGL and OpenGL ES context creation. GLFW supports multiple windows, which can be either a normal desktop window or a full screen window.</p>
|
||
|
<h1><a class="anchor" id="window_object"></a>
|
||
|
Window handles</h1>
|
||
|
<p>The <a class="el" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a> object encapsulates both a window and a context. They are created with <a class="el" href="group__window.html#ga5c336fddf2cbb5b92f65f10fb6043344">glfwCreateWindow</a> and destroyed with <a class="el" href="group__window.html#gacdf43e51376051d2c091662e9fe3d7b2">glfwDestroyWindow</a> (or <a class="el" href="group__init.html#gaaae48c0a18607ea4a4ba951d939f0901">glfwTerminate</a>, if any remain). As the window and context are inseparably linked, the object pointer is used as both a context and window handle.</p>
|
||
|
<h1><a class="anchor" id="window_creation"></a>
|
||
|
Window creation</h1>
|
||
|
<p>The window and its context are created with <a class="el" href="group__window.html#ga5c336fddf2cbb5b92f65f10fb6043344">glfwCreateWindow</a>, which returns a handle to the created window object. For example, this creates a 640 by 480 windowed mode window:</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window = <a class="code" href="group__window.html#ga5c336fddf2cbb5b92f65f10fb6043344" title="Creates a window and its associated context.">glfwCreateWindow</a>(640, 480, <span class="stringliteral">"My Title"</span>, NULL, NULL);</div>
|
||
|
</div><!-- fragment --><p>If window creation fails, <code>NULL</code> will be returned, so you need to check whether it did.</p>
|
||
|
<p>This handle is then passed to all window related functions, and is provided to you along with input events, so you know which window received the input.</p>
|
||
|
<p>To create a full screen window, you need to specify which monitor the window should use. In most cases, the user's primary monitor is a good choice. For more information about monitors, see the <a class="el" href="monitor.html">Multi-monitor guide</a>.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window = <a class="code" href="group__window.html#ga5c336fddf2cbb5b92f65f10fb6043344" title="Creates a window and its associated context.">glfwCreateWindow</a>(640, 480, <span class="stringliteral">"My Title"</span>, <a class="code" href="group__monitor.html#ga721867d84c6d18d6790d64d2847ca0b1" title="Returns the primary monitor.">glfwGetPrimaryMonitor</a>(), NULL);</div>
|
||
|
</div><!-- fragment --><p>Full screen windows cover the entire display area of a monitor, have no border or decorations, and change the monitor's resolution to the one most closely matching the requested window size.</p>
|
||
|
<p>For more control over how the window and its context are created, see <a class="el" href="window.html#window_hints">Window creation hints</a> below.</p>
|
||
|
<h1><a class="anchor" id="window_destruction"></a>
|
||
|
Window destruction</h1>
|
||
|
<p>When you are done with the window, destroy it with the <a class="el" href="group__window.html#gacdf43e51376051d2c091662e9fe3d7b2">glfwDestroyWindow</a> function.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#gacdf43e51376051d2c091662e9fe3d7b2" title="Destroys the specified window and its context.">glfwDestroyWindow</a>(window);</div>
|
||
|
</div><!-- fragment --><p>Once this function is called, no more events will be delivered for that window and its handle becomes invalid.</p>
|
||
|
<h1><a class="anchor" id="window_hints"></a>
|
||
|
Window creation hints</h1>
|
||
|
<p>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 <a class="el" href="group__init.html#ga317aac130a235ab08c6db0834907d85e">glfwInit</a>, can be set individually with <a class="el" href="group__window.html#ga4fd9e504bb937e79588a0ffdca9f620b">glfwWindowHint</a> and reset all at once to their defaults with <a class="el" href="group__window.html#gaa77c4898dfb83344a6b4f76aa16b9a4a">glfwDefaultWindowHints</a>.</p>
|
||
|
<p>Note that hints need to be set <em>before</em> the creation of the window and context you wish to have the specified attributes.</p>
|
||
|
<h2><a class="anchor" id="window_hints_hard"></a>
|
||
|
Hard and soft constraints</h2>
|
||
|
<p>Some window hints are hard constraints. These must match the available capabilities <em>exactly</em> for window and context creation to succeed. Hints that are not hard constraints are matched as closely as possible, but the resulting window and context may differ from what these hints requested. To find out the actual attributes of the created window and context, use the <a class="el" href="group__window.html#gacccb29947ea4b16860ebef42c2cb9337">glfwGetWindowAttrib</a> function.</p>
|
||
|
<p>The following hints are hard constraints:</p>
|
||
|
<ul>
|
||
|
<li><code>GLFW_STEREO</code></li>
|
||
|
<li><code>GLFW_CLIENT_API</code></li>
|
||
|
</ul>
|
||
|
<p>The following additional hints are hard constraints if requesting an OpenGL context:</p>
|
||
|
<ul>
|
||
|
<li><code>GLFW_OPENGL_FORWARD_COMPAT</code></li>
|
||
|
<li><code>GLFW_OPENGL_PROFILE</code></li>
|
||
|
</ul>
|
||
|
<p>Hints that do not apply to a given type of window or context are ignored.</p>
|
||
|
<h2><a class="anchor" id="window_hints_wnd"></a>
|
||
|
Window related hints</h2>
|
||
|
<p>The <code>GLFW_RESIZABLE</code> hint specifies whether the window will be resizable <em>by the user</em>. The window will still be resizable using the <a class="el" href="group__window.html#ga371911f12c74c504dd8d47d832d095cb">glfwSetWindowSize</a> function. This hint is ignored for full screen windows.</p>
|
||
|
<p>The <code>GLFW_VISIBLE</code> hint specifies whether the window will be initially visible. This hint is ignored for full screen windows.</p>
|
||
|
<p>The <code>GLFW_DECORATED</code> hint specifies whether the window will have window decorations such as a border, a close widget, etc. This hint is ignored for full screen windows. Note that even though a window may lack a close widget, it is usually still possible for the user to generate close events.</p>
|
||
|
<h2><a class="anchor" id="window_hints_fb"></a>
|
||
|
Framebuffer related hints</h2>
|
||
|
<p>The <code>GLFW_RED_BITS</code>, <code>GLFW_GREEN_BITS</code>, <code>GLFW_BLUE_BITS</code>, <code>GLFW_ALPHA_BITS</code>, <code>GLFW_DEPTH_BITS</code> and <code>GLFW_STENCIL_BITS</code> hints specify the desired bit depths of the various components of the default framebuffer.</p>
|
||
|
<p>The <code>GLFW_ACCUM_RED_BITS</code>, <code>GLFW_ACCUM_GREEN_BITS</code>, <code>GLFW_ACCUM_BLUE_BITS</code> and <code>GLFW_ACCUM_ALPHA_BITS</code> hints specify the desired bit depths of the various components of the accumulation buffer.</p>
|
||
|
<p>The <code>GLFW_AUX_BUFFERS</code> hint specifies the desired number of auxiliary buffers.</p>
|
||
|
<p>The <code>GLFW_STEREO</code> hint specifies whether to use stereoscopic rendering.</p>
|
||
|
<p>The <code>GLFW_SAMPLES</code> hint specifies the desired number of samples to use for multisampling. Zero disables multisampling.</p>
|
||
|
<p>The <code>GLFW_SRGB_CAPABLE</code> hint specifies whether the framebuffer should be sRGB capable.</p>
|
||
|
<p>The <code>GLFW_REFRESH_RATE</code> hint specifies the desired refresh rate for full screen windows. If set to zero, the highest available refresh rate will be used. This hint is ignored for windowed mode windows.</p>
|
||
|
<h2><a class="anchor" id="window_hints_ctx"></a>
|
||
|
Context related hints</h2>
|
||
|
<p>The <code>GLFW_CLIENT_API</code> hint specifies which client API to create the context for. Possible values are <code>GLFW_OPENGL_API</code> and <code>GLFW_OPENGL_ES_API</code>.</p>
|
||
|
<p>The <code>GLFW_CONTEXT_VERSION_MAJOR</code> and <code>GLFW_CONTEXT_VERSION_MINOR</code> hints specify the client API version that the created context must be compatible with.</p>
|
||
|
<p>For OpenGL, these hints are <em>not</em> hard constraints, as they don't have to match exactly, but <a class="el" href="group__window.html#ga5c336fddf2cbb5b92f65f10fb6043344">glfwCreateWindow</a> will still fail if the resulting OpenGL version 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.</p>
|
||
|
<p>While there is no way to ask the driver for a context of the highest supported version, most drivers provide this when you ask GLFW for a version 1.0 context.</p>
|
||
|
<p>For OpenGL ES, these hints are hard constraints.</p>
|
||
|
<p>If an OpenGL context is requested, the <code>GLFW_OPENGL_FORWARD_COMPAT</code> hint 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 version is 3.0 or above. If another client API is requested, this hint is ignored.</p>
|
||
|
<p>If an OpenGL context is requested, the <code>GLFW_OPENGL_DEBUG_CONTEXT</code> hint specifies whether to create a debug OpenGL context, which may have additional error and performance issue reporting functionality. If another client API is requested, this hint is ignored.</p>
|
||
|
<p>If an OpenGL context is requested, the <code>GLFW_OPENGL_PROFILE</code> hint specifies which OpenGL profile to create the context for. Possible values are one of <code>GLFW_OPENGL_CORE_PROFILE</code> or <code>GLFW_OPENGL_COMPAT_PROFILE</code>, or <code>GLFW_OPENGL_ANY_PROFILE</code> to not request a specific profile. If requesting an OpenGL version below 3.2, <code>GLFW_OPENGL_ANY_PROFILE</code> must be used. If another client API is requested, this hint is ignored.</p>
|
||
|
<p>The <code>GLFW_CONTEXT_ROBUSTNESS</code> hint specifies the robustness strategy to be used by the context. This can be one of <code>GLFW_NO_RESET_NOTIFICATION</code> or <code>GLFW_LOSE_CONTEXT_ON_RESET</code>, or <code>GLFW_NO_ROBUSTNESS</code> to not request a robustness strategy.</p>
|
||
|
<h2><a class="anchor" id="window_hints_values"></a>
|
||
|
Supported and default values</h2>
|
||
|
<table class="doxtable">
|
||
|
<tr>
|
||
|
<th>Name </th><th>Default value </th><th>Supported values </th></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_RESIZABLE</code> </td><td><code>GL_TRUE</code> </td><td><code>GL_TRUE</code> or <code>GL_FALSE</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_VISIBLE</code> </td><td><code>GL_TRUE</code> </td><td><code>GL_TRUE</code> or <code>GL_FALSE</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_DECORATED</code> </td><td><code>GL_TRUE</code> </td><td><code>GL_TRUE</code> or <code>GL_FALSE</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_RED_BITS</code> </td><td>8 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_GREEN_BITS</code> </td><td>8 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_BLUE_BITS</code> </td><td>8 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_ALPHA_BITS</code> </td><td>8 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_DEPTH_BITS</code> </td><td>24 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_STENCIL_BITS</code> </td><td>8 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_ACCUM_RED_BITS</code> </td><td>0 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_ACCUM_GREEN_BITS</code> </td><td>0 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_ACCUM_BLUE_BITS</code> </td><td>0 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_ACCUM_ALPHA_BITS</code> </td><td>0 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_AUX_BUFFERS</code> </td><td>0 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_SAMPLES</code> </td><td>0 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_REFRESH_RATE</code> </td><td>0 </td><td>0 to <code>INT_MAX</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_STEREO</code> </td><td><code>GL_FALSE</code> </td><td><code>GL_TRUE</code> or <code>GL_FALSE</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_SRGB_CAPABLE</code> </td><td><code>GL_FALSE</code> </td><td><code>GL_TRUE</code> or <code>GL_FALSE</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_CLIENT_API</code> </td><td><code>GLFW_OPENGL_API</code> </td><td><code>GLFW_OPENGL_API</code> or <code>GLFW_OPENGL_ES_API</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_CONTEXT_VERSION_MAJOR</code> </td><td>1 </td><td>Any valid major version number of the chosen client API </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_CONTEXT_VERSION_MINOR</code> </td><td>0 </td><td>Any valid minor version number of the chosen client API </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_CONTEXT_ROBUSTNESS</code> </td><td><code>GLFW_NO_ROBUSTNESS</code> </td><td><code>GLFW_NO_ROBUSTNESS</code>, <code>GLFW_NO_RESET_NOTIFICATION</code> or <code>GLFW_LOSE_CONTEXT_ON_RESET</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_OPENGL_FORWARD_COMPAT</code> </td><td><code>GL_FALSE</code> </td><td><code>GL_TRUE</code> or <code>GL_FALSE</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_OPENGL_DEBUG_CONTEXT</code> </td><td><code>GL_FALSE</code> </td><td><code>GL_TRUE</code> or <code>GL_FALSE</code> </td></tr>
|
||
|
<tr>
|
||
|
<td><code>GLFW_OPENGL_PROFILE</code> </td><td><code>GLFW_OPENGL_ANY_PROFILE</code> </td><td><code>GLFW_OPENGL_ANY_PROFILE</code>, <code>GLFW_OPENGL_COMPAT_PROFILE</code> or <code>GLFW_OPENGL_CORE_PROFILE</code> </td></tr>
|
||
|
</table>
|
||
|
<h1><a class="anchor" id="window_close"></a>
|
||
|
Window close flag</h1>
|
||
|
<p>When the user attempts to close the window, for example by clicking the close widget or using a key chord like Alt+F4, the <em>close flag</em> of the window is set. The window is however not actually destroyed and, unless you watch for this state change, nothing further happens.</p>
|
||
|
<p>The current state of the close flag is returned by <a class="el" href="group__window.html#ga24e02fbfefbb81fc45320989f8140ab5">glfwWindowShouldClose</a> and can be set or cleared directly with <a class="el" href="group__window.html#ga49c449dde2a6f87d996f4daaa09d6708">glfwSetWindowShouldClose</a>. A common pattern is to use the close flag as a main loop condition.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordflow">while</span> (!<a class="code" href="group__window.html#ga24e02fbfefbb81fc45320989f8140ab5" title="Checks the close flag of the specified window.">glfwWindowShouldClose</a>(window))</div>
|
||
|
<div class="line">{</div>
|
||
|
<div class="line"> render(window);</div>
|
||
|
<div class="line"></div>
|
||
|
<div class="line"> <a class="code" href="group__context.html#ga15a5a1ee5b3c2ca6b15ca209a12efd14" title="Swaps the front and back buffers of the specified window.">glfwSwapBuffers</a>(window);</div>
|
||
|
<div class="line"> <a class="code" href="group__window.html#ga37bd57223967b4211d60ca1a0bf3c832" title="Processes all pending events.">glfwPollEvents</a>();</div>
|
||
|
<div class="line">}</div>
|
||
|
</div><!-- fragment --><p>If you wish to be notified when the user attempts to close a window, you can set the close callback with <a class="el" href="group__window.html#gaade9264e79fae52bdb78e2df11ee8d6a">glfwSetWindowCloseCallback</a>. This callback is called directly <em>after</em> the close flag has been set.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#gaade9264e79fae52bdb78e2df11ee8d6a" title="Sets the close callback for the specified window.">glfwSetWindowCloseCallback</a>(window, window_close_callback);</div>
|
||
|
</div><!-- fragment --><p>The callback function can be used for example to filter close requests and clear the close flag again unless certain conditions are met.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordtype">void</span> window_close_callback(<a class="code" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window)</div>
|
||
|
<div class="line">{</div>
|
||
|
<div class="line"> <span class="keywordflow">if</span> (!time_to_close)</div>
|
||
|
<div class="line"> <a class="code" href="group__window.html#ga49c449dde2a6f87d996f4daaa09d6708" title="Sets the close flag of the specified window.">glfwSetWindowShouldClose</a>(window, GL_FALSE);</div>
|
||
|
<div class="line">}</div>
|
||
|
</div><!-- fragment --><h1><a class="anchor" id="window_size"></a>
|
||
|
Window size</h1>
|
||
|
<p>The size of a window can be changed with <a class="el" href="group__window.html#ga371911f12c74c504dd8d47d832d095cb">glfwSetWindowSize</a>. For windowed mode windows, this resizes the specified window so that its <em>client area</em> has the specified size. Note that the window system may put limitations on size. For full screen windows, it selects and sets the video mode most closely matching the specified size.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordtype">void</span> <a class="code" href="group__window.html#ga371911f12c74c504dd8d47d832d095cb" title="Sets the size of the client area of the specified window.">glfwSetWindowSize</a>(window, 640, 480);</div>
|
||
|
</div><!-- fragment --><p>If you wish to be notified when a window is resized, whether by the user or the system, you can set the size callback with <a class="el" href="group__window.html#gaa40cd24840daa8c62f36cafc847c72b6">glfwSetWindowSizeCallback</a>.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#gaa40cd24840daa8c62f36cafc847c72b6" title="Sets the size callback for the specified window.">glfwSetWindowSizeCallback</a>(window, window_size_callback);</div>
|
||
|
</div><!-- fragment --><p>The callback function receives the new size of the client area of the window.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordtype">void</span> window_size_callback(<a class="code" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">int</span> width, <span class="keywordtype">int</span> height)</div>
|
||
|
<div class="line">{</div>
|
||
|
<div class="line">}</div>
|
||
|
</div><!-- fragment --><p>There is also <a class="el" href="group__window.html#gaeea7cbc03373a41fb51cfbf9f2a5d4c6">glfwGetWindowSize</a> for directly retrieving the current size of a window.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordtype">int</span> width, height;</div>
|
||
|
<div class="line"><a class="code" href="group__window.html#gaeea7cbc03373a41fb51cfbf9f2a5d4c6" title="Retrieves the size of the client area of the specified window.">glfwGetWindowSize</a>(window, &width, &height);</div>
|
||
|
</div><!-- fragment --><h1><a class="anchor" id="window_fbsize"></a>
|
||
|
Window framebuffer size</h1>
|
||
|
<p>While the size of a window is measured in screen coordinates, OpenGL works with pixels. The size you pass into <code>glViewport</code>, for example, should be in pixels and not screen coordinates. On some platforms screen coordinates and pixels are the same, but this is not the case on all platforms supported by GLFW. There is a second set of functions to retrieve the size in pixels of the framebuffer of a window.</p>
|
||
|
<p>If you wish to be notified when the framebuffer of a window is resized, whether by the user or the system, you can set the size callback with <a class="el" href="group__window.html#ga3203461a5303bf289f2e05f854b2f7cf">glfwSetFramebufferSizeCallback</a>.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#ga3203461a5303bf289f2e05f854b2f7cf" title="Sets the framebuffer resize callback for the specified window.">glfwSetFramebufferSizeCallback</a>(window, framebuffer_size_callback);</div>
|
||
|
</div><!-- fragment --><p>The callback function receives the new size of the client area of the window, which can for example be used to update the OpenGL viewport.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordtype">void</span> framebuffer_size_callback(<a class="code" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">int</span> width, <span class="keywordtype">int</span> height)</div>
|
||
|
<div class="line">{</div>
|
||
|
<div class="line"> glViewport(0, 0, width, height);</div>
|
||
|
<div class="line">}</div>
|
||
|
</div><!-- fragment --><p>There is also <a class="el" href="group__window.html#ga0e2637a4161afb283f5300c7f94785c9">glfwGetFramebufferSize</a> for directly retrieving the current size of the framebuffer of a window.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordtype">int</span> width, height;</div>
|
||
|
<div class="line"><a class="code" href="group__window.html#ga0e2637a4161afb283f5300c7f94785c9" title="Retrieves the size of the framebuffer of the specified window.">glfwGetFramebufferSize</a>(window, &width, &height);</div>
|
||
|
<div class="line">glViewport(0, 0, width, height);</div>
|
||
|
</div><!-- fragment --><p>Note that 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.</p>
|
||
|
<h1><a class="anchor" id="window_pos"></a>
|
||
|
Window position</h1>
|
||
|
<p>The position of a windowed-mode window can be changed with <a class="el" href="group__window.html#ga1abb6d690e8c88e0c8cd1751356dbca8">glfwSetWindowPos</a>. This moves the window so that the upper-left corner of its client area has the specified screen coordinates. Note that the window system may put limitations on placement.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#ga1abb6d690e8c88e0c8cd1751356dbca8" title="Sets the position of the client area of the specified window.">glfwSetWindowPos</a>(window, 100, 100);</div>
|
||
|
</div><!-- fragment --><p>If you wish to be notified when a window is moved, whether by the user or the system, you can set the position callback with <a class="el" href="group__window.html#ga2837d4d240659feb4268fcb6530a6ba1">glfwSetWindowPosCallback</a>.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#ga2837d4d240659feb4268fcb6530a6ba1" title="Sets the position callback for the specified window.">glfwSetWindowPosCallback</a>(window, window_pos_callback);</div>
|
||
|
</div><!-- fragment --><p>The callback function receives the new position of the upper-left corner of its client area.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordtype">void</span> window_size_callback(<a class="code" href="group__window.html#ga3c96d80d363e67d13a41b5d1821f3242">GLFWwindow</a>* window, <span class="keywordtype">int</span> xpos, <span class="keywordtype">int</span> ypos)</div>
|
||
|
<div class="line">{</div>
|
||
|
<div class="line">}</div>
|
||
|
</div><!-- fragment --><p>There is also <a class="el" href="group__window.html#ga73cb526c000876fd8ddf571570fdb634">glfwGetWindowPos</a> for directly retrieving the current position of the client area of the window.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordtype">int</span> xpos, ypos;</div>
|
||
|
<div class="line"><a class="code" href="group__window.html#ga73cb526c000876fd8ddf571570fdb634" title="Retrieves the position of the client area of the specified window.">glfwGetWindowPos</a>(window, &xpos, &ypos);</div>
|
||
|
</div><!-- fragment --><h1><a class="anchor" id="window_title"></a>
|
||
|
Window title</h1>
|
||
|
<p>All GLFW windows have a title, although undecorated or full screen windows may not display it or only display it in a task bar or similar interface. To change the title of a window, use <a class="el" href="group__window.html#ga5d877f09e968cef7a360b513306f17ff">glfwSetWindowTitle</a>.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#ga5d877f09e968cef7a360b513306f17ff" title="Sets the title of the specified window.">glfwSetWindowTitle</a>(window, <span class="stringliteral">"My Window"</span>);</div>
|
||
|
</div><!-- fragment --><p>The window title is a regular C string using the UTF-8 encoding. This means for example that, as long as your source file is encoded as UTF-8, you can use any Unicode characters.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__window.html#ga5d877f09e968cef7a360b513306f17ff" title="Sets the title of the specified window.">glfwSetWindowTitle</a>(window, <span class="stringliteral">"さよなら絶望先生"</span>);</div>
|
||
|
</div><!-- fragment --><h1><a class="anchor" id="window_attribs"></a>
|
||
|
Window attributes</h1>
|
||
|
<p>Windows have a number of attributes that can be returned using <a class="el" href="group__window.html#gacccb29947ea4b16860ebef42c2cb9337">glfwGetWindowAttrib</a>. Some reflect state that may change during the lifetime of the window, while others reflect the corresponding hints and are fixed at the time of creation.</p>
|
||
|
<div class="fragment"><div class="line"><span class="keywordflow">if</span> (<a class="code" href="group__window.html#gacccb29947ea4b16860ebef42c2cb9337" title="Returns an attribute of the specified window.">glfwGetWindowAttrib</a>(window, <a class="code" href="glfw3_8h.html#a54ddb14825a1541a56e22afb5f832a9e">GLFW_FOCUSED</a>))</div>
|
||
|
<div class="line">{</div>
|
||
|
<div class="line"> <span class="comment">// window has input focus</span></div>
|
||
|
<div class="line">}</div>
|
||
|
</div><!-- fragment --><h2><a class="anchor" id="window_attribs_window"></a>
|
||
|
Window attributes</h2>
|
||
|
<p>The <code>GLFW_FOCUSED</code> attribute indicates whether the specified window currently has input focus.</p>
|
||
|
<p>The <code>GLFW_ICONIFIED</code> attribute indicates whether the specified window is currently iconified, whether by the user or with <a class="el" href="group__window.html#ga1bb559c0ebaad63c5c05ad2a066779c4">glfwIconifyWindow</a>.</p>
|
||
|
<p>The <code>GLFW_VISIBLE</code> attribute indicates whether the specified window is currently visible. Window visibility can be controlled with <a class="el" href="group__window.html#ga61be47917b72536a148300f46494fc66">glfwShowWindow</a> and <a class="el" href="group__window.html#ga49401f82a1ba5f15db5590728314d47c">glfwHideWindow</a> and initial visibility is controlled by the <a class="el" href="window.html#window_hints">window hint</a> with the same name.</p>
|
||
|
<p>The <code>GLFW_RESIZABLE</code> attribute indicates whether the specified window is resizable <em>by the user</em>. This is controlled by the <a class="el" href="window.html#window_hints">window hint</a> with the same name.</p>
|
||
|
<p>The <code>GLFW_DECORATED</code> attribute indicates whether the specified window has decorations such as a border, a close widget, etc. This is controlled by the <a class="el" href="window.html#window_hints">window hint</a> with the same name.</p>
|
||
|
<h2><a class="anchor" id="window_attribs_context"></a>
|
||
|
Context attributes</h2>
|
||
|
<p>The <code>GLFW_CLIENT_API</code> attribute indicates the client API provided by the window's context; either <code>GLFW_OPENGL_API</code> or <code>GLFW_OPENGL_ES_API</code>.</p>
|
||
|
<p>The <code>GLFW_CONTEXT_VERSION_MAJOR</code>, <code>GLFW_CONTEXT_VERSION_MINOR</code> and <code>GLFW_CONTEXT_REVISION</code> attributes indicate the client API version of the window's context.</p>
|
||
|
<p>The <code>GLFW_OPENGL_FORWARD_COMPAT</code> attribute is <code>GL_TRUE</code> if the window's context is an OpenGL forward-compatible one, or <code>GL_FALSE</code> otherwise.</p>
|
||
|
<p>The <code>GLFW_OPENGL_DEBUG_CONTEXT</code> attribute is <code>GL_TRUE</code> if the window's context is an OpenGL debug context, or <code>GL_FALSE</code> otherwise.</p>
|
||
|
<p>The <code>GLFW_OPENGL_PROFILE</code> attribute indicates the OpenGL profile used by the context. This is <code>GLFW_OPENGL_CORE_PROFILE</code> or <code>GLFW_OPENGL_COMPAT_PROFILE</code> if the context uses a known profile, or <code>GLFW_OPENGL_ANY_PROFILE</code> if the OpenGL profile is unknown or the context is for another client API.</p>
|
||
|
<p>The <code>GLFW_CONTEXT_ROBUSTNESS</code> attribute indicates the robustness strategy used by the context. This is <code>GLFW_LOSE_CONTEXT_ON_RESET</code> or <code>GLFW_NO_RESET_NOTIFICATION</code> if the window's context supports robustness, or <code>GLFW_NO_ROBUSTNESS</code> otherwise.</p>
|
||
|
<h1><a class="anchor" id="window_swap"></a>
|
||
|
Swapping buffers</h1>
|
||
|
<p>GLFW windows are always double buffered. That means that you have two 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.</p>
|
||
|
<p>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 <a class="el" href="group__context.html#ga15a5a1ee5b3c2ca6b15ca209a12efd14">glfwSwapBuffers</a>.</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__context.html#ga15a5a1ee5b3c2ca6b15ca209a12efd14" title="Swaps the front and back buffers of the specified window.">glfwSwapBuffers</a>(window);</div>
|
||
|
</div><!-- fragment --><p>Sometimes it can be useful to select when the buffer swap will occur. With the function <a class="el" href="group__context.html#ga6d4e0cdf151b5e579bd67f13202994ed">glfwSwapInterval</a> it is possible to select the minimum number of monitor refreshes the driver should wait before swapping the buffers:</p>
|
||
|
<div class="fragment"><div class="line"><a class="code" href="group__context.html#ga6d4e0cdf151b5e579bd67f13202994ed" title="Sets the swap interval for the current context.">glfwSwapInterval</a>(1);</div>
|
||
|
</div><!-- fragment --><p>If the interval is zero, the swap will take place immediately when <a class="el" href="group__context.html#ga15a5a1ee5b3c2ca6b15ca209a12efd14">glfwSwapBuffers</a> 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.</p>
|
||
|
<p>Note that not all OpenGL implementations properly implement this function, in which case <a class="el" href="group__context.html#ga6d4e0cdf151b5e579bd67f13202994ed">glfwSwapInterval</a> will have no effect. Some drivers also have user settings that override requests by GLFW. </p>
|
||
|
</div></div><!-- contents -->
|
||
|
<!-- start footer part -->
|
||
|
<hr class="footer"/><address class="footer"><small>
|
||
|
Generated on Sun Aug 25 2013 21:45:13 for GLFW by  <a href="http://www.doxygen.org/index.html">
|
||
|
<img class="footer" src="doxygen.png" alt="doxygen"/>
|
||
|
</a> 1.8.3.1
|
||
|
</small></address>
|
||
|
</body>
|
||
|
</html>
|