Skip to main content

3D Game Engine with software rendering written in Python

Project description

Logo

Welcome to Retro3D!

Retro3D is a 3D game engine written in Python. All of the rendering is done in code (as opposed to using your 3d video card).

To use this library, you will need to have Python installed on your machine. The project was built using Python 3.10.10

You will also need to have pip installed. I did it on Windows like this:

Two ways to use Retro3D

  1. Install the library using
    pip install Retro3d

  2. Clone/Download the project from
    https://github.com/deepakbr14/Retro3D
    and add it to your project/solution.

    Make sure to install its requirements:

    • terminal to the Retro3D directory that has the file requirements.txt
    • pip install -r requirements.txt

Sample Project : HelloRetro3D

https://github.com/deepakbr14/HelloRetro3D
This is the simplest form of a project using Retro3d.
It just shows a rotating cube. Hello World

Sample Project : Combat

https://github.com/deepakbr14/Combat
This is basic clone of the arcade game BattleZone. This game will show you how to handle camera rotation, model loading, sound, music, player input, and 2D HUD graphics. Retro3D uses pygame for functionality like drawing, sound, etc. Combat https://youtu.be/kFMuBot71Jg

How to step through Retro3D Engine Code

I've built Retro3D using Microsoft Visual Studio Community 2019.
My Visual Studio Solution looked like this:

  • Solution
    • Combat
    • Retro3d

I added the Retro3d.pyproj (python project) as a reference.

Easy Game Development

The 'game engine' part of Retro3D is there so you can get your
game up and running quickly.

The game title, instructions, and credits are all auto-generated
based on the contents of your ConfigGame object.

For example, when you do this

config = ConfigGame()

config.screen_resolution = pg.math.Vector2(1024, 768)
config.title = "Combat";
config.author = "Deepak Deo"
config.year = "1977"

the game engine automatically creates a window (1024x768) and shows the title and author on the cover screen. Cover

You can also easily add instructions... Instructions

and game credits. Credits

Future Changes

3D Engine
  • engine optimizations
  • better inline documentation of 3d engine math
  • autoreflections - just the geometry upside down
  • some form of very cheap shadows
  • Have not yet passed the teapot test..
  • Display lists should hold tris, not objs for better optimization + variety of rendering types within a single object (i.e. solid + transparent, etc)
  • Need proper clipping. should be adding vertices to show part of the poly. use z buffer to hide 'behind' polys engine still needs to handle object draw ordering
  • Use .mtl file along with .obj so that the obj files can have color per face info also, need to use 'materials' so that we can color objs on top of what the .obj file specifies. right now it's just one color per object
  • Support multiple lights, multiple light types (i.e. point), and light color
  • Optimize by use njit properly https://numba.readthedocs.io/en/stable/user/performance-tips.html
  • Optimize draw_normals method
  • Optimize Matrix class: should have pre-multipled matrix methods: ie zxyt
  • The core pipeline is shit: not using python for single line list processing as i should copying and recopying vert_lists/matrices when dealing with vertex transformation normals transformation is even worse! math could use some streamlining
  • Draw vertices with flag (like normals) self.draw_vertices = False if obj.draw_vertices: for vertex in list_vertex: pg.draw.circle(self.screen, pg.Color('white'), vertex, 6)
  • Shaded outline shouldn't show the diagonal line of the tri maybe precalc which line is the longest and flag it

##### Game Engine * Upgrade rez system. Maybe break out sound into a proper sound engine. * Create a high score system that auto stores on line. Develoepr should just have to say type of score. * support for full screen mode. see https://www.delftstack.com/howto/python-pygame/set-window-to-fullscreen-in-pygame/ * need safety code for model loading. assuming just tris right now. * formal font system. just drop in a folder and use. art and sound should be just as easy. * Formal input system. Support mouse input for Game * Use texture sheets
##### Common * Make code more 'pythonic' * Need simpler/cleaner way of doing imports * Abstract out pygame stuff or use directly? i.e. font system, image loading with error checking same for python standard lib and si code. * 'dsd's in code
##### Community * Instructions on how others can contribute to the project. * how do others tell me/us what new features they want or what bugs they find? * Formal page on retro3D.org or something like that. Have documentation of Engine functions and tutorials. And some youTube vids! And some place to converse about using this thing. Don't forget to udpate url in setup.py and links in this readme file. * Make some more sample games: - Fighter Jet - Racing - Space Battle - Tron - Fractal Terrain Flyer
##### Cosmetic Changes * Want a cheesy 80s/90s style 3d game engine intro. see https://youtu.be/DIMlll1gOWQ?t=31 * Make the Cover/Instructions/Credits look less-shitty :/



Change Log


1.0 (Jan 11, 2023)

  • First Release

1.1 (Jan 11, 2023)

  • Reorg

1.2 (Jan 12, 2023)

  • Another reorg

1.3 (Jan 12, 2023)

  • Added game config

1.4 (Jan 12, 2023)

  • Added BackgroundInfo to support from flat to mutli-part-gradient backgrounds

1.5 (Jan 12, 2023)

  • Support for hud drawing
  • Added a shaded outline draw list

1.6 (Jan 17, 2023)

  • Added safety check to Engine.__calc_face_color by making sure dot product parameter is in valid range

1.7 (Jan 18, 2023)

  • Fixed issue of vertices that were behind the camera were being drawn
  • Fixed normals - which was causing a dot product miscalc

2.7 (Mar 31, 2023)

  • Project reorg to work better with Pypi
  • Built separate sample projects: HelloWorld and Combat.
  • Added requirements.txt
  • Setup rez system for fonts/images/sounds
  • Dumped some Si functions in favor of pygame functions
  • Added cover/instruction/credits system
  • Fixed 3d math bugs





Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Retro3D-2.7.tar.gz (38.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page