WGL (sometimes pronounced "wiggle") is the application programming interface (API) that connects OpenGL to the windowing system of Microsoft Windows. It fills the same role on Windows that GLX fills on the X Window System, CGL on macOS, and EGL on a range of embedded and native platforms. WGL is a Windows-specific extension to OpenGL whose functions use the wgl prefix and whose constant tokens use the WGL_ prefix.
Role
OpenGL itself defines only rendering operations; it does not define how a rendering surface is attached to a window, how a rendering context is created, or how buffers are presented on screen. Those responsibilities belong to a platform-specific "window-system binding." WGL is Windows' binding. It mediates between the Win32 graphics device interface (GDI) and an OpenGL implementation, using GDI objects such as the device context (HDC) and a WGL-specific rendering-context handle (HGLRC).
Because higher-level toolkits (for example GLUT, GLFW, and SDL) and extension loaders (for example GLEW and glad) typically hide WGL, many OpenGL programs never call WGL functions directly.
Core functions
Microsoft documents the following WGL functions as the core Windows OpenGL interface:
- Pixel-format selection:
ChoosePixelFormat,DescribePixelFormat,GetPixelFormat,SetPixelFormat,GetEnhMetaFilePixelFormat - Buffer presentation:
SwapBuffers,wglSwapLayerBuffers - Context management:
wglCreateContext,wglCreateLayerContext,wglDeleteContext,wglGetCurrentContext,wglGetCurrentDC,wglMakeCurrent,wglShareLists,wglCopyContext - Extension lookup:
wglGetProcAddress - Overlay/underlay layers:
wglDescribeLayerPlane,wglGetLayerPaletteEntries,wglSetLayerPaletteEntries,wglRealizeLayerPalette - Font helpers:
wglUseFontBitmaps,wglUseFontOutlines
Associated structures include PIXELFORMATDESCRIPTOR, LAYERPLANEDESCRIPTOR, GLYPHMETRICSFLOAT, and POINTFLOAT.
Extensions
The original WGL interface is small and largely fixed, so almost all modern functionality is provided through WGL extensions:
WGL_ARB_extensions_string/WGL_EXT_extensions_string— enumerate available WGL extensions (wglGetExtensionsStringARB/EXT).WGL_ARB_pixel_format— attribute-list pixel-format selection (wglChoosePixelFormatARB), replacing reliance on the non-extensiblePIXELFORMATDESCRIPTOR.WGL_ARB_create_context— context creation with attributes (wglCreateContextAttribsARB), which is how OpenGL 3.0-and-later and core/compatibility profiles are requested.WGL_ARB_create_context_profile— profile and flag selection.WGL_EXT_swap_control— vertical-sync control (wglSwapIntervalEXT,wglGetSwapIntervalEXT);WGL_EXT_swap_control_tearextends this to late-swap behavior.WGL_ARB_multisample,WGL_ARB_framebuffer_sRGB,WGL_ARB_pixel_format_float— multisampled, sRGB, and floating-point framebuffers.
WGL extensions are loaded by obtaining function addresses with wglGetProcAddress; those addresses are specific to a pixel format rather than to the process as a whole.
Bootstrapping considerations
Because the functions that enumerate WGL extensions (wglGetExtensionsStringARB) are themselves extensions, an application must first create a temporary ("dummy") context with the fixed core functions, query its extensions, and then create the real context. Two constraints matter in this process: a window's pixel format can be set only once on Windows, so changing it may require recreating the window; and wglGetProcAddress is documented to return NULL on failure, though some implementations return other sentinel values (such as 1, 2, 3, or −1).
Relationship to Microsoft's implementation
Windows ships a software OpenGL implementation (historically reported as OpenGL 1.1) through the operating system's opengl32.dll, while graphics-vendor installable client drivers (ICDs) provide hardware-accelerated support for later OpenGL versions. WGL is the interface through which these drivers expose both context creation and their extensions.
See also
- GLX — the equivalent X11 interface to OpenGL
- CGL — the equivalent macOS interface to OpenGL
- EGL — a similar interface between rendering APIs and native windowing systems
- GLUT, GLFW, SDL — higher-level libraries that abstract WGL, GLX, and related bindings
References
- Microsoft Learn, "WGL and Windows Reference" and "WGL Functions" (Win32 OpenGL documentation)
- Khronos OpenGL Wiki, "Creating an OpenGL Context (WGL)"
- Khronos Group, OpenGL Registry — WGL extension specifications (
WGL_EXT_swap_control,WGL_ARB_pixel_format,WGL_ARB_create_context, and others) - Wikipedia, "WGL (API)"