This page documents Dear ImGui's OpenGL renderer backends, which translate ImGui draw commands into OpenGL API calls. These backends handle shader compilation, buffer management, texture uploads, and render state configuration for OpenGL-based rendering.
For information about platform backends (GLFW, SDL, Win32, etc.) that work alongside these renderer backends, see Platform Backends. For other renderer backends (Vulkan, DirectX, Metal, etc.), see Renderer Backends.
Dear ImGui provides two OpenGL renderer backends:
| Backend | File | Use Case | GL Versions | Pipeline |
|---|---|---|---|---|
| OpenGL 3 | imgui_impl_opengl3.cpp/h | Modern applications | Desktop: 2.x, 3.x, 4.x ES: 2.0, 3.0 WebGL: 1.0, 2.0 | Programmable (shaders) |
| OpenGL 2 | imgui_impl_opengl2.cpp/h | Legacy/reference | Desktop: 1.x, 2.x | Fixed-function |
Recommendation: Use imgui_impl_opengl3 for all new projects. The OpenGL 2 backend is provided primarily as a reference implementation and for very old systems that cannot support shaders.
Key Features:
ImGuiBackendFlags_RendererHasVtxOffset: Large mesh support (64k+ vertices) - Desktop GL 3.2+ onlyImGuiBackendFlags_RendererHasTextures: Dynamic font atlas texture updatesGLuint texture identifiersSources: backends/imgui_impl_opengl3.cpp1-119 backends/imgui_impl_opengl2.cpp1-49
ImGui_ImplOpenGL3_Data stores all backend state including:
Sources: backends/imgui_impl_opengl3.cpp232-257
Initialization Process:
GL Loader: The backend includes an embedded minimal GL loader (imgui_impl_opengl3_loader.h) to avoid external dependencies. This is automatically used unless you define IMGUI_IMPL_OPENGL_LOADER_CUSTOM.
Version Detection: The backend detects GL version and profile at runtime:
GL_VERSION stringglGetIntegerv(GL_MAJOR_VERSION/GL_MINOR_VERSION)GLSL Version: You can specify the GLSL version string or let the backend choose defaults:
"#version 130" (or "#version 150" on macOS)"#version 100" (WebGL 1.0)"#version 300 es" (WebGL 2.0)Example Initialization:
Sources: backends/imgui_impl_opengl3.cpp314-427 backends/imgui_impl_opengl3.cpp291-311
The following table shows the correspondence between OpenGL and GLSL versions:
| OpenGL Version | GLSL Version | String |
|---|---|---|
| 2.0 | 110 | "#version 110" |
| 2.1 | 120 | "#version 120" |
| 3.0 | 130 | "#version 130" |
| 3.1 | 140 | "#version 140" |
| 3.2 | 150 | "#version 150" |
| 3.3 | 330 | "#version 330 core" |
| 4.0+ | 400+ | "#version 400 core" |
| ES 2.0 | 100 | "#version 100" |
| ES 3.0 | 300 | "#version 300 es" |
Compile-Time Defines:
IMGUI_IMPL_OPENGL_ES2: Force OpenGL ES 2.0 mode (auto-detected on iOS/Android/Emscripten)IMGUI_IMPL_OPENGL_ES3: Force OpenGL ES 3.0 modeIMGUI_IMPL_OPENGL_LOADER_CUSTOM: Disable embedded GL loaderSources: backends/imgui_impl_opengl3.cpp102-118 backends/imgui_impl_opengl3.cpp386-400
The shaders are simple and perform:
Shaders are compiled at device object creation time with appropriate version strings and precision qualifiers for ES contexts.
Sources: backends/imgui_impl_opengl3.cpp601-715
Key Rendering Steps:
draw_data->Textures listSources: backends/imgui_impl_opengl3.cpp535-785
The backend saves and restores extensive GL state to avoid interfering with the application:
State Backup & Restore:
Sources: backends/imgui_impl_opengl3.cpp787-984
Texture Update Process:
RenderDrawData() for textures with non-OK statusglTexImage2DglTexSubImage2D for partial updatesglDeleteTextures and clears texture IDPixel Store State: The backend sets GL_UNPACK_ALIGNMENT to 1 before texture operations to handle tightly packed RGBA data.
Sources: backends/imgui_impl_opengl3.cpp987-1094
The backend uses dynamic vertex and index buffers that grow as needed:
Buffer Sizing Strategy:
TotalVtxCount + 5000 / TotalIdxCount + 10000GL_STREAM_DRAW (data changes every frame)Vertex Format (ImDrawVert):
Attribute 0 (aPos): 2 floats at offset 0
Attribute 1 (aUV): 2 floats at offset 8
Attribute 2 (aColor): 4 ubytes at offset 16 (normalized)
Large Mesh Support: Desktop GL 3.2+ supports ImGuiBackendFlags_RendererHasVtxOffset via glDrawElementsBaseVertex(), allowing meshes with 64k+ vertices even with 16-bit indices.
Sources: backends/imgui_impl_opengl3.cpp1096-1166 backends/imgui_impl_opengl3.cpp458-530
Desktop GL:
GL_NUM_EXTENSIONSOpenGL ES 2.0 / WebGL 1.0:
OES_vertex_array_object)lowp, mediump)GL_UNPACK_ROW_LENGTH (except with pixel unpack buffer)OpenGL ES 3.0 / WebGL 2.0:
highp precision availableglBindSampler() supportGL_UNPACK_ROW_LENGTH availableSources: backends/imgui_impl_opengl3.cpp152-220 backends/imgui_impl_opengl3.cpp408-424
The OpenGL 2 backend (imgui_impl_opengl2.cpp/h) uses the fixed-function pipeline and is provided primarily for reference and very old systems.
Use Cases:
Limitations:
ImGuiBackendFlags_RendererHasVtxOffset (cannot handle 64k+ vertex meshes efficiently)glUseProgram(0))Key Differences:
| Aspect | OpenGL 3 | OpenGL 2 |
|---|---|---|
| Pipeline | Programmable (shaders) | Fixed-function |
| Vertex Data | VBO/VAO | Client-side arrays |
| Projection | Uniform matrix | Matrix stack (glOrtho) |
| Drawing | glDrawElements[BaseVertex] | glDrawElements |
| Texture | Shader sampling | Fixed-function units |
| State Isolation | Full backup/restore | Limited (no shader reset) |
OpenGL 2 Rendering Setup:
glMatrixMode(GL_PROJECTION) and glOrtho() for orthographic projectionglEnableClientState() and glVertexPointer/glTexCoordPointer/glColorPointerGL_TEXTURE_ENV and fixed-function texture unitsglUseProgram(0) or reset shader stateSources: backends/imgui_impl_opengl2.cpp91-272
Sources: backends/imgui_impl_opengl3.h34-48 backends/imgui_impl_opengl2.h31-43
Define these in your imconfig.h or before including the backend:
Backend Flags (set automatically):
ImGuiBackendFlags_RendererHasVtxOffset: Set on Desktop GL 3.2+ for large mesh supportImGuiBackendFlags_RendererHasTextures: Always set, enables dynamic font atlasTexture IDs: User textures should be passed as (ImTextureID)(intptr_t)texture_id where texture_id is a GLuint OpenGL texture name.
Sources: backends/imgui_impl_opengl3.cpp375-379 backends/imgui_impl_opengl3.h46-58
The OpenGL 3 backend includes a minimal GL function loader to eliminate external dependencies:
Features:
IMGUI_IMPL_OPENGL_LOADER_CUSTOMSupported Loaders: If you prefer external loaders, the backend is compatible with:
IMGUI_IMPL_OPENGL_LOADER_CUSTOMRegeneration: The loader can be regenerated using the gl3w_stripped project if new GL functions are needed.
Sources: backends/imgui_impl_opengl3_loader.h1-26 backends/imgui_impl_opengl3.cpp291-311
Refresh this wiki