PyOpenGL-accelerate

3.1.10 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

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.

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()

view raw JSON →