-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Mark Brooks edited this page Sep 7, 2025
·
3 revisions
# Install from source
git clone https://github.com/markxbrooks/picogl.git
cd picogl
pip install -e .
6.2.2 Your First PicoGL Program Let’s create a simple program that displays a colored cube:
from picogl.renderer import MeshData
from picogl.ui.backend.glut.window.object import RenderWindow
import numpy as np
def main():
# Define cube vertices (8 corners of a cube)
vertices = np.array([
# Front face
[-1, -1, 1], [ 1, -1, 1], [ 1, 1, 1], [-1, 1, 1],
# Back face
[-1, -1, -1], [-1, 1, -1], [ 1, 1, -1], [ 1, -1, -1],
# Top face
[-1, 1, -1], [-1, 1, 1], [ 1, 1, 1], [ 1, 1, -1],
# Bottom face
[-1, -1, -1], [ 1, -1, -1], [ 1, -1, 1], [-1, -1, 1],
# Right face
[ 1, -1, -1], [ 1, 1, -1], [ 1, 1, 1], [ 1, -1, 1],
# Left face
[-1, -1, -1], [-1, -1, 1], [-1, 1, 1], [-1, 1, -1]
], dtype=np.float32)
# Define colors for each vertex
colors = np.array([
# Front face (red)
[1, 0, 0], [1, 0, 0], [1, 0, 0], [1, 0, 0],
# Back face (green)
[0, 1, 0], [0, 1, 0], [0, 1, 0], [0, 1, 0],
# Top face (blue)
[0, 0, 1], [0, 0, 1], [0, 0, 1], [0, 0, 1],
# Bottom face (yellow)
[1, 1, 0], [1, 1, 0], [1, 1, 0], [1, 1, 0],
# Right face (magenta)
[1, 0, 1], [1, 0, 1], [1, 0, 1], [1, 0, 1],
# Left face (cyan)
[0, 1, 1], [0, 1, 1], [0, 1, 1], [0, 1, 1]
], dtype=np.float32)
# Create mesh data
data = MeshData.from_raw(vertices=vertices, colors=colors)
# Create render window
window = RenderWindow(
width=800,
height=600,
title="My First PicoGL Cube",
data=data
)
# Initialize and run
window.initialize()
window.run()
if __name__ == "__main__":
main()Save this code as my_first_cube.py and run it:
python my_first_cube.pyYou should see a window with a colorful cube that you can rotate with your mouse! 6.2.3 Understanding the Code Let’s break down what this code does:
- Import PicoGL modules: - MeshData: Container for vertex and color data - RenderWindow: Window for displaying 3D content
- Define vertices: 24 vertices defining 6 faces of a cube
- Define colors: One color per vertex
- Create mesh data: Combine vertices and colors into a mesh
- Create window: Set up the display window
- Run: Start the interactive display 6.2.4 Key Concepts
MeshData is the core data structure for objects:
data = MeshData.from_raw(
vertices=vertices, # 3D positions
colors=colors, # RGB colors
normals=normals, # Surface normals (optional)
uvs=uvs # Texture coordinates (optional)
)RenderWindow provides the display interface. It handles: • OpenGL context creation • Window management • User input (mouse, keyboard) • Rendering loop
window = RenderWindow(
width=800, # Window width
height=600, # Window height
title="My App", # Window title
data=mesh_data # Mesh to display
)