Skip to main content

A simple rendering engine with some game engine features made with OpenGL for Python

Reason this release was yanked:

Bug

Project description

Grafyte

Grafyte is a lightweight and simple 2D game engine written in C++ with OpenGL and exposed to Python using pybind11. It aims to provide a fast and easy-to-use interface for creating 2D games and interactive applications.

Features

  • Simple API: Designed for ease of use with a straightforward Pythonic interface.
  • Fast Rendering: Core engine written in C++ utilizing OpenGL.
  • 2D Sprites: Support for textures and colored objects.
  • Text Rendering: Easy text display with scale and color control.
  • Simple Collision System: Integrated AABB-based collision detection with automatic resolution.
  • Input Management: Easy-to-use action-based input system with support for keyboard triggers (Press, Hold, Release).
  • Scene-based Workflow: Manage game objects within scenes.

Installation

To install grafyte , simply run the following command in your terminal:

python -m pip install grafyte

Building from Source

Prerequisites

  • Python 3.10+
  • A C++ compiler (MSVC, GCC, or Clang)
  • CMake
  • OpenGL drivers

[!NOTE] When applicable please make sure to test your code on both windows and linux as well as on Python 3.10 to 3.14 if possible.

Build

To set up the development environment and build Grafyte:

Windows:

scripts\setup.bat
.\.venv\Scripts\activate
pip install .

Linux:

chmod +x scripts/setup.sh
./scripts/setup.sh
source .venv/bin/activate
pip install .

Finally, you can build the python extension using CMake:

mkdir build
cd build
cmake ..
cmake --build .

Quick Start

Here's a minimal example to get you started:

import grafyte
from grafyte import Key, InputTrigger

# Initialize application
app = grafyte.Application("My Game", (800, 600))
scene = app.make_new_scene()

# Create a player object
player = scene.spawn_object((0, 0), (50, 50))
player.set_color((0, 255, 0), 1.0) # Green color

# Register an action
app.create_input_action("move_right", Key.D, InputTrigger.Hold)

while not app.should_close():
    dt = app.get_delta_time()
    
    # Handle input
    if app.is_action_active("move_right"):
        player.move((100 * dt, 0))
    
    # Render scene
    app.render()

app.quit()

Demo

Here is another exemple of a game made using only grafyte: grafyte demo

API Overview

Application

The main entry point for the engine.

  • render(): Draw the current frame.
  • should_close(): Returns True if the window should close.
  • get_delta_time(): Get time since last frame.
  • create_input_action(name, key, trigger): Map a key to a named action.

Scene

Manages game objects.

  • spawn_object(pos, size, z_index=0, has_texture=False): Create a new sprite.
  • spawn_text_object(pos, text): Create a text object.

Object

A 2D entity in the game.

  • move(offset): Relative movement.
  • move_to(position): Absolute movement.
  • set_color(rgba, alpha): Set object color.
  • use_texture(path, slot): Load and use a texture.
  • add_collision_box(pos, size): Add collision properties.
  • is_colliding(): Check for collisions.

License

Grafyte is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

grafyte-0.3.0-py3-none-win_amd64.whl (5.7 MB view details)

Uploaded Python 3Windows x86-64

grafyte-0.3.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (7.7 MB view details)

Uploaded Python 3manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file grafyte-0.3.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: grafyte-0.3.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.7 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for grafyte-0.3.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 96f3ce330b580338b73c5bbd54892864cfbe57dbdc4f627bbd5a0ae2ede9172f
MD5 6dc8fb6e783df007847d60e524c68e1a
BLAKE2b-256 dbe43189612985b2971773e4781e020908fd30a73fba3c95ff3e85f80c2c3ee7

See more details on using hashes here.

File details

Details for the file grafyte-0.3.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for grafyte-0.3.0-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2a6faa5f5a72a0043c5a50a71e4e2cc6c857a008f69f5807124195e73e148ede
MD5 ebe649a41a2852d2313bc6b840518ea1
BLAKE2b-256 29e7e6d189fa0ce55079c53213eb505ebc236681ec245980e1b844dd4370422f

See more details on using hashes here.

Supported by

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