Python OpenGL Tutorials

I recently started writing Pythons versions of the C++ code from OpenGL-Tutorials.org. You can find my code at my Github [here]. 99% of the source comments are from the original tutorials, the other 1% cover Python-specific content and any modifications I had to make to replace C++-only libraries.

The Python source code mimics the original C++ source with a few tweaks to accomodate missing libraries. For instance, at the time of this writing the Python glew wrapper is almost 10 years old and does not play well with Python 3.4.

The original tutorials will also be rewritten for Python (with the original author's permission) but that process is time consuming and I want to get the code out early. By and large the changes are minimal.

Requirements

  1. Python 3.X [download]
  2. PyOpengl && PyOpenGL_Accelerate: pip install pyopengl pyopengl_accelerate
  3. Pillow (a Python Image Library (PIL) fork): pip install pillow
  4. pyglfw (a glfw wrapper)
    • Download pyglfw, unpack, and run python setup.py install
    • Download glfw binaries for your OS.
    • Linux users: You should be all set after installation.
    • Windows users: Copy the glfw binaries in the tutorials folder or modify pyglfw.py to use Windows paths, by default pyglfw.py is set to common Linux paths.

Replacements

A few of the original C++ tutorials contain references to libraries that don't have Python equivalents or the equivalent libraries were beyond the scope of a simple tutorial. Here is a quick table showing what has been replaced:

glm --> cgsl
glew --> glew_wish
obj loader --> objloader.py

  • cgsl: Curiously simple graphics library (CSGL) is a hacky little bit of code I threw together to mimic GLM from the original C++ tutorials. Given more time I may go back and do a proper port. The idea with CSGL was to avoid using complex modules like Numpy that are beyond the scope of these tutorials.
  • glew_wish: Very much a tongue in cheek kludge to support GLEW's function querying. GLEW is rarely used in the beginner tutorials so this code was never finished. It will handle the basics and the reason can take it as an exercise to finish what I started or do a proper GLEW port. In a perfect world I would do something similar to pyglfw like wrapping the GLEW binaries.
  • objloader.py: The original C++ code creates its own Wavefront OBJ loader that supports a very specific output format from Blender. I copied the original tutorials exactly, meaning you need both UVs and Normals in your Blender output or objloader.py won't know what to do.

Completed Conversions

  • Basic OpenGL
    • Tutorial 1 : Opening a window [source]
    • Tutorial 2 : The first triangle [source]
    • Tutorial 3 : Matrices [source]
    • Tutorial 4 : A Colored Cube [source]
    • Tutorial 5 : A Textured Cube [source]
    • Tutorial 6 : Keyboard and Mouse [source]
    • Tutorial 7 : Model loading [source]
    • Tutorial 8 : Basic shading [source]
  • Intermediate Tutorials
    • Tutorial 9 : VBO Indexing [source]

Ongoing Conversions

  • Intermediate Tutorials
    • Tutorial 10 : Transparency
    • Tutorial 11 : 2D text
    • Tutorial 12 : OpenGL Extensions
    • Tutorial 13 : Normal Mapping
    • Tutorial 14 : Render To Texture
    • Tutorial 15 : Lightmaps
    • Tutorial 16 : Shadow mapping
    • Tutorial 17 : Rotations
    • Tutorial 18 : Billboards & Particles

License(s)

Original

WTFPL Public License Version 2*

*Note: WTFPL contains unprofessional language and after some deliberation I've decided not to include it here. Initially I released my code under WTFPL but I've decided to move to the MIT license.

Current

The MIT License (MIT)

Copyright (c) 2014 Jeremy Carson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View Comments