Algorithmic Generation of OpenGL Geometry
Presented by Jonathan Hartley
Starting from a basic 'hello world' OpenGL app, a simple and Pythonic model of 3D polyhedra is presented, with neat generators to convert these into ctype arrays for OpenGL. Geometric algorithms then generate some fun geometry, and these are compounded to produce successively more complex and interesting shapes.
The author's intent is to demonstrate that effective stylistic 3D graphics can be achieved using surprisingly small amounts of code. This hopefully makes the topic amenable to 3D beginners, while possibly suggesting some alternative approaches to those with 3D experience.
Throughout, discussion of ideas and code dissection alternates with live animated demos, at 60fps on very modest hardware.
- Inspirations - Effective non-photo-realistic work in gaming, movies and the demo scene. (1m)
- A convenient & Pythonic way to model 3D polyhedra, and some neat generators to convert these into OpenGL arrays at runtime. (7m)
- Composition of polyhedra to create more complex shapes. (3m)
- The resulting performance characteristics: What works well from Python, and what doesn't. (2m)
- Koch tetrahedron & tetrix, aka Sierpinski tetrahedron. (1m)
- Surprisingly effective 3D models created from small bitmaps. (1m)
- Automatic generation of trees, mazes, complex spaces. (3m)
- Algorithmic modification of existing shapes, such as bevels, geometric duals, and polyhedron stellation. (2m)
- Shapes that morph: Rearranging vertices on the fly (5m)
- Questions (5m)
The ideas demonstrated in the talk are written against OpenGL 2.1, but written in a 'mostly OpenGL 3' style, using vertex buffer objects or vertex arrays.
The demo code uses pyglet to create a window and handle GUI events, and uses PyOpenGL for the majority of OpenGL calls, since it provides a more friendly and Pythonic interface. In the performance-sensitive inner render loop, however, I use pyglet's slightly more bare-bones OpenGL bindings.
However, the majority of the talk focuses on the manipulation of abstract data structures to represent geometry, which is not affected by these or other OpenGL library choices.
This is a substantially improved version of the talk 'Flying High: Hobbyist OpenGL from Python', previously presented at EuroPython 2010.