Category: 📂 gl/ (Graphics & Display)
Header: <GL/gl.h>
Scope: OpenGL 1.1+ (Legacy/Core)
The GL/gl.h header provides the interface for OpenGL, a cross-platform API for rendering 2D and 3D vector graphics. It interacts with the GPU driver to perform hardware-accelerated rendering.
| Facility Category | Key Symbols | Description |
|---|---|---|
| State Control | glClear, glClearColor, glEnable | Configuring the global rendering state. |
| Drawing | glDrawArrays, glDrawElements | Initiating rendering commands from buffers. |
| Buffers | glGenBuffers, glBindBuffer | Managing GPU-side memory (VBOs). |
| View System | glViewport | Mapping Normalized Device Coordinates to window pixels. |
typedef unsigned int GLuint;Standard unsigned 32-bit integer.
typedef int GLint;Standard signed 32-bit integer.
typedef float GLfloat;Standard 32-bit floating point.
typedef unsigned int GLenum;Enumerated type for OpenGL constants (e.g., GL_FLOAT, GL_TRIANGLES).
void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)Specifies the red, green, blue, and alpha values used by glClear to clear the color buffers. Values are clamped to [0, 1].
Returns: None.
Example
#include <GL/gl.h>
void setup_render(void) {
// Set clear color to teal
glClearColor(0.0f, 0.5f, 0.5f, 1.0f);
}void glClear(GLbitfield mask)Sets the bitplane area of the window to values previously selected by glClearColor, glClearDepth, and glClearStencil.
mask: Bitwise OR ofGL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT, etc.
Returns: None.
void glGenBuffers(GLsizei n, GLuint *buffers)Generates n buffer object names (IDs). No buffer objects are associated with the returned names until they are first bound.
Returns: None.
void glBindBuffer(GLenum target, GLuint buffer)Binds a named buffer object to the specified buffer binding point (target).
target:GL_ARRAY_BUFFER(Vertex attributes),GL_ELEMENT_ARRAY_BUFFER(Indices), etc.
Returns: None.
void glBufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage)Creates and initializes a buffer object's data store.
usage:GL_STATIC_DRAW,GL_DYNAMIC_DRAW, etc.
Returns: None.
Example
#include <GL/gl.h>
void upload_triangle(GLuint vbo) {
float vertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
}void glDrawArrays(GLenum mode, GLint first, GLsizei count)Render primitives from array data.
mode:GL_TRIANGLES,GL_LINES, etc.
Returns: None.
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)Specifies the affine transformation of x and y from normalized device coordinates to window coordinates.
Returns: None.