Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Andrea-Oliveri/OpenGL-TileMap-Demos-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenGL-TileMap-Demos-Python

Project Overview

This repository offers a port into Python of some renderers from davudk/OpenGL-TileMap-Demos, originally written in C#.

As a result, it provides Python code to render a tilemap much faster than what would be possible with immediate rendering.

Vertex-buffered rendering and Geometry Shader Rendering in particular are implemented in src/renderer.py

Vertex-buffered rendering is implemented both using native OpenGL calls and using Pyglet's ShaderProgram class.

Topline Profiler Results

On a simple benchmark with a TileMap composed of 36 rows and 28 columns, the following results were obtained. Reported are the cumulative time, per call, in seconds:

Renderer draw() recalculate()
Geometry Shader 0.0002031 0.0001807
Vertex-Buffered 0.0001621 0.006053
Vertex-Buffered (Pyglet) 0.0004581 0.003455
Instantaneous 0.2491 0

References

For more detailed explainations on each renderer, please refer to the original repository davudk/OpenGL-TileMap-Demos.

To learn more about OpenGL and shaders, I found very helpful Learn OpenGL.

To learn more about Pyglet, please reference their documentation and their Github repository.

Repository Structure

This directory contains the following files and directories:

  • main.py: Main Python script used to run the app.
  • src: Directory collecting all additional Python scripts and custom packages needed to run the app.
  • Assets: Directory containing the image atlas used in this demo.
  • Shaders: Directory containing the GLSL code for the different shader implementations.
  • README.md: The Readme file you are currently reading.

Getting Started

0) Python Environment

The Python enviroment used for this project was kept as simple as possible.

An environment containing the required packages with compatible versions can be created as follows:

conda create -n tilemap_demo python=3.12.0
conda activate tilemap_demo
pip install pyglet==2.0.8 snakeviz==2.2.0

1) Run

To run the demo app, simply activate the correct conda environment and, from the same directory as the main.py file run:

python main.py

Use the whitespace key to toggle between the different types of renderers. Use any other key to randomly generate a new tilemap.

2) Visualize profile results

cProfile is used to generate a performance dump each time the application is run. This allows to compare the speed of the different rendering techniques. Note that the time needed by Pyglet to draw the FPS on screen may represent a sizeable portion of the rendering time and is therefore advised to remove the FPS counter when benchmarking your implementations.

To visualize the results in the profiler dump, run:

snakeviz "Profiler Results {...}.prof"

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published