Introduction

Learn how to program in 3D computer graphics in the Python programming language!

frustum1

Approach

You’ll learn how to place geometric objects in space, draw them relative to other geometric objects, position a camera in space which moves over time based on user input, and transform all those objects into the 2D pixel coordinates of your screen. By the end, you’ll understand the foundations of creating first-person and third-person applications or games. The goal? To empower you to build the graphics programs you want, using math you mostly already know.

This book intentionally keeps things simple intended for beginners. In this book, the applications created won’t be particularly pretty or realistic-looking. After reading this book, for more advanced topics, you’ll want to dive into other references, such as

  1. Fundamentals of Computer Graphics, Third Edition by Shirley and Marschner [SM09a]

  2. Computer Graphics With OpenGL, by Hearn Baker and Carithers [HBC11a]

  3. LearnOpenGL

  4. OpenGLTutorial

  5. Computer Graphics From Scratch

  6. Learning Modern 3D Graphics Programming (2012)

  7. OGLdev

Things You Should Know

  1. Basic programming concepts in Python.

    1. YouTube videos

      1. Learn Python with Socratica

      2. Microsoft Python Tutorials

    2. Books

      1. https://diveintopython3.net/

  2. High school Geometry

    1. [CHK+12]

Required Software

You will need to install Python, and make a virtual environment. You can search how to do this using a search engine, or AI Chatbot, or follow the instructions below.

Windows

On Windows, install Visual Studio and the Python extension. Afterwards, to set up the virtual environment, open the Developer Command Prompt,

python -m venv venv
cd venv\Scripts
activate.bat
cd ..\..\
python -m pip install --upgrade pip setuptools
python -m pip install -e .

The book assumes that you’ll use the Spyder Integrated Development Environment (IDE), to install Spyder

python -m pip install spyder

To run the Spyder Integrated Development Environment (IDE) to execute the code in the book, open Spyder on the Developer Command Prompt

cd venv\Scripts
activate.bat
cd ..\..\
spyder -p .

Linux

Install Python3, glfw via a package manager. Use pip and virtualenv to install dependencies

To set up the environment in a terminal, execute

python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip setuptools
python3 -m pip install -e .

The book assumes that you’ll use the Spyder Integrated Development Environment (IDE), to install Spyder

python -m pip install spyder

To run the Spyder IDE to execute the code in the book, open Spyder on the developer command prompt

source venv/bin/activate
spyder -p .

Mac

Install Python3 (via anaconda, homebrew, macports, whatever), and use pip and virtualenv to install dependencies.

On MacOS, to set up the environment in a terminal, execute

python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip setuptools
python3 -m pip install -e .

The book assumes that you’ll use the Spyder Integrated Development Environment (IDE), to install Spyder

python -m pip install spyder

To run the Spyder IDE to execute the code in the book, open Spyder on the developer command prompt

source venv/bin/activate
spyder -p .

Podman Container

The code is mainly tested against a container in Podman, specified in the Dockerfile.

Command Line

To run the code from the command line, run the following to create the podman image

make image

Once that is made, you can run the image in a container by running

make shell # get a shell into the environment

Spyder

To create the podman image for running the code in Spyder:

make spyderimage # make the OCI image that has the base image and Spyder IDE preinstalled

To run Spyder within the container

make spyder # run spyder in the OCI container

Jupyter Notebook

To run Python code as jupyter notebooks, the following command will launch jupyter and a firefox web browser from within the container.

Make the image

make image

Run Jupyter notebook

make jupyter # run jupyter notebook in a container

Getting the Source code

This book references source code, which is at https://github.com/billsix/modelviewprojection

This documentation was generated from from commit e4deead2580dc35650a150c40895798d7973094e