Add language tags for C code sections

This commit is contained in:
Camilla Löwy 2024-02-13 20:16:04 +01:00
parent d93868bcf3
commit fb10e95f78
9 changed files with 224 additions and 224 deletions

View File

@ -21,7 +21,7 @@ the documentation for your development environment.
You should include the GLFW header in the source files where you use OpenGL or
GLFW.
@code
@code{.c}
#include <GLFW/glfw3.h>
@endcode
@ -50,7 +50,7 @@ ES header or extension loader header included before it and will then disable
the inclusion of the default OpenGL header. Most extension loaders also define
macros that disable similar headers below it.
@code
@code{.c}
#include <glad/gl.h>
#include <GLFW/glfw3.h>
@endcode
@ -61,7 +61,7 @@ macro. If yours doesn't or you don't know which one your users will pick, the
including the OpenGL header. This will also allow you to include the two
headers in any order.
@code
@code{.c}
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <glad/gl.h>

View File

@ -47,7 +47,7 @@ When creating a window and its OpenGL or OpenGL ES context with @ref
glfwCreateWindow, you can specify another window whose context the new one
should share its objects (textures, vertex and element buffers, etc.) with.
@code
@code{.c}
GLFWwindow* second_window = glfwCreateWindow(640, 480, "Second Window", NULL, first_window);
@endcode
@ -70,7 +70,7 @@ GLFW doesn't support creating contexts without an associated window. However,
contexts with hidden windows can be created with the
[GLFW_VISIBLE](@ref GLFW_VISIBLE_hint) window hint.
@code
@code{.c}
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
GLFWwindow* offscreen_context = glfwCreateWindow(640, 480, "", NULL, NULL);
@ -105,13 +105,13 @@ thread before making it current on the new one.
The context of a window is made current with @ref glfwMakeContextCurrent.
@code
@code{.c}
glfwMakeContextCurrent(window);
@endcode
The window of the current context is returned by @ref glfwGetCurrentContext.
@code
@code{.c}
GLFWwindow* window = glfwGetCurrentContext();
@endcode
@ -185,14 +185,14 @@ include the glad header file, which will replace the OpenGL header of your
development environment. By including the glad header before the GLFW header,
it suppresses the development environment's OpenGL or OpenGL ES header.
@code
@code{.c}
#include <glad/glad.h>
#include <GLFW/glfw3.h>
@endcode
Finally, you need to initialize glad once you have a suitable current context.
@code
@code{.c}
window = glfwCreateWindow(640, 480, "My Window", NULL, NULL);
if (!window)
{
@ -215,7 +215,7 @@ check the actual OpenGL or OpenGL ES version with
a specific version is supported by the current context with the
`GLAD_GL_VERSION_x_x` booleans.
@code
@code{.c}
if (GLAD_GL_VERSION_3_2)
{
// Call OpenGL 3.2+ specific code
@ -225,7 +225,7 @@ if (GLAD_GL_VERSION_3_2)
To check whether a specific extension is supported, use the `GLAD_GL_xxx`
booleans.
@code
@code{.c}
if (GLAD_GL_ARB_gl_spirv)
{
// Use GL_ARB_gl_spirv
@ -267,7 +267,7 @@ to function) and `PROC` (procedure) are added to the ends.
To include the extension header, define @ref GLFW_INCLUDE_GLEXT before including
the GLFW header.
@code
@code{.c}
#define GLFW_INCLUDE_GLEXT
#include <GLFW/glfw3.h>
@endcode
@ -280,7 +280,7 @@ drivers or a graphics card that lacks the necessary hardware features), so it
is necessary to check at run-time whether the context supports the extension.
This is done with @ref glfwExtensionSupported.
@code
@code{.c}
if (glfwExtensionSupported("GL_ARB_gl_spirv"))
{
// The extension is supported by the current context
@ -299,7 +299,7 @@ These functions often do not have entry points in the client API libraries of
your operating system, making it necessary to fetch them at run time. You can
retrieve pointers to these functions with @ref glfwGetProcAddress.
@code
@code{.c}
PFNGLSPECIALIZESHADERARBPROC pfnSpecializeShaderARB = glfwGetProcAddress("glSpecializeShaderARB");
@endcode
@ -310,7 +310,7 @@ use a different prefix, like above, or some other naming scheme.
Now that all the pieces have been introduced, here is what they might look like
when used together.
@code
@code{.c}
#define GLFW_INCLUDE_GLEXT
#include <GLFW/glfw3.h>

View File

@ -42,7 +42,7 @@ There are three functions for processing pending events. @ref glfwPollEvents,
processes only those events that have already been received and then returns
immediately.
@code
@code{.c}
glfwPollEvents();
@endcode
@ -51,7 +51,7 @@ This is the best choice when rendering continuously, like most games do.
If you only need to update the contents of the window when you receive new
input, @ref glfwWaitEvents is a better choice.
@code
@code{.c}
glfwWaitEvents();
@endcode
@ -62,7 +62,7 @@ useful for, for example, editing tools.
If you want to wait for events but have UI elements or other tasks that need
periodic updates, @ref glfwWaitEventsTimeout lets you specify a timeout.
@code
@code{.c}
glfwWaitEventsTimeout(0.7);
@endcode
@ -74,7 +74,7 @@ If the main thread is sleeping in @ref glfwWaitEvents, you can wake it from
another thread by posting an empty event to the event queue with @ref
glfwPostEmptyEvent.
@code
@code{.c}
glfwPostEmptyEvent();
@endcode
@ -108,14 +108,14 @@ same keyboard layout, input method or even operating system as you.
If you wish to be notified when a physical key is pressed or released or when it
repeats, set a key callback.
@code
@code{.c}
glfwSetKeyCallback(window, key_callback);
@endcode
The callback function receives the [keyboard key](@ref keys), platform-specific
scancode, key action and [modifier bits](@ref mods).
@code
@code{.c}
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_E && action == GLFW_PRESS)
@ -149,7 +149,7 @@ different scancodes depending on the platform but they are safe to save to disk.
You can query the scancode for any [key token](@ref keys) supported on the
current platform with @ref glfwGetKeyScancode.
@code
@code{.c}
const int scancode = glfwGetKeyScancode(GLFW_KEY_X);
set_key_mapping(scancode, swap_weapons);
@endcode
@ -157,7 +157,7 @@ set_key_mapping(scancode, swap_weapons);
The last reported state for every physical key with a [key token](@ref keys) is
also saved in per-window state arrays that can be polled with @ref glfwGetKey.
@code
@code{.c}
int state = glfwGetKey(window, GLFW_KEY_E);
if (state == GLFW_PRESS)
{
@ -177,7 +177,7 @@ If a pressed key is released again before you poll its state, you will have
missed the key press. The recommended solution for this is to use a
key callback, but there is also the `GLFW_STICKY_KEYS` input mode.
@code
@code{.c}
glfwSetInputMode(window, GLFW_STICKY_KEYS, GLFW_TRUE);
@endcode
@ -190,7 +190,7 @@ the state will reset to `GLFW_RELEASE`, otherwise it will remain `GLFW_PRESS`.
If you wish to know what the state of the Caps Lock and Num Lock keys was when
input events were generated, set the `GLFW_LOCK_KEY_MODS` input mode.
@code
@code{.c}
glfwSetInputMode(window, GLFW_LOCK_KEY_MODS, GLFW_TRUE);
@endcode
@ -217,7 +217,7 @@ you can treat the code point argument as native endian UTF-32.
If you wish to offer regular text input, set a character callback.
@code
@code{.c}
glfwSetCharCallback(window, character_callback);
@endcode
@ -225,7 +225,7 @@ The callback function receives Unicode code points for key events that would
have led to regular text input and generally behaves as a standard text field on
that platform.
@code
@code{.c}
void character_callback(GLFWwindow* window, unsigned int codepoint)
{
}
@ -237,7 +237,7 @@ void character_callback(GLFWwindow* window, unsigned int codepoint)
If you wish to refer to keys by name, you can query the keyboard layout
dependent name of printable keys with @ref glfwGetKeyName.
@code
@code{.c}
const char* key_name = glfwGetKeyName(GLFW_KEY_W, 0);
show_tutorial_hint("Press %s to move forward", key_name);
@endcode
@ -260,7 +260,7 @@ a custom image or a standard cursor shape from the system theme.
If you wish to be notified when the cursor moves over the window, set a cursor
position callback.
@code
@code{.c}
glfwSetCursorPosCallback(window, cursor_position_callback);
@endcode
@ -268,7 +268,7 @@ The callback functions receives the cursor position, measured in screen
coordinates but relative to the top-left corner of the window content area. On
platforms that provide it, the full sub-pixel cursor position is passed on.
@code
@code{.c}
static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos)
{
}
@ -277,7 +277,7 @@ static void cursor_position_callback(GLFWwindow* window, double xpos, double ypo
The cursor position is also saved per-window and can be polled with @ref
glfwGetCursorPos.
@code
@code{.c}
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);
@endcode
@ -295,7 +295,7 @@ If you wish to implement mouse motion based camera controls or other input
schemes that require unlimited mouse movement, set the cursor mode to
`GLFW_CURSOR_DISABLED`.
@code
@code{.c}
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
@endcode
@ -311,7 +311,7 @@ other features of GLFW. It is not supported and will not work as robustly as
If you only wish the cursor to become hidden when it is over a window but still
want it to behave normally, set the cursor mode to `GLFW_CURSOR_HIDDEN`.
@code
@code{.c}
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
@endcode
@ -320,7 +320,7 @@ This mode puts no limit on the motion of the cursor.
If you wish the cursor to be visible but confined to the content area of the
window, set the cursor mode to `GLFW_CURSOR_CAPTURED`.
@code
@code{.c}
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_CAPTURED);
@endcode
@ -330,7 +330,7 @@ leave unless the window loses focus.
To exit out of either of these special modes, restore the `GLFW_CURSOR_NORMAL`
cursor mode.
@code
@code{.c}
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
@endcode
@ -353,7 +353,7 @@ Call @ref glfwRawMouseMotionSupported to check if the current machine provides
raw motion and set the `GLFW_RAW_MOUSE_MOTION` input mode to enable it. It is
disabled by default.
@code
@code{.c}
if (glfwRawMouseMotionSupported())
glfwSetInputMode(window, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
@endcode
@ -376,7 +376,7 @@ A custom cursor is created with @ref glfwCreateCursor, which returns a handle to
the created cursor object. For example, this creates a 16x16 white square
cursor with the hot-spot in the upper-left corner:
@code
@code{.c}
unsigned char pixels[16 * 16 * 4];
memset(pixels, 0xff, sizeof(pixels));
@ -401,7 +401,7 @@ sequential rows, starting from the top-left corner.
A cursor with a [standard shape](@ref shapes) from the current system cursor
theme can be created with @ref glfwCreateStandardCursor.
@code
@code{.c}
GLFWcursor* url_cursor = glfwCreateStandardCursor(GLFW_POINTING_HAND_CURSOR);
@endcode
@ -416,7 +416,7 @@ A few of these shapes are not available everywhere. If a shape is unavailable,
When a cursor is no longer needed, destroy it with @ref glfwDestroyCursor.
@code
@code{.c}
glfwDestroyCursor(cursor);
@endcode
@ -429,7 +429,7 @@ mode. All remaining cursors are destroyed when @ref glfwTerminate is called.
A cursor can be set as current for a window with @ref glfwSetCursor.
@code
@code{.c}
glfwSetCursor(window, cursor);
@endcode
@ -441,7 +441,7 @@ A single cursor may be set for any number of windows.
To revert to the default cursor, set the cursor of that window to `NULL`.
@code
@code{.c}
glfwSetCursor(window, NULL);
@endcode
@ -454,13 +454,13 @@ default cursor. This does not affect the cursor mode.
If you wish to be notified when the cursor enters or leaves the content area of
a window, set a cursor enter/leave callback.
@code
@code{.c}
glfwSetCursorEnterCallback(window, cursor_enter_callback);
@endcode
The callback function receives the new classification of the cursor.
@code
@code{.c}
void cursor_enter_callback(GLFWwindow* window, int entered)
{
if (entered)
@ -477,7 +477,7 @@ void cursor_enter_callback(GLFWwindow* window, int entered)
You can query whether the cursor is currently inside the content area of the
window with the [GLFW_HOVERED](@ref GLFW_HOVERED_attrib) window attribute.
@code
@code{.c}
if (glfwGetWindowAttrib(window, GLFW_HOVERED))
{
highlight_interface();
@ -490,14 +490,14 @@ if (glfwGetWindowAttrib(window, GLFW_HOVERED))
If you wish to be notified when a mouse button is pressed or released, set
a mouse button callback.
@code
@code{.c}
glfwSetMouseButtonCallback(window, mouse_button_callback);
@endcode
The callback function receives the [mouse button](@ref buttons), button action
and [modifier bits](@ref mods).
@code
@code{.c}
void mouse_button_callback(GLFWwindow* window, int button, int action, int mods)
{
if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS)
@ -511,7 +511,7 @@ The last reported state for every [supported mouse button](@ref buttons) is also
saved in per-window state arrays that can be polled with @ref
glfwGetMouseButton.
@code
@code{.c}
int state = glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT);
if (state == GLFW_PRESS)
{
@ -531,7 +531,7 @@ missed the button press. The recommended solution for this is to use a
mouse button callback, but there is also the `GLFW_STICKY_MOUSE_BUTTONS`
input mode.
@code
@code{.c}
glfwSetInputMode(window, GLFW_STICKY_MOUSE_BUTTONS, GLFW_TRUE);
@endcode
@ -550,13 +550,13 @@ The `GLFW_MOUSE_BUTTON_LAST` constant holds the highest value of any
If you wish to be notified when the user scrolls, whether with a mouse wheel or
touchpad gesture, set a scroll callback.
@code
@code{.c}
glfwSetScrollCallback(window, scroll_callback);
@endcode
The callback function receives two-dimensional scroll offsets.
@code
@code{.c}
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset)
{
}
@ -573,7 +573,7 @@ referred to as joysticks. It supports up to sixteen joysticks, ranging from
`GLFW_JOYSTICK_LAST`. You can test whether a [joystick](@ref joysticks) is
present with @ref glfwJoystickPresent.
@code
@code{.c}
int present = glfwJoystickPresent(GLFW_JOYSTICK_1);
@endcode
@ -601,7 +601,7 @@ The positions of all axes of a joystick are returned by @ref
glfwGetJoystickAxes. See the reference documentation for the lifetime of the
returned array.
@code
@code{.c}
int count;
const float* axes = glfwGetJoystickAxes(GLFW_JOYSTICK_5, &count);
@endcode
@ -615,7 +615,7 @@ The states of all buttons of a joystick are returned by @ref
glfwGetJoystickButtons. See the reference documentation for the lifetime of the
returned array.
@code
@code{.c}
int count;
const unsigned char* buttons = glfwGetJoystickButtons(GLFW_JOYSTICK_3, &count);
@endcode
@ -632,7 +632,7 @@ the reference documentation for @ref glfwGetJoystickButtons for details.
The states of all hats are returned by @ref glfwGetJoystickHats. See the
reference documentation for the lifetime of the returned array.
@code
@code{.c}
int count;
const unsigned char* hats = glfwGetJoystickHats(GLFW_JOYSTICK_7, &count);
@endcode
@ -655,7 +655,7 @@ The diagonal directions are bitwise combinations of the primary (up, right, down
and left) directions and you can test for these individually by ANDing it with
the corresponding direction.
@code
@code{.c}
if (hats[2] & GLFW_HAT_RIGHT)
{
// State of hat 2 could be right-up, right or right-down
@ -673,7 +673,7 @@ The human-readable, UTF-8 encoded name of a joystick is returned by @ref
glfwGetJoystickName. See the reference documentation for the lifetime of the
returned string.
@code
@code{.c}
const char* name = glfwGetJoystickName(GLFW_JOYSTICK_4);
@endcode
@ -698,14 +698,14 @@ The initial value of the pointer is `NULL`.
If you wish to be notified when a joystick is connected or disconnected, set
a joystick callback.
@code
@code{.c}
glfwSetJoystickCallback(joystick_callback);
@endcode
The callback function receives the ID of the joystick that has been connected
and disconnected and the event that occurred.
@code
@code{.c}
void joystick_callback(int jid, int event)
{
if (event == GLFW_CONNECTED)
@ -748,7 +748,7 @@ a joystick is connected or the mappings are updated.
You can check whether a joystick is both present and has a gamepad mapping with
@ref glfwJoystickIsGamepad.
@code
@code{.c}
if (glfwJoystickIsGamepad(GLFW_JOYSTICK_2))
{
// Use as gamepad
@ -762,13 +762,13 @@ You can query the human-readable name provided by the gamepad mapping with @ref
glfwGetGamepadName. This may or may not be the same as the
[joystick name](@ref joystick_name).
@code
@code{.c}
const char* name = glfwGetGamepadName(GLFW_JOYSTICK_7);
@endcode
To retrieve the gamepad state of a joystick, call @ref glfwGetGamepadState.
@code
@code{.c}
GLFWgamepadstate state;
if (glfwGetGamepadState(GLFW_JOYSTICK_3, &state))
@ -818,7 +818,7 @@ GLFW contains a copy of the mappings available in
time of release. Newer ones can be added at runtime with @ref
glfwUpdateGamepadMappings.
@code
@code{.c}
const char* mappings = load_file_contents("game/data/gamecontrollerdb.txt");
glfwUpdateGamepadMappings(mappings);
@ -898,7 +898,7 @@ and described above.
GLFW provides high-resolution time input, in seconds, with @ref glfwGetTime.
@code
@code{.c}
double seconds = glfwGetTime();
@endcode
@ -908,7 +908,7 @@ nanosecond resolution.
You can modify the base time with @ref glfwSetTime.
@code
@code{.c}
glfwSetTime(4.0);
@endcode
@ -918,7 +918,7 @@ from there.
You can also access the raw timer used to implement the functions above,
with @ref glfwGetTimerValue.
@code
@code{.c}
uint64_t value = glfwGetTimerValue();
@endcode
@ -926,7 +926,7 @@ This value is in 1&nbsp;/&nbsp;frequency seconds. The frequency of the raw
timer varies depending on the operating system and hardware. You can query the
frequency, in Hz, with @ref glfwGetTimerFrequency.
@code
@code{.c}
uint64_t frequency = glfwGetTimerFrequency();
@endcode
@ -937,7 +937,7 @@ If the system clipboard contains a UTF-8 encoded string or if it can be
converted to one, you can retrieve it with @ref glfwGetClipboardString. See the
reference documentation for the lifetime of the returned string.
@code
@code{.c}
const char* text = glfwGetClipboardString(NULL);
if (text)
{
@ -951,7 +951,7 @@ returned.
The contents of the system clipboard can be set to a UTF-8 encoded string with
@ref glfwSetClipboardString.
@code
@code{.c}
glfwSetClipboardString(NULL, "A string with words in it");
@endcode
@ -961,13 +961,13 @@ glfwSetClipboardString(NULL, "A string with words in it");
If you wish to receive the paths of files and/or directories dropped on
a window, set a file drop callback.
@code
@code{.c}
glfwSetDropCallback(window, drop_callback);
@endcode
The callback function receives an array of paths encoded as UTF-8.
@code
@code{.c}
void drop_callback(GLFWwindow* window, int count, const char** paths)
{
int i;

View File

@ -48,7 +48,7 @@ GLFW_NOT_INITIALIZED error.
The library is initialized with @ref glfwInit, which returns `GLFW_FALSE` if an
error occurred.
@code
@code{.c}
if (!glfwInit())
{
// Handle initialization failure
@ -76,7 +76,7 @@ hint.
Initialization hints are set before @ref glfwInit and affect how the library
behaves until termination. Hints are set with @ref glfwInitHint.
@code
@code{.c}
glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE);
@endcode
@ -176,7 +176,7 @@ default, this is set to @ref GLFW_ANY_PLATFORM, which will look for supported wi
systems in order of priority and select the first one it finds. It can also be set to any
specific platform to have GLFW only look for that one.
@code
@code{.c}
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_X11);
@endcode
@ -184,14 +184,14 @@ This mechanism also provides the Null platform, which is always supported but ne
explicitly requested. This platform is effectively a stub, emulating a window system on
a single 1080p monitor, but will not interact with any actual window system.
@code
@code{.c}
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_NULL);
@endcode
You can test whether a library binary was compiled with support for a specific platform
with @ref glfwPlatformSupported.
@code
@code{.c}
if (glfwPlatformSupported(GLFW_PLATFORM_WAYLAND))
glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);
@endcode
@ -199,7 +199,7 @@ if (glfwPlatformSupported(GLFW_PLATFORM_WAYLAND))
Once GLFW has been initialized, you can query which platform was selected with @ref
glfwGetPlatform.
@code
@code{.c}
int platform = glfwGetPlatform();
@endcode
@ -213,7 +213,7 @@ selected platform.
The heap memory allocator can be customized before initialization with @ref
glfwInitAllocator.
@code
@code{.c}
GLFWallocator allocator;
allocator.allocate = my_malloc;
allocator.reallocate = my_realloc;
@ -235,7 +235,7 @@ The allocation function must have a signature matching @ref GLFWallocatefun. It
the desired size, in bytes, and the user pointer passed to @ref glfwInitAllocator and
returns the address to the allocated memory block.
@code
@code{.c}
void* my_malloc(size_t size, void* user)
{
...
@ -250,7 +250,7 @@ It receives the memory block to be reallocated, the new desired size, in bytes,
pointer passed to @ref glfwInitAllocator and returns the address to the resized memory
block.
@code
@code{.c}
void* my_realloc(void* block, size_t size, void* user)
{
...
@ -264,7 +264,7 @@ The deallocation function must have a function signature matching @ref GLFWdeall
It receives the memory block to be deallocated and the user pointer passed to @ref
glfwInitAllocator.
@code
@code{.c}
void my_free(void* block, void* user)
{
...
@ -280,7 +280,7 @@ for a deallocation function. If the active one does not meet all of these, GLFW
Before your application exits, you should terminate the GLFW library if it has
been initialized. This is done with @ref glfwTerminate.
@code
@code{.c}
glfwTerminate();
@endcode
@ -305,7 +305,7 @@ values.
The last [error code](@ref errors) for the calling thread can be queried at any
time with @ref glfwGetError.
@code
@code{.c}
int code = glfwGetError(NULL);
if (code != GLFW_NO_ERROR)
@ -324,7 +324,7 @@ can retrieve a UTF-8 encoded human-readable description along with the error
code. If no error has occurred since the last call, the description is set to
`NULL`.
@code
@code{.c}
const char* description;
int code = glfwGetError(&description);
@ -338,14 +338,14 @@ This means you must make a copy of it if you want to keep it.
You can also set an error callback, which will be called each time an error
occurs. It is set with @ref glfwSetErrorCallback.
@code
@code{.c}
glfwSetErrorCallback(error_callback);
@endcode
The error callback receives the same error code and human-readable description
returned by @ref glfwGetError.
@code
@code{.c}
void error_callback(int code, const char* description)
{
display_error_message(code, description);
@ -572,7 +572,7 @@ this to verify that the library binary is compatible with your application.
The compile-time version of GLFW is provided by the GLFW header with the
`GLFW_VERSION_MAJOR`, `GLFW_VERSION_MINOR` and `GLFW_VERSION_REVISION` macros.
@code
@code{.c}
printf("Compiled against GLFW %i.%i.%i\n",
GLFW_VERSION_MAJOR,
GLFW_VERSION_MINOR,
@ -585,7 +585,7 @@ printf("Compiled against GLFW %i.%i.%i\n",
The run-time version can be retrieved with @ref glfwGetVersion, a function that
may be called regardless of whether GLFW is initialized.
@code
@code{.c}
int major, minor, revision;
glfwGetVersion(&major, &minor, &revision);
@ -624,14 +624,14 @@ The format of the string is as follows:
For example, compiling GLFW 3.4 with MinGW as a DLL for Windows, may result in a version string
like this:
@code
@code{.c}
3.4.0 Win32 WGL Null EGL OSMesa MinGW DLL
@endcode
Compiling GLFW as a static library for Linux, with both Wayland and X11 enabled, may
result in a version string like this:
@code
@code{.c}
3.4.0 Wayland X11 GLX Null EGL OSMesa monotonic
@endcode

View File

@ -42,14 +42,14 @@ The primary monitor is returned by @ref glfwGetPrimaryMonitor. It is the user's
preferred monitor and is usually the one with global UI elements like task bar
or menu bar.
@code
@code{.c}
GLFWmonitor* primary = glfwGetPrimaryMonitor();
@endcode
You can retrieve all currently connected monitors with @ref glfwGetMonitors.
See the reference documentation for the lifetime of the returned array.
@code
@code{.c}
int count;
GLFWmonitor** monitors = glfwGetMonitors(&count);
@endcode
@ -64,14 +64,14 @@ disconnected.
If you wish to be notified when a monitor is connected or disconnected, set
a monitor callback.
@code
@code{.c}
glfwSetMonitorCallback(monitor_callback);
@endcode
The callback function receives the handle for the monitor that has been
connected or disconnected and the event that occurred.
@code
@code{.c}
void monitor_callback(GLFWmonitor* monitor, int event)
{
if (event == GLFW_CONNECTED)
@ -109,7 +109,7 @@ Video modes are represented as @ref GLFWvidmode structures. You can get an
array of the video modes supported by a monitor with @ref glfwGetVideoModes.
See the reference documentation for the lifetime of the returned array.
@code
@code{.c}
int count;
GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
@endcode
@ -117,7 +117,7 @@ GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
To get the current video mode of a monitor call @ref glfwGetVideoMode. See the
reference documentation for the lifetime of the returned pointer.
@code
@code{.c}
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
@endcode
@ -132,7 +132,7 @@ retrieved with @ref glfwGetMonitorPhysicalSize. This has no relation to its
current _resolution_, i.e. the width and height of its current
[video mode](@ref monitor_modes).
@code
@code{.c}
int width_mm, height_mm;
glfwGetMonitorPhysicalSize(monitor, &width_mm, &height_mm);
@endcode
@ -147,7 +147,7 @@ useful. Instead, use the [monitor content scale](@ref monitor_scale) and
The content scale for a monitor can be retrieved with @ref
glfwGetMonitorContentScale.
@code
@code{.c}
float xscale, yscale;
glfwGetMonitorContentScale(monitor, &xscale, &yscale);
@endcode
@ -170,7 +170,7 @@ The position of the monitor on the virtual desktop, in
[screen coordinates](@ref coordinate_systems), can be retrieved with @ref
glfwGetMonitorPos.
@code
@code{.c}
int xpos, ypos;
glfwGetMonitorPos(monitor, &xpos, &ypos);
@endcode
@ -182,7 +182,7 @@ The area of a monitor not occupied by global task bars or menu bars is the work
area. This is specified in [screen coordinates](@ref coordinate_systems) and
can be retrieved with @ref glfwGetMonitorWorkarea.
@code
@code{.c}
int xpos, ypos, width, height;
glfwGetMonitorWorkarea(monitor, &xpos, &ypos, &width, &height);
@endcode
@ -194,7 +194,7 @@ The human-readable, UTF-8 encoded name of a monitor is returned by @ref
glfwGetMonitorName. See the reference documentation for the lifetime of the
returned string.
@code
@code{.c}
const char* name = glfwGetMonitorName(monitor);
@endcode
@ -219,7 +219,7 @@ The initial value of the pointer is `NULL`.
The gamma ramp of a monitor can be set with @ref glfwSetGammaRamp, which accepts
a monitor handle and a pointer to a @ref GLFWgammaramp structure.
@code
@code{.c}
GLFWgammaramp ramp;
unsigned short red[256], green[256], blue[256];
@ -245,7 +245,7 @@ ramp for that monitor.
The current gamma ramp for a monitor is returned by @ref glfwGetGammaRamp. See
the reference documentation for the lifetime of the returned structure.
@code
@code{.c}
const GLFWgammaramp* ramp = glfwGetGammaRamp(monitor);
@endcode
@ -253,7 +253,7 @@ If you wish to set a regular gamma ramp, you can have GLFW calculate it for you
from the desired exponent with @ref glfwSetGamma, which in turn calls @ref
glfwSetGammaRamp with the resulting ramp.
@code
@code{.c}
glfwSetGamma(monitor, 1.0);
@endcode

View File

@ -22,12 +22,12 @@ Unix-like systems, where it uses the
[soname](https://en.wikipedia.org/wiki/soname) `libglfw.so.3`.
@par Old syntax
@code
@code{.c}
#include <GL/glfw.h>
@endcode
@par New syntax
@code
@code{.c}
#include <GLFW/glfw3.h>
@endcode
@ -95,12 +95,12 @@ the creation of DLLs and DLL link libraries, as there's no need to explicitly
disable `@n` entry point suffixes.
@par Old syntax
@code
@code{.c}
void GLFWCALL callback_function(...);
@endcode
@par New syntax
@code
@code{.c}
void callback_function(...);
@endcode
@ -114,12 +114,12 @@ a newly created window is returned by @ref glfwCreateWindow (formerly
[opaque](https://en.wikipedia.org/wiki/Opaque_data_type) type @ref GLFWwindow.
@par Old syntax
@code
@code{.c}
glfwSetWindowTitle("New Window Title");
@endcode
@par New syntax
@code
@code{.c}
glfwSetWindowTitle(window, "New Window Title");
@endcode
@ -134,12 +134,12 @@ GLFW 2 would have selected, but there are many other
[opaque](https://en.wikipedia.org/wiki/Opaque_data_type) type @ref GLFWmonitor.
@par Old basic full screen
@code
@code{.c}
glfwOpenWindow(640, 480, 8, 8, 8, 0, 24, 0, GLFW_FULLSCREEN);
@endcode
@par New basic full screen
@code
@code{.c}
window = glfwCreateWindow(640, 480, "My Window", glfwGetPrimaryMonitor(), NULL);
@endcode
@ -156,7 +156,7 @@ buffer swap, which acts on a single window, the event processing functions act
on all windows at once.
@par Old basic main loop
@code
@code{.c}
while (...)
{
// Process input
@ -166,7 +166,7 @@ while (...)
@endcode
@par New basic main loop
@code
@code{.c}
while (...)
{
// Process input
@ -198,13 +198,13 @@ glfwGetFramebufferSize function. A framebuffer size callback has also been
added, which can be set with @ref glfwSetFramebufferSizeCallback.
@par Old basic viewport setup
@code
@code{.c}
glfwGetWindowSize(&width, &height);
glViewport(0, 0, width, height);
@endcode
@par New basic viewport setup
@code
@code{.c}
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
@endcode
@ -227,7 +227,7 @@ You can query the close flag at any time with @ref glfwWindowShouldClose and set
it at any time with @ref glfwSetWindowShouldClose.
@par Old basic main loop
@code
@code{.c}
while (glfwGetWindowParam(GLFW_OPENED))
{
...
@ -235,7 +235,7 @@ while (glfwGetWindowParam(GLFW_OPENED))
@endcode
@par New basic main loop
@code
@code{.c}
while (!glfwWindowShouldClose(window))
{
...
@ -248,12 +248,12 @@ event processing completes. You may however not call @ref glfwDestroyWindow
from the close callback (or any other window related callback).
@par Old syntax
@code
@code{.c}
int GLFWCALL window_close_callback(void);
@endcode
@par New syntax
@code
@code{.c}
void window_close_callback(GLFWwindow* window);
@endcode
@ -289,12 +289,12 @@ produce characters with diacritical marks. Even the Swedish keyboard layout
requires this for uncommon cases like ü.
@par Old syntax
@code
@code{.c}
void GLFWCALL character_callback(int character, int action);
@endcode
@par New syntax
@code
@code{.c}
void character_callback(GLFWwindow* window, int character);
@endcode
@ -324,12 +324,12 @@ two-dimensional floating point scroll offsets. This allows you to receive
precise scroll data from for example modern touchpads.
@par Old syntax
@code
@code{.c}
void GLFWCALL mouse_wheel_callback(int position);
@endcode
@par New syntax
@code
@code{.c}
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
@endcode
@ -437,12 +437,12 @@ has been moved to GLFW 3, you can request that the GLFW header includes it by
defining @ref GLFW_INCLUDE_GLU before the inclusion of the GLFW header.
@par Old syntax
@code
@code{.c}
#include <GL/glfw.h>
@endcode
@par New syntax
@code
@code{.c}
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
@endcode

View File

@ -21,7 +21,7 @@ behave differently in GLFW 3.
In the source files of your application where you use GLFW, you need to include
its header file.
@code
@code{.c}
#include <GLFW/glfw3.h>
@endcode
@ -38,7 +38,7 @@ This example uses files generated by [glad](https://gen.glad.sh/). The GLFW
header can detect most such headers if they are included first and will then not
include the one from your development environment.
@code
@code{.c}
#include <glad/gl.h>
#include <GLFW/glfw3.h>
@endcode
@ -48,7 +48,7 @@ GLFW_INCLUDE_NONE before the GLFW header to explicitly disable inclusion of the
development environment header. This also allows the two headers to be included
in any order.
@code
@code{.c}
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <glad/gl.h>
@ -61,7 +61,7 @@ Before you can use most GLFW functions, the library must be initialized. On
successful initialization, `GLFW_TRUE` is returned. If an error occurred,
`GLFW_FALSE` is returned.
@code
@code{.c}
if (!glfwInit())
{
// Initialization failed
@ -73,7 +73,7 @@ Note that `GLFW_TRUE` and `GLFW_FALSE` are and will always be one and zero.
When you are done using GLFW, typically just before the application exits, you
need to terminate GLFW.
@code
@code{.c}
glfwTerminate();
@endcode
@ -92,7 +92,7 @@ In case a GLFW function fails, an error is reported to the GLFW error callback.
You can receive these reports with an error callback. This function must have
the signature below but may do anything permitted in other callbacks.
@code
@code{.c}
void error_callback(int error, const char* description)
{
fprintf(stderr, "Error: %s\n", description);
@ -104,7 +104,7 @@ the error callback is one of the few GLFW functions that may be called before
initialization, which lets you be notified of errors both during and after
initialization.
@code
@code{.c}
glfwSetErrorCallback(error_callback);
@endcode
@ -115,7 +115,7 @@ The window and its OpenGL context are created with a single call to @ref
glfwCreateWindow, which returns a handle to the created combined window and
context object
@code
@code{.c}
GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);
if (!window)
{
@ -138,7 +138,7 @@ You can select the OpenGL profile by setting the `GLFW_OPENGL_PROFILE` hint.
This program uses the core profile as that is the only profile macOS supports
for OpenGL 3.x and 4.x.
@code
@code{.c}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
@ -151,7 +151,7 @@ if (!window)
When a window and context is no longer needed, destroy it.
@code
@code{.c}
glfwDestroyWindow(window);
@endcode
@ -163,7 +163,7 @@ and its handle becomes invalid.
Before you can use the OpenGL API, you must have a current OpenGL context.
@code
@code{.c}
glfwMakeContextCurrent(window);
@endcode
@ -176,7 +176,7 @@ a current context to load from. This example uses
[glad](https://github.com/Dav1dde/glad), but the same rule applies to all such
libraries.
@code
@code{.c}
gladLoadGL(glfwGetProcAddress);
@endcode
@ -191,7 +191,7 @@ Note that __the window isn't actually closed__, so you are expected to monitor
this flag and either destroy the window or give some kind of feedback to the
user.
@code
@code{.c}
while (!glfwWindowShouldClose(window))
{
// Keep running
@ -213,7 +213,7 @@ Each window has a large number of callbacks that can be set to receive all the
various kinds of events. To receive key press and release events, create a key
callback function.
@code
@code{.c}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
@ -223,7 +223,7 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
The key callback, like other window related callbacks, are set per-window.
@code
@code{.c}
glfwSetKeyCallback(window, key_callback);
@endcode
@ -237,7 +237,7 @@ Once you have a current OpenGL context, you can use OpenGL normally. In this
tutorial, a multicolored rotating triangle will be rendered. The framebuffer
size needs to be retrieved for `glViewport`.
@code
@code{.c}
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
@ -265,7 +265,7 @@ returns the number of seconds since initialization. The time source used is the
most accurate on each platform and generally has micro- or nanosecond
resolution.
@code
@code{.c}
double time = glfwGetTime();
@endcode
@ -279,7 +279,7 @@ the one being displayed and the back buffer the one you render to.
When the entire frame has been rendered, the buffers need to be swapped with one
another, so the back buffer becomes the front buffer and vice versa.
@code
@code{.c}
glfwSwapBuffers(window);
@endcode
@ -296,7 +296,7 @@ For these reasons, applications will typically want to set the swap interval to
one. It can be set to higher values, but this is usually not recommended,
because of the input latency it leads to.
@code
@code{.c}
glfwSwapInterval(1);
@endcode
@ -315,7 +315,7 @@ There are two methods for processing pending events; polling and waiting. This
example will use event polling, which processes only those events that have
already been received and then returns immediately.
@code
@code{.c}
glfwPollEvents();
@endcode

View File

@ -45,7 +45,7 @@ you will need to direct GLFW to it. Pass your version of `vkGetInstanceProcAddr
glfwInitVulkanLoader before initializing GLFW and it will use that function for all Vulkan
entry point retrieval. This prevents GLFW from dynamically loading the Vulkan loader.
@code
@code{.c}
glfwInitVulkanLoader(vkGetInstanceProcAddr);
@endcode
@ -59,7 +59,7 @@ bundle according to the LunarG SDK documentation. This is explained in more det
To have GLFW include the Vulkan header, define @ref GLFW_INCLUDE_VULKAN before including
the GLFW header.
@code
@code{.c}
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
@endcode
@ -67,7 +67,7 @@ the GLFW header.
If you instead want to include the Vulkan header from a custom location or use
your own custom Vulkan header then do this before the GLFW header.
@code
@code{.c}
#include <path/to/vulkan.h>
#include <GLFW/glfw3.h>
@endcode
@ -94,7 +94,7 @@ If you are loading the Vulkan loader dynamically instead of linking directly
against it, you can check for the availability of a loader and ICD with @ref
glfwVulkanSupported.
@code
@code{.c}
if (glfwVulkanSupported())
{
// Vulkan is available, at least for compute
@ -114,7 +114,7 @@ To load any Vulkan core or extension function from the found loader, call @ref
glfwGetInstanceProcAddress. To load functions needed for instance creation,
pass `NULL` as the instance.
@code
@code{.c}
PFN_vkCreateInstance pfnCreateInstance = (PFN_vkCreateInstance)
glfwGetInstanceProcAddress(NULL, "vkCreateInstance");
@endcode
@ -122,7 +122,7 @@ PFN_vkCreateInstance pfnCreateInstance = (PFN_vkCreateInstance)
Once you have created an instance, you can load from it all other Vulkan core
functions and functions from any instance extensions you enabled.
@code
@code{.c}
PFN_vkCreateDevice pfnCreateDevice = (PFN_vkCreateDevice)
glfwGetInstanceProcAddress(instance, "vkCreateDevice");
@endcode
@ -137,7 +137,7 @@ Vulkan also provides `vkGetDeviceProcAddr` for loading device-specific versions
of Vulkan function. This function can be retrieved from an instance with @ref
glfwGetInstanceProcAddress.
@code
@code{.c}
PFN_vkGetDeviceProcAddr pfnGetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)
glfwGetInstanceProcAddress(instance, "vkGetDeviceProcAddr");
@endcode
@ -156,7 +156,7 @@ GLFW requires to create Vulkan surfaces.
To query the instance extensions required, call @ref
glfwGetRequiredInstanceExtensions.
@code
@code{.c}
uint32_t count;
const char** extensions = glfwGetRequiredInstanceExtensions(&count);
@endcode
@ -174,7 +174,7 @@ If successful the returned array will always include `VK_KHR_surface`, so if
you don't require any additional extensions you can pass this list directly to
the `VkInstanceCreateInfo` struct.
@code
@code{.c}
VkInstanceCreateInfo ici;
memset(&ici, 0, sizeof(ici));
@ -203,7 +203,7 @@ To check whether a specific queue family of a physical device supports image
presentation without first having to create a window and surface, call @ref
glfwGetPhysicalDevicePresentationSupport.
@code
@code{.c}
if (glfwGetPhysicalDevicePresentationSupport(instance, physical_device, queue_family_index))
{
// Queue family supports image presentation
@ -221,7 +221,7 @@ Unless you will be using OpenGL or OpenGL ES with the same window as Vulkan,
there is no need to create a context. You can disable context creation with the
[GLFW_CLIENT_API](@ref GLFW_CLIENT_API_hint) hint.
@code
@code{.c}
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(640, 480, "Window Title", NULL, NULL);
@endcode
@ -234,7 +234,7 @@ See @ref context_less for more information.
You can create a Vulkan surface (as defined by the `VK_KHR_surface` extension)
for a GLFW window with @ref glfwCreateWindowSurface.
@code
@code{.c}
VkSurfaceKHR surface;
VkResult err = glfwCreateWindowSurface(instance, window, NULL, &surface);
if (err)

View File

@ -32,7 +32,7 @@ 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:
@code
@code{.c}
GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);
@endcode
@ -50,7 +50,7 @@ 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 retrieving monitors, see @ref monitor_monitors.
@code
@code{.c}
GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", glfwGetPrimaryMonitor(), NULL);
@endcode
@ -101,7 +101,7 @@ 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, request the current video mode.
@code
@code{.c}
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
glfwWindowHint(GLFW_RED_BITS, mode->redBits);
@ -114,7 +114,7 @@ GLFWwindow* window = glfwCreateWindow(mode->width, mode->height, "My Title", mon
This also works for windowed mode windows that are made full screen.
@code
@code{.c}
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
@ -129,7 +129,7 @@ make windowed full screen, you need to have saved the desktop resolution before.
When a window is no longer needed, destroy it with @ref glfwDestroyWindow.
@code
@code{.c}
glfwDestroyWindow(window);
@endcode
@ -598,7 +598,7 @@ 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
@code{.c}
while (!glfwWindowShouldClose(window))
{
render(window);
@ -611,7 +611,7 @@ while (!glfwWindowShouldClose(window))
If you wish to be notified when the user attempts to close a window, set a close
callback.
@code
@code{.c}
glfwSetWindowCloseCallback(window, window_close_callback);
@endcode
@ -619,7 +619,7 @@ The callback function is called directly _after_ the close flag has been set.
It can be used for example to filter close requests and clear the close flag
again unless certain conditions are met.
@code
@code{.c}
void window_close_callback(GLFWwindow* window)
{
if (!time_to_close)
@ -635,7 +635,7 @@ mode windows, this sets the size, in
[screen coordinates](@ref coordinate_systems) of the _content area_ or _content
area_ of the window. The window system may impose limits on window size.
@code
@code{.c}
glfwSetWindowSize(window, 640, 480);
@endcode
@ -647,14 +647,14 @@ resolution of the set video mode.
If you wish to be notified when a window is resized, whether by the user, the
system or your own code, set a size callback.
@code
@code{.c}
glfwSetWindowSizeCallback(window, window_size_callback);
@endcode
The callback function receives the new size, in screen coordinates, of the
content area of the window when the window is resized.
@code
@code{.c}
void window_size_callback(GLFWwindow* window, int width, int height)
{
}
@ -663,7 +663,7 @@ void window_size_callback(GLFWwindow* window, int width, int height)
There is also @ref glfwGetWindowSize for directly retrieving the current size of
a window.
@code
@code{.c}
int width, height;
glfwGetWindowSize(window, &width, &height);
@endcode
@ -677,7 +677,7 @@ The above functions work with the size of the content 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
@code{.c}
int left, top, right, bottom;
glfwGetWindowFrameSize(window, &left, &top, &right, &bottom);
@endcode
@ -698,14 +698,14 @@ pixels, of the framebuffer of a window.
If you wish to be notified when the framebuffer of a window is resized, whether
by the user or the system, set a size callback.
@code
@code{.c}
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
@endcode
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.
@code
@code{.c}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
@ -715,7 +715,7 @@ void framebuffer_size_callback(GLFWwindow* window, int width, int height)
There is also @ref glfwGetFramebufferSize for directly retrieving the current
size of the framebuffer of a window.
@code
@code{.c}
int width, height;
glfwGetFramebufferSize(window, &width, &height);
glViewport(0, 0, width, height);
@ -730,7 +730,7 @@ example if the window is dragged between a regular monitor and a high-DPI one.
The content scale for a window can be retrieved with @ref
glfwGetWindowContentScale.
@code
@code{.c}
float xscale, yscale;
glfwGetWindowContentScale(window, &xscale, &yscale);
@endcode
@ -750,13 +750,13 @@ If you wish to be notified when the content scale of a window changes, whether
because of a system setting change or because it was moved to a monitor with
a different scale, set a content scale callback.
@code
@code{.c}
glfwSetWindowContentScaleCallback(window, window_content_scale_callback);
@endcode
The callback function receives the new content scale of the window.
@code
@code{.c}
void window_content_scale_callback(GLFWwindow* window, float xscale, float yscale)
{
set_interface_scale(xscale, yscale);
@ -777,14 +777,14 @@ be 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
@code{.c}
glfwSetWindowSizeLimits(window, 200, 200, 400, 400);
@endcode
To specify only a minimum size or only a maximum one, set the other pair to
`GLFW_DONT_CARE`.
@code
@code{.c}
glfwSetWindowSizeLimits(window, 640, 480, GLFW_DONT_CARE, GLFW_DONT_CARE);
@endcode
@ -795,7 +795,7 @@ 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
@code{.c}
glfwSetWindowAspectRatio(window, 16, 9);
@endcode
@ -803,7 +803,7 @@ 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, use its current size as the ratio.
@code
@code{.c}
int width, height;
glfwGetWindowSize(window, &width, &height);
glfwSetWindowAspectRatio(window, width, height);
@ -824,7 +824,7 @@ This is most often the right choice. If you need to create a window at
a specific position, you can set the desired position with the @ref
GLFW_POSITION_X and @ref GLFW_POSITION_Y window hints.
@code
@code{.c}
glfwWindowHint(GLFW_POSITION_X, 70);
glfwWindowHint(GLFW_POSITION_Y, 83);
@endcode
@ -836,21 +836,21 @@ glfwSetWindowPos. This moves the window so that the upper-left corner of its
content area has the specified [screen coordinates](@ref coordinate_systems).
The window system may put limitations on window placement.
@code
@code{.c}
glfwSetWindowPos(window, 100, 100);
@endcode
If you wish to be notified when a window is moved, whether by the user, the
system or your own code, set a position callback.
@code
@code{.c}
glfwSetWindowPosCallback(window, window_pos_callback);
@endcode
The callback function receives the new position, in screen coordinates, of the
upper-left corner of the content area when the window is moved.
@code
@code{.c}
void window_pos_callback(GLFWwindow* window, int xpos, int ypos)
{
}
@ -859,7 +859,7 @@ void window_pos_callback(GLFWwindow* window, int xpos, int ypos)
There is also @ref glfwGetWindowPos for directly retrieving the current position
of the content area of the window.
@code
@code{.c}
int xpos, ypos;
glfwGetWindowPos(window, &xpos, &ypos);
@endcode
@ -871,7 +871,7 @@ 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. You can
set a UTF-8 encoded window title with @ref glfwSetWindowTitle.
@code
@code{.c}
glfwSetWindowTitle(window, "My Window");
@endcode
@ -881,13 +881,13 @@ 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
@code{.c}
glfwSetWindowTitle(window, "ラストエグザイル");
@endcode
If you are using C++11 or C11, you can use a UTF-8 string literal.
@code
@code{.c}
glfwSetWindowTitle(window, u8"This is always a UTF-8 string");
@endcode
@ -897,7 +897,7 @@ glfwSetWindowTitle(window, u8"This is always a UTF-8 string");
Decorated windows have icons on some platforms. You can set this icon by
specifying a list of candidate images with @ref glfwSetWindowIcon.
@code
@code{.c}
GLFWimage images[2];
images[0] = load_icon("my_icon.png");
images[1] = load_icon("my_icon_small.png");
@ -911,7 +911,7 @@ sequential rows, starting from the top-left corner.
To revert to the default window icon, pass in an empty image array.
@code
@code{.c}
glfwSetWindowIcon(window, 0, NULL);
@endcode
@ -921,7 +921,7 @@ glfwSetWindowIcon(window, 0, NULL);
Full screen windows are associated with a specific monitor. You can get the
handle for this monitor with @ref glfwGetWindowMonitor.
@code
@code{.c}
GLFWmonitor* monitor = glfwGetWindowMonitor(window);
@endcode
@ -935,7 +935,7 @@ with @ref glfwSetWindowMonitor. When making a window full screen on the same or
on a different monitor, specify the desired monitor, resolution and refresh
rate. The position arguments are ignored.
@code
@code{.c}
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
@ -944,7 +944,7 @@ glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->ref
When making the window windowed, specify the desired position and size. The
refresh rate argument is ignored.
@code
@code{.c}
glfwSetWindowMonitor(window, NULL, xpos, ypos, width, height, 0);
@endcode
@ -958,7 +958,7 @@ before making it full screen and then pass them in as above.
Windows can be iconified (i.e. minimized) with @ref glfwIconifyWindow.
@code
@code{.c}
glfwIconifyWindow(window);
@endcode
@ -968,7 +968,7 @@ is restored until the user or application restores the window.
Iconified windows can be restored with @ref glfwRestoreWindow. This function
also restores windows from maximization.
@code
@code{.c}
glfwRestoreWindow(window);
@endcode
@ -978,13 +978,13 @@ monitor as well.
If you wish to be notified when a window is iconified or restored, whether by
the user, system or your own code, set an iconify callback.
@code
@code{.c}
glfwSetWindowIconifyCallback(window, window_iconify_callback);
@endcode
The callback function receives changes in the iconification state of the window.
@code
@code{.c}
void window_iconify_callback(GLFWwindow* window, int iconified)
{
if (iconified)
@ -1000,7 +1000,7 @@ void window_iconify_callback(GLFWwindow* window, int iconified)
You can also get the current iconification state with @ref glfwGetWindowAttrib.
@code
@code{.c}
int iconified = glfwGetWindowAttrib(window, GLFW_ICONIFIED);
@endcode
@ -1009,7 +1009,7 @@ int iconified = glfwGetWindowAttrib(window, GLFW_ICONIFIED);
Windows can be maximized (i.e. zoomed) with @ref glfwMaximizeWindow.
@code
@code{.c}
glfwMaximizeWindow(window);
@endcode
@ -1019,20 +1019,20 @@ function does nothing.
Maximized windows can be restored with @ref glfwRestoreWindow. This function
also restores windows from iconification.
@code
@code{.c}
glfwRestoreWindow(window);
@endcode
If you wish to be notified when a window is maximized or restored, whether by
the user, system or your own code, set a maximize callback.
@code
@code{.c}
glfwSetWindowMaximizeCallback(window, window_maximize_callback);
@endcode
The callback function receives changes in the maximization state of the window.
@code
@code{.c}
void window_maximize_callback(GLFWwindow* window, int maximized)
{
if (maximized)
@ -1048,7 +1048,7 @@ void window_maximize_callback(GLFWwindow* window, int maximized)
You can also get the current maximization state with @ref glfwGetWindowAttrib.
@code
@code{.c}
int maximized = glfwGetWindowAttrib(window, GLFW_MAXIMIZED);
@endcode
@ -1056,7 +1056,7 @@ By default, newly created windows are not maximized. You can change this
behavior by setting the [GLFW_MAXIMIZED](@ref GLFW_MAXIMIZED_hint) window hint
before creating the window.
@code
@code{.c}
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
@endcode
@ -1065,7 +1065,7 @@ glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
Windowed mode windows can be hidden with @ref glfwHideWindow.
@code
@code{.c}
glfwHideWindow(window);
@endcode
@ -1075,7 +1075,7 @@ and calling @ref glfwHideWindow on a full screen window does nothing.
Hidden windows can be shown with @ref glfwShowWindow.
@code
@code{.c}
glfwShowWindow(window);
@endcode
@ -1086,7 +1086,7 @@ existing window with @ref glfwSetWindowAttrib.
You can also get the current visibility state with @ref glfwGetWindowAttrib.
@code
@code{.c}
int visible = glfwGetWindowAttrib(window, GLFW_VISIBLE);
@endcode
@ -1094,7 +1094,7 @@ By default, newly created windows are visible. You can change this behavior by
setting the [GLFW_VISIBLE](@ref GLFW_VISIBLE_hint) window hint before creating
the window.
@code
@code{.c}
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
@endcode
@ -1108,7 +1108,7 @@ example moving it to a specific location.
Windows can be given input focus and brought to the front with @ref
glfwFocusWindow.
@code
@code{.c}
glfwFocusWindow(window);
@endcode
@ -1119,13 +1119,13 @@ to the top. For a less disruptive way of getting the user's attention, see
If you wish to be notified when a window gains or loses input focus, whether by
the user, system or your own code, set a focus callback.
@code
@code{.c}
glfwSetWindowFocusCallback(window, window_focus_callback);
@endcode
The callback function receives changes in the input focus state of the window.
@code
@code{.c}
void window_focus_callback(GLFWwindow* window, int focused)
{
if (focused)
@ -1141,7 +1141,7 @@ void window_focus_callback(GLFWwindow* window, int focused)
You can also get the current input focus state with @ref glfwGetWindowAttrib.
@code
@code{.c}
int focused = glfwGetWindowAttrib(window, GLFW_FOCUSED);
@endcode
@ -1149,7 +1149,7 @@ By default, newly created windows are given input focus. You can change this
behavior by setting the [GLFW_FOCUSED](@ref GLFW_FOCUSED_hint) window hint
before creating the window.
@code
@code{.c}
glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
@endcode
@ -1159,7 +1159,7 @@ glfwWindowHint(GLFW_FOCUSED, GLFW_FALSE);
If you wish to notify the user of an event without interrupting, you can request
attention with @ref glfwRequestWindowAttention.
@code
@code{.c}
glfwRequestWindowAttention(window);
@endcode
@ -1173,14 +1173,14 @@ attention, the system will automatically end the request.
If you wish to be notified when the contents of a window is damaged and needs
to be refreshed, set a window refresh callback.
@code
@code{.c}
glfwSetWindowRefreshCallback(m_handle, window_refresh_callback);
@endcode
The callback function is called when the contents of the window needs to be
refreshed.
@code
@code{.c}
void window_refresh_callback(GLFWwindow* window)
{
draw_editor_ui(window);
@ -1207,7 +1207,7 @@ Window framebuffers can be made transparent on a per-pixel per-frame basis with
the [GLFW_TRANSPARENT_FRAMEBUFFER](@ref GLFW_TRANSPARENT_FRAMEBUFFER_hint)
window hint.
@code
@code{.c}
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
@endcode
@ -1220,7 +1220,7 @@ with the
[GLFW_TRANSPARENT_FRAMEBUFFER](@ref GLFW_TRANSPARENT_FRAMEBUFFER_attrib)
window attribute.
@code
@code{.c}
if (glfwGetWindowAttrib(window, GLFW_TRANSPARENT_FRAMEBUFFER))
{
// window framebuffer is currently transparent
@ -1232,7 +1232,7 @@ GLFW comes with an example that enabled framebuffer transparency called `gears`.
The opacity of the whole window, including any decorations, can be set with @ref
glfwSetWindowOpacity.
@code
@code{.c}
glfwSetWindowOpacity(window, 0.5f);
@endcode
@ -1242,7 +1242,7 @@ opacity value for newly created windows is 1.
The current opacity of a window can be queried with @ref glfwGetWindowOpacity.
@code
@code{.c}
float opacity = glfwGetWindowOpacity(window);
@endcode
@ -1265,7 +1265,7 @@ interaction, (e.g. whether it has input focus), while others reflect inherent
properties of the window (e.g. what kind of border it has). Some are related to
the window and others to its OpenGL or OpenGL ES context.
@code
@code{.c}
if (glfwGetWindowAttrib(window, GLFW_FOCUSED))
{
// window has input focus
@ -1279,7 +1279,7 @@ The [GLFW_DECORATED](@ref GLFW_DECORATED_attrib),
[GLFW_FOCUS_ON_SHOW](@ref GLFW_FOCUS_ON_SHOW_attrib) window attributes can be
changed with @ref glfwSetWindowAttrib.
@code
@code{.c}
glfwSetWindowAttrib(window, GLFW_RESIZABLE, GLFW_FALSE);
@endcode
@ -1465,7 +1465,7 @@ 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
@code{.c}
glfwSwapBuffers(window);
@endcode
@ -1474,7 +1474,7 @@ function @ref glfwSwapInterval it is possible to select the minimum number of
monitor refreshes the driver should wait from the time @ref glfwSwapBuffers was
called before swapping the buffers:
@code
@code{.c}
glfwSwapInterval(1);
@endcode