Skip to content

A framework for rendering 3D computer graphics with Python. Created as educational material for a Software Engineering Lab course: https://robsonger.dev/software-engineering-lab/

License

Notifications You must be signed in to change notification settings

rsonger/pycg-framework

Repository files navigation

Issues AFL License

PyCG Framework

A framework for rendering 3D computer graphics with Python.

Try It · Report Bug · Request Feature

Screenshot

Table of Contents

  1. About the Project
  2. Getting Started
  3. Usage
  4. License
  5. Contact
  6. References

About The Project

This 3D CG graphics framework was created using Python for the purposes of teaching Computer Graphics and Software Engineering through the object-oriented design and application of a CG rendering library. The framework is largely inspired by the one developed by Lee Stemkoski and Michael Pascale (see References) with a focus on cross-compatibility, object-oriented software design principles, and the use of pythonic conventions over the ones commonly used with OpenGL.

For more information on the course and the companion material that uses this framework, see the Software Engineering Lab website and the posts there.

Built With

  • Python
  • Pygame
  • PyOpenGL

Getting Started

The following instructions describe how to create a local copy of the framework and configure it to run in a virtual environment.

Prerequisites

This project requires Python 3.8+ and it is recommended to use a virtual environment for installing all the dependencies. Either venv or Pipenv work fine.

Installation

  1. Clone the repo.
    git clone https://github.com/rsonger/pycg-framework.git
  2. Create a virtual environment.
    venv
    python -m venv .venv
    Pipenv
    pipenv install
  3. Activate the virtual environment.
    venv
    # Windows
    source .venv/Scripts/activate
    # MacOS
    source .venv/bin/activate
    Pipenv
    pipenv shell
  4. In venv, the packages need to be installed after activating the environment.
    pip install -r requirements.txt
  5. On MacOS, a discrepency in the OpenGL package may result in an ImportError. You can test this by running the following command in the terminal:
    python -c "import OpenGL.GL"
    If you see the error, look at the Traceback and find the location of the site-packages\OpenGL\platform directory inside your Python library. Open the ctypesloader.py file from that directory and find the line that has:
    fullName = util.find_library( name )
    Then change the line to:
    fullName = f"/System/Library/Frameworks/{name}.framework/{name}"

Usage

The WindowApp class in the graphics.core.app module contains all the basic logic for setting up a rendering context inside a windowed application. It implements the typical lifecycle of an interactive rendering application as shown in the flowchart below. An application using the framework should extend the WindowApp class and implement its startup and update methods as exemplified by the program in demo.py.

Application lifecycle

Run the demo app with python demo.py to see the scene depicted in the screenshot from above. The demo also makes use of CameraRig from graphics.extras.camera_rig which allows the user to move through the scene and look. The keys WASD move the camera forward, left, back, and right while Q and E move it down and up. The keys IJKL rotate the camera to look up, left, down, and right.

Roadmap

License

Distributed under the Academic Free License. See LICENSE.txt for more information.

Contact

Rob Songer

Website

Project Link: https://github.com/rsonger/pycg-framework

References

  • Lee Stemkoski and Michael Pascale (2021). Developing Graphics Frameworks with Python and OpenGL. CRC Press, in print and online. DOI: 10.1201/9781003181378

About

A framework for rendering 3D computer graphics with Python. Created as educational material for a Software Engineering Lab course: https://robsonger.dev/software-engineering-lab/

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages