PyOpenGL-accelerate
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.
Warnings
- gotcha 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.
- gotcha 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.
- breaking 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`.
- gotcha 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.
Install
-
pip install PyOpenGL PyOpenGL-accelerate
Imports
- OpenGL_accelerate
import OpenGL_accelerate # Rarely explicitly imported, works implicitly
Quickstart
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
def draw_cube():
vertices = (
(1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, -1),
(1, -1, 1), (1, 1, 1), (-1, -1, 1), (-1, 1, 1)
)
edges = (
(0,1), (0,3), (0,4), (2,1), (2,3), (2,7),
(6,3), (6,4), (6,7), (5,1), (5,4), (5,7)
)
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glVertex3fv(vertices[vertex])
glEnd()
def main():
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF | OPENGL)
gluPerspective(45, (display[0] / display[1]), 0.1, 50.0)
glTranslatef(0.0, 0.0, -5)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
return
glRotatef(1, 3, 1, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
draw_cube()
pygame.display.flip()
pygame.time.wait(10)
if __name__ == '__main__':
main()