Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 14, 2026·3 min de lecture

GLFW — Multi-Platform Library for OpenGL, Vulkan, and Window Management

GLFW is a lightweight C library for creating windows, OpenGL and Vulkan contexts, and handling input. It provides a simple, portable API for desktop application and game development across Windows, macOS, and Linux without the overhead of a full framework.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Needs Confirmation · 66/100Policy : confirmer
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
GLFW Overview
Commande CLI universelle
npx tokrepo install 69c037ee-4f6e-11f1-9bc6-00163e2b0d79

Introduction

GLFW is a focused C library that handles the platform-specific tasks every graphics application needs: creating windows, setting up OpenGL or Vulkan contexts, and processing keyboard, mouse, and gamepad input. It deliberately avoids being a framework and instead provides the minimal portable foundation that lets you use whichever rendering API and architecture you prefer.

What GLFW Does

  • Creates and manages windows with OpenGL or Vulkan rendering contexts on Windows, macOS, and Linux
  • Handles keyboard, mouse, scroll, gamepad, and joystick input via callbacks or polling
  • Supports multiple monitors, full-screen modes, and high-DPI/Retina displays
  • Provides clipboard access, drag-and-drop file input, and system cursor customization
  • Exposes a Vulkan surface creation API and loader integration

Architecture Overview

GLFW is written in C99 with no external dependencies beyond the target platform's native APIs (Win32, Cocoa, X11/Wayland). The library provides a single-threaded event model where you create one or more windows, set callbacks, and poll or wait for events in your main loop. Context management is explicit, making it straightforward to use with multi-window or multi-context setups. The build system uses CMake and the library can be linked statically or dynamically.

Self-Hosting & Configuration

  • Install via system package manager or build from source with CMake
  • Include <GLFW/glfw3.h> and link against the glfw library
  • Call glfwInit() once at startup and glfwTerminate() at shutdown
  • Create windows with glfwCreateWindow() specifying size, title, and optional monitor for fullscreen
  • Set window hints before creation to request specific OpenGL versions, Vulkan support, or MSAA samples

Key Features

  • Minimal API surface with clear ownership semantics and no hidden global state
  • Native Wayland and X11 support on Linux with runtime backend selection
  • Built-in Vulkan surface creation without external loader boilerplate
  • High-DPI aware with content scale queries for proper UI sizing
  • Widely adopted as the windowing layer for graphics tutorials, engines, and tools

Comparison with Similar Tools

  • SDL — larger library covering audio, threading, networking, and 2D rendering; more batteries-included but bigger dependency
  • SFML — C++ multimedia library with built-in 2D graphics and audio; higher-level but less control over rendering pipeline
  • Dear ImGui backends — often paired with GLFW for immediate-mode GUI; GLFW handles the window, ImGui handles the UI
  • Raylib — beginner-friendly game library with built-in rendering; uses GLFW internally but abstracts it away
  • GLUT/FreeGLUT — legacy OpenGL windowing toolkit; simpler but less maintained and fewer features

FAQ

Q: Can GLFW be used with Vulkan? A: Yes. GLFW provides glfwCreateWindowSurface() for Vulkan surface creation and functions to query required Vulkan instance extensions. Set the GLFW_CLIENT_API hint to GLFW_NO_API when creating the window.

Q: Does GLFW support Wayland? A: Yes. Since version 3.4, GLFW supports Wayland natively alongside X11 on Linux. The backend can be selected at compile time or at runtime.

Q: Is GLFW thread-safe? A: Most GLFW functions must be called from the main thread. However, context management and certain input functions can be used from other threads when following the documented threading rules.

Q: Why choose GLFW over SDL? A: GLFW is smaller and more focused on window and context management. If you only need a window, an OpenGL/Vulkan context, and input handling without audio, networking, or 2D rendering, GLFW is a lighter dependency.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires