Pure 3D Rendering with Pygame (No OpenGL) β A simple and efficient library for 3D graphics from scratch
- π Fully written in Python (no OpenGL dependencies)
- π¨ Simple API for quick 3D graphics development
- π¦ Core 3D primitives support (starting with triangles)
- π Built-in transformations (rotation, translation)
- ποΈ Flexible object appearance customization
- ποΈβπ¨οΈ Camera with perspective projection
- Ensure you have Python 3.7+ installed
- Install requirements:
pip install -r requirements.txt
- Clone the repository or add the
corelibs
files to your project
import pygame
from corelibs import core
from corelibs.transformations import Vector3
# Initialization
pygame.init()
screen = pygame.display.set_mode((800, 600))
camera = core.Camera(Vector3(0, 0, -5), 60)
# Create a 3D triangle
triangle = core.Triangle(
Vector3(-1, -1, 0),
Vector3(1, -1, 0),
Vector3(0, 1, 0)
)
# Configure appearance
triangle.configure(
shaded=True, # Enable shading
color=(255, 0, 0), # Red color
outlinded=True, # Enable outline
outline_color=(255, 255, 255) # White outline
)
# Main loop
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
screen.fill((0, 0, 0)) # Clear screen
# Rotate and render
triangle.rotate(Vector3(0, 0.01, 0))
triangle.draw(screen, camera)
pygame.display.flip()
pygame.time.Clock().tick(60)
pygame.quit()
Creates a 3D triangle with specified vertices.
Parameters:
v1
,v2
,v3
: Triangle vertices in 3D space
Configures the triangle's appearance.
Parameters:
shaded
: Enable/disable shadingcolor
: Fill color (RGB)outlinded
: Enable/disable outlineoutline_color
: Outline color (RGB)
Rotates the triangle around axes.
Parameters:
angle_vector
: Rotation angles for X, Y, Z axes
Renders the triangle on screen.
Parameters:
screen
: Pygame surface for renderingcamera
: Camera for projection
Creates a camera for 3D scenes.
Parameters:
position
: Camera position in 3D spacefov
: Field of view (in degrees)
# Create 12 triangles (2 per cube face)
# ... cube creation code ...
# In the main loop:
for triangle in cube_triangles:
triangle.rotate(Vector3(0.01, 0.02, 0.005))
triangle.draw(screen, camera)
camera.position.z += 0.1 # Zoom in
camera.position.y -= 0.1 # Move up
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License.
Triangle.py (Latest)
Vertices coordinates
outdated/cubeshaded.py
outdated/render_q.py
outdated/main.py