ScriptsMay 14, 2026·3 min read

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.

Agent ready

This asset can be read and installed directly by agents

TokRepo exposes a universal CLI command, install contract, metadata JSON, adapter-aware plan, and raw content links so agents can judge fit, risk, and next actions.

Needs Confirmation · 66/100Policy: confirm
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
GLFW Overview
Universal CLI install command
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

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets