mirror of
https://github.com/glfw/glfw.git
synced 2026-09-20 08:23:13 +00:00
Add language tags for C code sections
This commit is contained in:
+20
-20
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user