Registry / ai-ml / pyopengl

pyopengl

JSON →
library3.1.10pypypi✓ verified 26d ago

PyOpenGL (version 3.1.10) provides standard OpenGL bindings for Python, allowing Python programs to interact directly with OpenGL graphics APIs. It offers access to both core OpenGL functionality and extensions, enabling development of 2D/3D graphics applications. The library is mature and stable, with a moderate release cadence driven by bug fixes and OpenGL specification updates.

pip install PyOpenGL PyOpenGL_accelerate
INSTALL
IMPORT
SIG · PYOPENGL
P
pyopengl
ai-mlpythonv3.1.10
Install
3.3s avg
Import
Disk
56MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.1.10 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 55.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.3s · import 0.000s · 59MB
56MB installed
● package 56MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GL
from OpenGL.GL import *
import GL
Core OpenGL functions are within the OpenGL.GL module.
GLUT
from OpenGL.GLUT import *
import GLUT
The OpenGL Utility Toolkit (windowing, input) is in OpenGL.GLUT.
GLU
from OpenGL.GLU import *
import GLU
The OpenGL Utility Library (matrix operations, NURBS) is in OpenGL.GLU.
shaders
from OpenGL.GL.shaders import compileShader, compileProgram
For programmable pipeline (modern OpenGL) shader compilation.

This example demonstrates basic PyOpenGL usage with GLUT to create a window and draw a simple colored triangle. It uses the traditional fixed-function pipeline for simplicity. Ensure you have GLUT installed on your system (e.g., `freeglut3-dev` on Debian/Ubuntu, or a GLUT for Windows build).

import sys from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * def draw_triangle(): glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslatef(0.0, 0.0, -5.0) glBegin(GL_TRIANGLES) glColor3f(1.0, 0.0, 0.0) # Red glVertex3f(-1.0, -1.0, 0.0) glColor3f(0.0, 1.0, 0.0) # Green glVertex3f(1.0, -1.0, 0.0) glColor3f(0.0, 0.0, 1.0) # Blue glVertex3f(0.0, 1.0, 0.0) glEnd() glutSwapBuffers() def reshape(width, height): glViewport(0, 0, width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45, (width / height), 0.1, 50.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() def keyboard(key, x, y): if key == b'\x1b': # ESC key sys.exit() def main(): glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(600, 600) glutInitWindowPosition(100, 100) glutCreateWindow(b"PyOpenGL Triangle (ESC to exit)") glClearColor(0.2, 0.2, 0.2, 1.0) # Dark gray background glEnable(GL_DEPTH_TEST) glutDisplayFunc(draw_triangle) glutIdleFunc(draw_triangle) # Redraw continuously glutReshapeFunc(reshape) glutKeyboardFunc(keyboard) glutMainLoop() if __name__ == '__main__': main()
Debug
Known issues
gotchaMany simple PyOpenGL examples, including the quickstart, use the fixed-function pipeline (`glBegin`/`glEnd`), which is deprecated in modern OpenGL (3.1+ core profiles). This can lead to poor performance, driver issues, or not working at all on systems configured for core profiles.
fix
For new development or performance-critical applications, migrate to the programmable pipeline using shaders (`OpenGL.GL.shaders` module) and Vertex Buffer Objects (`OpenGL.arrays.vbo`).
affects: All PyOpenGL versions with modern OpenGL drivers/contexts
gotchaPyOpenGL is solely a binding library; it does not handle window creation or OpenGL context management itself. An external library like Pygame, Pyglet, GLFW (via `pyGLFW`), PyQt, or GLUT (as shown in quickstart) is required to set up the rendering environment.
fix
Choose a suitable windowing toolkit (e.g., GLUT, GLFW, PyQt) and integrate its context creation/management with PyOpenGL calls. Ensure the correct context is active before making OpenGL calls.
affects: All
gotchaOn Linux, installing PyOpenGL often requires system-level OpenGL development libraries (e.g., `mesa-common-dev` or `libgl1-mesa-dev` for Debian/Ubuntu, `freeglut-dev` for GLUT). Without these, `pip install` or runtime might fail.
fix
Install the necessary development packages via your system's package manager (e.g., `sudo apt-get install freeglut3-dev mesa-common-dev` on Ubuntu) before running `pip install PyOpenGL`.
affects: All, especially on Linux/Unix systems
gotchaOpenGL errors are not automatically translated into Python exceptions by PyOpenGL. Developers must explicitly call `glGetError()` after OpenGL operations to check for errors and handle them, especially during development.
fix
Implement explicit `glGetError()` checks throughout your OpenGL code to identify and debug issues. Consider wrapping OpenGL calls with an error-checking decorator for development builds.
affects: All
gotchaWhile PyOpenGL automatically converts Python types (lists, tuples, numbers) to C types for OpenGL calls, for large data sets (e.g., vertex data), using `numpy` arrays is significantly more performant due to reduced Python overhead and direct memory access.
fix
For performance-critical code involving large arrays, use `numpy` arrays for data (e.g., `numpy.array([...], dtype=numpy.float32)`) and leverage Vertex Buffer Objects (VBOs) and Element Buffer Objects (EBOs) for efficient data transfer to the GPU.
affects: All
Upgrade
Version history
3.1.10latest on PyPI · released Aug 18, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
23 hits · last 30 days
node
18
OpenAI (training)
1
Resources
pyopengl — pip install pyopengl · libregistry