{"id":5414,"library":"pyopengl-accelerate","title":"PyOpenGL-accelerate","description":"PyOpenGL-accelerate is a collection of Cython-coded extensions designed to optimize common, performance-critical operations within PyOpenGL 3.x. While not strictly required for PyOpenGL functionality, its installation is highly recommended to achieve improved rendering speeds, particularly when dealing with large arrays of data. It is maintained as an integral part of the broader PyOpenGL project. The current version is 3.1.10, with releases typically synchronized with the main PyOpenGL library.","status":"active","version":"3.1.10","language":"en","source_language":"en","source_url":"https://github.com/mcfletch/pyopengl","tags":["opengl","graphics","performance","cython","acceleration","3d"],"install":[{"cmd":"pip install PyOpenGL PyOpenGL-accelerate","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"PyOpenGL-accelerate provides performance enhancements for PyOpenGL; it does not function independently.","package":"PyOpenGL"},{"reason":"Required for building from source if pre-compiled wheels are not available for your platform/Python version.","package":"Cython","optional":true},{"reason":"Required for building the Cython extensions from source.","package":"C compiler","optional":true}],"imports":[{"note":"PyOpenGL-accelerate generally works by transparently patching PyOpenGL internals. Direct import is usually not necessary for its benefits, but might be used for specific low-level access or debugging.","symbol":"OpenGL_accelerate","correct":"import OpenGL_accelerate # Rarely explicitly imported, works implicitly"}],"quickstart":{"code":"import pygame\nfrom pygame.locals import *\n\nfrom OpenGL.GL import *\nfrom OpenGL.GLU import *\n\ndef draw_cube():\n    vertices = (\n        (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1),\n        (1, -1, 1), (1, 1, 1), (-1, -1, 1), (-1, 1, 1)\n    )\n    edges = (\n        (0,1), (0,3), (0,4), (2,1), (2,3), (2,7),\n        (6,3), (6,4), (6,7), (5,1), (5,4), (5,7)\n    )\n\n    glBegin(GL_LINES)\n    for edge in edges:\n        for vertex in edge:\n            glVertex3fv(vertices[vertex])\n    glEnd()\n\ndef main():\n    pygame.init()\n    display = (800, 600)\n    pygame.display.set_mode(display, DOUBLEBUF | OPENGL)\n\n    gluPerspective(45, (display[0] / display[1]), 0.1, 50.0)\n    glTranslatef(0.0, 0.0, -5)\n\n    while True:\n        for event in pygame.event.get():\n            if event.type == pygame.QUIT:\n                pygame.quit()\n                return\n\n        glRotatef(1, 3, 1, 1)\n        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)\n        draw_cube()\n        pygame.display.flip()\n        pygame.time.wait(10)\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"PyOpenGL-accelerate transparently enhances the performance of PyOpenGL code when installed. This quickstart demonstrates a basic rotating 3D cube using PyOpenGL with Pygame, where PyOpenGL-accelerate would provide underlying performance improvements without requiring explicit calls."},"warnings":[{"fix":"Focus on modern OpenGL techniques (e.g., Vertex Buffer Objects/VBOs) for significant performance gains, which PyOpenGL-accelerate can then further optimize.","message":"PyOpenGL-accelerate is not a silver bullet for all performance issues. It primarily optimizes specific 'slow points' in PyOpenGL 3.x, particularly for array-based operations. Older, less performant OpenGL patterns (like immediate mode with `glBegin`/`glEnd`) will not see significant benefits.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Simply install `PyOpenGL-accelerate` alongside `PyOpenGL`. Your existing PyOpenGL code will be accelerated automatically where applicable.","message":"PyOpenGL-accelerate typically works by transparently patching PyOpenGL internals. Users should not expect to import symbols directly from `OpenGL_accelerate` for most common usage, as its benefits are applied implicitly to PyOpenGL calls.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure a compatible C compiler (e.g., GCC on Linux, MSVC on Windows) is installed and configured in your system's PATH. Consider installing `Cython` explicitly if building from source. Look for pre-built wheels (`.whl` files) for your specific Python version and OS if `pip install` fails.","message":"Installation issues related to C compiler availability or specific Python/Cython versions are common, especially on platforms without pre-built wheels. This can lead to compilation errors during `pip install`.","severity":"breaking","affected_versions":"All versions, particularly with newer Python releases or non-standard environments."},{"fix":"Whenever possible, install both `PyOpenGL` and `PyOpenGL-accelerate` simultaneously using `pip install PyOpenGL PyOpenGL-accelerate` to ensure compatible versions are chosen by the package resolver. If issues persist, try a slightly older, stable pair of versions.","message":"There have been reports of `TypeError`s or other runtime issues when using mismatched versions of `PyOpenGL` and `PyOpenGL-accelerate`. While often compatible, specific combinations can cause problems.","severity":"gotcha","affected_versions":"Potentially all versions, especially when manually selecting versions."}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}