Comprehensive ctypes-based OpenGL binding for Python providing access to OpenGL, GLU, and GLUT functionality
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Complete OpenGL API providing fundamental graphics functionality including drawing primitives, state management, transformations, texturing, lighting, and vertex operations. PyOpenGL supports all OpenGL versions from 1.0 through 4.6 with comprehensive extension coverage from major vendors.
Basic geometric primitives for immediate mode rendering with points, lines, triangles, and quads.
def glBegin(mode):
"""
Begin primitive rendering.
Parameters:
- mode: Primitive type (GL_POINTS, GL_LINES, GL_TRIANGLES, GL_QUADS, etc.)
"""
def glEnd():
"""End primitive rendering."""
def glVertex2f(x: float, y: float):
"""Specify 2D vertex coordinates."""
def glVertex3f(x: float, y: float, z: float):
"""Specify 3D vertex coordinates."""
def glVertex3fv(v: list):
"""
Specify 3D vertex from array.
Parameters:
- v: Array-like of 3 float values [x, y, z]
"""Modern OpenGL vertex array rendering for high-performance graphics.
def glDrawArrays(mode, first: int, count: int):
"""
Draw arrays of vertex data.
Parameters:
- mode: Primitive type
- first: Starting array index
- count: Number of vertices to render
"""
def glDrawElements(mode, count: int, type, indices):
"""
Draw indexed vertex arrays.
Parameters:
- mode: Primitive type
- count: Number of elements
- type: Index data type (GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT)
- indices: Index array or buffer offset
"""
def glVertexPointer(size: int, type, stride: int, pointer):
"""
Define vertex coordinate array.
Parameters:
- size: Coordinates per vertex (2, 3, or 4)
- type: Data type (GL_FLOAT, GL_DOUBLE, etc.)
- stride: Byte offset between vertices
- pointer: Array data or buffer offset
"""
def glColorPointer(size: int, type, stride: int, pointer):
"""Define color array for vertices."""
def glNormalPointer(type, stride: int, pointer):
"""Define normal vector array."""
def glTexCoordPointer(size: int, type, stride: int, pointer):
"""Define texture coordinate array."""
def glEnableClientState(array):
"""
Enable vertex array.
Parameters:
- array: Array type (GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_NORMAL_ARRAY, etc.)
"""
def glDisableClientState(array):
"""Disable vertex array."""OpenGL state machine control for rendering modes, capabilities, and parameters.
def glEnable(cap):
"""
Enable OpenGL capability.
Parameters:
- cap: Capability (GL_DEPTH_TEST, GL_LIGHTING, GL_TEXTURE_2D, etc.)
"""
def glDisable(cap):
"""Disable OpenGL capability."""
def glIsEnabled(cap) -> bool:
"""Test if capability is enabled."""
def glGetBooleanv(pname) -> list:
"""Get boolean state values."""
def glGetIntegerv(pname) -> list:
"""Get integer state values."""
def glGetFloatv(pname) -> list:
"""Get float state values."""
def glGetDoublev(pname) -> list:
"""Get double state values."""
# Convenience aliases for state queries
glGetBoolean = glGetBooleanv # Alias for boolean state query
glGetDouble = glGetDoublev # Alias for double state query
glGetFloat = glGetFloatv # Alias for float state query
glGetInteger = glGetIntegerv # Alias for integer state queryTransformation matrix management for model, view, and projection transformations.
def glMatrixMode(mode):
"""
Set current matrix mode.
Parameters:
- mode: Matrix type (GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE)
"""
def glLoadIdentity():
"""Load identity matrix."""
def glLoadMatrixf(m: list):
"""
Load matrix from array.
Parameters:
- m: 16-element array in column-major order
"""
def glMultMatrixf(m: list):
"""Multiply current matrix by given matrix."""
def glPushMatrix():
"""Push current matrix onto stack."""
def glPopMatrix():
"""Pop matrix from stack."""
def glTranslatef(x: float, y: float, z: float):
"""Apply translation transformation."""
def glRotatef(angle: float, x: float, y: float, z: float):
"""
Apply rotation transformation.
Parameters:
- angle: Rotation angle in degrees
- x, y, z: Rotation axis vector
"""
def glScalef(x: float, y: float, z: float):
"""Apply scaling transformation."""
# Convenience aliases for common functions
glRotate = glRotated # Alias for double-precision rotation
glTranslate = glTranslated # Alias for double-precision translation
glScale = glScaled # Alias for double-precision scaling
glLight = glLightfv # Alias for vector light parameter setting
glTexCoord = glTexCoord2d # Alias for 2D double-precision texture coordinates
glNormal = glNormal3d # Alias for 3D double-precision normal vectorsColor specification and material properties for lighting calculations.
def glColor3f(red: float, green: float, blue: float):
"""Set current color (RGB)."""
def glColor4f(red: float, green: float, blue: float, alpha: float):
"""Set current color with alpha (RGBA)."""
def glColor3fv(v: list):
"""Set color from RGB array."""
def glColor4fv(v: list):
"""Set color from RGBA array."""
def glNormal3f(nx: float, ny: float, nz: float):
"""Set current normal vector."""
def glNormal3fv(v: list):
"""Set normal from array."""
def glMaterialf(face, pname, param: float):
"""
Set material property (single value).
Parameters:
- face: Material face (GL_FRONT, GL_BACK, GL_FRONT_AND_BACK)
- pname: Property name (GL_SHININESS)
- param: Property value
"""
def glMaterialfv(face, pname, params: list):
"""
Set material property (array values).
Parameters:
- pname: Property (GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION)
- params: Property values array
"""Lighting system configuration and light source management.
def glLightf(light, pname, param: float):
"""
Set light parameter (single value).
Parameters:
- light: Light identifier (GL_LIGHT0 through GL_LIGHT7)
- pname: Parameter name
- param: Parameter value
"""
def glLightfv(light, pname, params: list):
"""
Set light parameter (array values).
Parameters:
- pname: Parameter (GL_POSITION, GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR)
- params: Parameter values array
"""
def glLightModelfv(pname, params: list):
"""
Set lighting model parameters.
Parameters:
- pname: Model parameter (GL_LIGHT_MODEL_AMBIENT, GL_LIGHT_MODEL_TWO_SIDE)
- params: Parameter values
"""
def glShadeModel(mode):
"""
Set shading model.
Parameters:
- mode: Shading type (GL_FLAT, GL_SMOOTH)
"""Texture mapping functionality for applying images to geometry.
def glGenTextures(n: int) -> list:
"""
Generate texture names.
Parameters:
- n: Number of texture names to generate
Returns:
List of texture identifiers
"""
def glBindTexture(target, texture: int):
"""
Bind texture to target.
Parameters:
- target: Texture target (GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.)
- texture: Texture identifier
"""
def glTexImage2D(target, level: int, internalformat, width: int, height: int,
border: int, format, type, pixels):
"""
Define 2D texture image.
Parameters:
- target: Texture target
- level: Mipmap level (0 for base level)
- internalformat: Internal format (GL_RGB, GL_RGBA, etc.)
- width, height: Image dimensions
- border: Border width (must be 0)
- format: Pixel format
- type: Pixel data type
- pixels: Image data array
"""
def glTexParameteri(target, pname, param: int):
"""
Set texture parameter.
Parameters:
- pname: Parameter (GL_TEXTURE_WRAP_S, GL_TEXTURE_MAG_FILTER, etc.)
- param: Parameter value
"""
def glTexCoord2f(s: float, t: float):
"""Set current texture coordinates."""
def glTexCoord2fv(v: list):
"""Set texture coordinates from array."""Frame buffer and depth buffer operations.
def glClear(mask):
"""
Clear buffers.
Parameters:
- mask: Buffer mask (GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT)
"""
def glClearColor(red: float, green: float, blue: float, alpha: float):
"""Set clear color for color buffer."""
def glClearDepth(depth: float):
"""
Set clear value for depth buffer.
Parameters:
- depth: Clear depth (typically 1.0)
"""
def glDepthFunc(func):
"""
Set depth test function.
Parameters:
- func: Comparison function (GL_LESS, GL_LEQUAL, GL_GREATER, etc.)
"""
def glDepthMask(flag: bool):
"""Enable/disable depth buffer writing."""Viewport transformation and clipping plane management.
def glViewport(x: int, y: int, width: int, height: int):
"""
Set viewport transformation.
Parameters:
- x, y: Lower-left corner coordinates
- width, height: Viewport dimensions
"""
def glScissor(x: int, y: int, width: int, height: int):
"""Set scissor test rectangle."""
def glClipPlane(plane, equation: list):
"""
Define clipping plane.
Parameters:
- plane: Plane identifier (GL_CLIP_PLANE0 through GL_CLIP_PLANE5)
- equation: Plane equation coefficients [A, B, C, D]
"""GL_POINTS: int
GL_LINES: int
GL_LINE_STRIP: int
GL_LINE_LOOP: int
GL_TRIANGLES: int
GL_TRIANGLE_STRIP: int
GL_TRIANGLE_FAN: int
GL_QUADS: int
GL_QUAD_STRIP: int
GL_POLYGON: intGL_COLOR_BUFFER_BIT: int
GL_DEPTH_BUFFER_BIT: int
GL_STENCIL_BUFFER_BIT: intGL_DEPTH_TEST: int
GL_LIGHTING: int
GL_TEXTURE_2D: int
GL_BLEND: int
GL_CULL_FACE: int
GL_SCISSOR_TEST: intGL_MODELVIEW: int
GL_PROJECTION: int
GL_TEXTURE: intGL_BYTE: int
GL_UNSIGNED_BYTE: int
GL_SHORT: int
GL_UNSIGNED_SHORT: int
GL_INT: int
GL_UNSIGNED_INT: int
GL_FLOAT: int
GL_DOUBLE: intInstall with Tessl CLI
npx tessl i tessl/pypi-pyopengl