or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

array-operations.mdcore-opengl.mderror-handling.mdglu-utilities.mdglut-window.mdindex.mdplatform-support.mdshaders.md
tile.json

tessl/pypi-pyopengl

Comprehensive ctypes-based OpenGL binding for Python providing access to OpenGL, GLU, and GLUT functionality

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyopengl@3.1.x

To install, run

npx @tessl/cli install tessl/pypi-pyopengl@3.1.0

index.mddocs/

PyOpenGL

A comprehensive ctypes-based OpenGL binding for Python, providing complete access to OpenGL, GLU, and GLUT functionality. PyOpenGL enables 3D graphics programming with support for OpenGL versions 1.0 through 4.6, extensive vendor-specific extensions, and robust array handling for high-performance graphics applications.

Package Information

  • Package Name: PyOpenGL
  • Language: Python
  • Installation: pip install PyOpenGL PyOpenGL_accelerate

Core Imports

import OpenGL

Common import patterns for OpenGL functionality:

from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *

Namespace imports for cleaner code:

from OpenGL import GL, GLU, GLUT
import OpenGL.GL as gl

Array and utility imports:

from OpenGL.arrays import vbo
from OpenGL.GL import shaders
from OpenGL.error import GLError

Basic Usage

import pygame
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
import numpy as np

# Initialize display with OpenGL context
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, pygame.DOUBLEBUF | pygame.OPENGL)

# Set up 3D perspective
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
glTranslatef(0.0, 0.0, -5)

# Basic rendering setup
glEnable(GL_DEPTH_TEST)
glClearColor(0.0, 0.0, 0.0, 1.0)

# Simple triangle vertices
vertices = np.array([
    [0.0, 1.0, 0.0],   # Top vertex
    [-1.0, -1.0, 0.0], # Bottom left
    [1.0, -1.0, 0.0]   # Bottom right
], dtype=np.float32)

# Render loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    
    # Clear buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    
    # Draw triangle
    glBegin(GL_TRIANGLES)
    for vertex in vertices:
        glVertex3fv(vertex)
    glEnd()
    
    pygame.display.flip()
    pygame.time.wait(10)

pygame.quit()

Architecture

PyOpenGL's modular architecture provides complete OpenGL access with Python-friendly enhancements:

  • OpenGL.GL: Core OpenGL functions organized by version (1.0-4.6) with extensive extensions
  • OpenGL.GLU: Utility functions for common operations (perspective, tessellation, quadrics)
  • OpenGL.GLUT: Window management and user interface toolkit
  • OpenGL.arrays: Unified array handling supporting NumPy, ctypes, and Python built-ins
  • OpenGL.platform: Cross-platform abstraction for context creation and library loading
  • OpenGL.raw: Low-level ctypes bindings providing direct access to native OpenGL functions

Configuration

# Global configuration flags
ERROR_CHECKING: bool  # Enable/disable error checking (default: True)
USE_ACCELERATE: bool  # Use Cython acceleration if available (default: True)
CONTEXT_CHECKING: bool  # Validate OpenGL context on calls (default: False)
ERROR_ON_COPY: bool  # Prevent implicit data copying (default: False)
STORE_POINTERS: bool  # Memory management for arrays (default: True)
FULL_LOGGING: bool  # Comprehensive call logging (default: False)

Capabilities

Core OpenGL Functions

Complete OpenGL API including drawing primitives, state management, transformations, texturing, lighting, and vertex operations. Supports all OpenGL versions from 1.0 through 4.6 with comprehensive extension coverage.

def glBegin(mode): ...
def glEnd(): ...
def glVertex3f(x: float, y: float, z: float): ...
def glColor3f(red: float, green: float, blue: float): ...
def glEnable(cap): ...
def glDisable(cap): ...
def glClear(mask): ...
def glLoadIdentity(): ...
def glTranslatef(x: float, y: float, z: float): ...
def glRotatef(angle: float, x: float, y: float, z: float): ...

Core OpenGL

OpenGL Utility Functions (GLU)

High-level utility functions for perspective projection, object rendering, tessellation, and coordinate transformations that simplify common OpenGL operations.

def gluPerspective(fovy: float, aspect: float, zNear: float, zFar: float): ...
def gluLookAt(eyeX: float, eyeY: float, eyeZ: float, 
              centerX: float, centerY: float, centerZ: float,
              upX: float, upY: float, upZ: float): ...
def gluSphere(quad: GLUquadric, radius: float, slices: int, stacks: int): ...
def gluNewQuadric() -> GLUquadric: ...

GLU Utilities

Window Management (GLUT)

Complete window management and event handling system for creating OpenGL applications with keyboard, mouse, and timer support.

def glutInit(argv: list): ...
def glutCreateWindow(title: str) -> int: ...
def glutDisplayFunc(func): ...
def glutMainLoop(): ...
def glutInitDisplayMode(mode): ...
def glutSwapBuffers(): ...

GLUT Window Management

Array Handling

Unified array interface supporting NumPy arrays, Python lists, ctypes arrays, and other data formats with automatic conversion and memory management.

class VBO:
    def __init__(self, data, usage=GL_STATIC_DRAW, target=GL_ARRAY_BUFFER): ...
    def bind(self): ...
    def unbind(self): ...
    def delete(self): ...
    def __enter__(self): ...
    def __exit__(self, exc_type, exc_val, exc_tb): ...

Array Operations

Shader Programming

Modern OpenGL shader support with compilation, linking, and program management utilities for vertex and fragment shaders.

def compileShader(source: str, shaderType) -> int: ...
def compileProgram(*shaders) -> int: ...
def glUseProgram(program: int): ...
def glGetUniformLocation(program: int, name: str) -> int: ...
def glUniform1f(location: int, value: float): ...

Shaders

Error Handling

Comprehensive error detection and reporting with OpenGL-specific exceptions, context validation, and debugging utilities.

class GLError(Exception):
    def __init__(self, err, result, cArguments, name): ...

class NoContext(Exception): ...
class CopyError(Exception): ...

def glGetError() -> int: ...

Error Handling

Platform Integration

Cross-platform support for Windows (WGL), Linux/X11 (GLX), macOS (CGL), and embedded systems (EGL) with automatic platform detection.

def setPlatform(key: str): ...
def GetCurrentPlatform(): ...

Platform Support