graphics-snippets

StackOverflow

“I’m a programmer. I like programming. And the best way I’ve found to have a positive impact on code is to write it.”
Robert C. Martin, Clean Architecture


Python examples

Python code snippets

Hello Triangle

Hello Triangle - GLUT
Hello Triangle - GLUT - OpenGL 4.1 core (macOS)
Hello Triangle - GLUT - immediate mode (legacy)
Hello Triangle - GLFW
Hello Triangle - GLFW - OpenGL 4.1 core (macOS)
Hello Triangle - GLFW - immediate mode (legacy)
Hello Triangle - Pygame
Hello Triangle - Pygame - OpenGL 4.1 core (macOS)
Hello Triangle - Pygame - immediate mode (legacy)
Hello Triangle - tkinter
Hello Triangle - tkinter - immediate mode (legacy)

Hello Cube

Hello Cube - GLUT
Hello Cube - GLUT - OpenGL 4.1 core (macOS)
Hello Cube - GLUT - immediate mode (legacy)
Hello Cube - GLFW
Hello Cube - GLFW - OpenGL 4.1 core (macOS)
Hello Cube - GLFW - immediate mode (legacy)
Hello Cube - Pygame
Hello Cube - Pygame - OpenGL 4.1 core (macOS)
Hello Cube - Pygame - immediate mode (legacy)
Hello Cube - tkinter
Hello Cube - tkinter - immediate mode (legacy)

Examples

Mesh

OpenGL 4.6, Direct State Access (DSA), Spir-V Shader Program
OpenGL 4.6, Direct State Access (DSA), Spir-V Shader Program

Mesh - glut
Mesh - glfw
Mesh

Mesh in Tkinter frame
Mesh

Instancing
Instancing

Visualizing a 3D NumPy array with PyOpenGL
Visualizing a 3D NumPy array with PyOpenGL

Draw elements

Geometry shader

Geometry
example/python/geometry_shader/geometry_001/geo.py
Geometry

Tessellation shader

Tessellation
example/python/tessellation_shader/tessellation_001/tess.py
Tessellation

Model, View and Projection

OpenGL 4.6, Python OpenGL 4.6, GLM navigation
OpenGL 4.6, Python OpenGL 4.6, GLM navigation

Text

OpenGL 4.6, Python OpenGL 4.6, freetype text
OpenGL 4.6, Python OpenGL 4.6, freetype text

Voxel

OpenGL 4.6, Python OpenGL 4.6, voxel ray tracing
OpenGL 4.6, Python OpenGL 4.6, voxel ray tracing

Shadow

Shadow
Shadow

Parallax

Parallax
Parallax

Relief mapping with geometry shader
Parallax

SSAO

no SSAO, diffuse light
fixed SSAO
kernel SSAO
No SSAO, diffuse light fixed SSAO kernel SSAO

2D shader

2D rounded rectangle
2D rounded rectangle

2D rounded rectangle with shadow
2D rounded rectangle with shadow

Ray marching shader

Ray marching - shapes

Minimal example

Debug Output

Texture

Cub Mesh (glut)

Cube Mesh (glfw)
Wood shader

Wood shader
Wood shader

Zoom

Pan cube 1
Pan cube 2

Wavefront (obj) - viewer
Wavefront (obj) - viewer

Compute shader

Shader 2D

Freetype - Hello world
Freetype - Hello World

Shared context

PyGame

See

Legacy OpenGL

Immediate mode and legacy OpenGL

Math

.obj to raw vertices converter with normals in python