SCOP is a GPU-based 3D object renderer developed as part of the 42 Network / 1337 advanced curriculum. This project serves as an introduction to GPU rendering using OpenGL (via the Glium library in Rust). It parses .obj files, renders 3D models with perspective projection, and supports texture mapping with smooth transitions.
- Parse and render 3D objects from
.objfiles - Implement perspective projection for realistic 3D visualization
- Auto-rotate the object around its center of mass
- Support movement along all three axes (X, Y, Z)
- Apply textures with smooth transition effects
- Generate per-face colors for visual distinction
- Implement custom matrix mathematics (no external math libraries)
| Feature | Description |
|---|---|
| OBJ Parser | Custom parser for Wavefront .obj files with support for vertices (v) and faces (f) |
| Fan Triangulation | Converts n-gon polygons to triangles for GPU rendering |
| Perspective Projection | Proper 3D perspective with configurable FOV, near/far planes |
| Look-At Camera | View matrix implementation with camera positioning |
| Auto-Rotation | Continuous rotation around the object's center of symmetry |
| Axis Switching | Smooth animated transitions between rotation axes (X, Y, Z) |
| Texture Mapping | PPM texture loading with UV coordinate generation |
| Smooth Transitions | Lerp-based transitions between colored and textured modes |
- Box Projection: UV mapping based on dominant axis direction
- Spherical Projection: Longitude/latitude based UV mapping for spherical objects
| Component | Technology |
|---|---|
| Language | Rust (Edition 2024) |
| Graphics API | OpenGL (via Glium) |
| Windowing | Winit (cross-platform) |
| Shader Language | GLSL 1.40 |
scop/
โโโ Cargo.toml # Rust package manifest
โโโ Makefile # Build automation (42 standard)
โโโ README.md # This file
โโโ src/
โโโ main.rs # Application entry, rendering loop, shaders
โโโ obj_parcer.rs # OBJ file parser and texture loader
- Rust toolchain (stable)
- OpenGL compatible GPU
# Using Makefile (42 standard)
make
# Or using Cargo directly
cargo build --releasemake clean # Remove build artifacts
make fclean # Full clean including binary
make re # Rebuild from scratch./target/release/scop <obj_path> <texture_path> <uv_algorithm>| Argument | Description |
|---|---|
obj_path |
Path to the .obj file to render |
texture_path |
Path to the .ppm texture file |
uv_algorithm |
UV mapping method: box or sphere |
./target/release/scop models/42.obj textures/ponies.ppm box| Key | Action |
|---|---|
Q |
Toggle texture/color mode (smooth transition) |
T |
Toggle dynamic color animation ("lizard mode") |
W |
Switch to X-axis rotation |
E |
Switch to Y-axis rotation |
R |
Switch to Z-axis rotation |
Y |
Reverse rotation direction |
A / Z |
Move along X-axis (+/-) |
S / X |
Move along Y-axis (+/-) |
D / C |
Move along Z-axis (+/-) |
All matrix operations are implemented from scratch without external math libraries:
- Perspective Projection Matrix: Standard OpenGL perspective with configurable FOV
- View Matrix (Look-At): Camera positioning using forward, right, and up vectors
- Rotation Matrices: Separate X, Y, Z rotation with column-major layout
- Matrix Multiplication: Column-major 4x4 matrix multiplication
#version 140
// Transforms vertices through Model-View-Projection pipeline
// Generates per-face colors from uniform buffer
// Centers object using bounding box calculation#version 140
// Blends between solid color and texture based on lerp value
// Supports smooth transitions between rendering modes- Vertex position parsing (
v x y z) - Face parsing with n-gon support (
f v1 v2 v3 ...) - Face indices with vertex/texture/normal format (
f v/vt/vn) - Bounding box calculation for object centering
- Automatic fan triangulation for polygons with 3+ vertices
- Binary PPM (P6) format support
- Header parsing (magic number, dimensions, max value)
- Raw RGB data loading
OBJ File โ Parser โ Vertices/Indices โ Vertex Buffer
โ
PPM File โ Texture Loader โ Texture2D โ Fragment Shader
โ
Uniforms (Matrices, Colors) โ Shaders โ Framebuffer โ Display
The renderer uses a uniform buffer with 5 colors for per-face coloring:
- Colors are assigned cyclically to triangles (
(gl_VertexID / 3) % 5) - "Lizard mode" creates dynamic animated colors using cosine waves
- Smooth interpolation between color and texture modes
- โ No external libraries for matrix operations
- โ No external libraries for OBJ parsing
- โ No external libraries for shader loading
- โ Custom perspective projection implementation
- โ Classic Makefile provided
- OBJ files: Standard Wavefront format with
v(vertices) andf(faces) - Textures: PPM format (P6 binary) required
[dependencies]
glium = { git = "https://github.com/glium/glium.git" }Glium provides:
- OpenGL context creation
- Window management (via Winit)
- Safe OpenGL bindings
- Shader compilation and management
This project is part of the 42 Network curriculum.
Developed as part of the 42 Network / 1337 Advanced Curriculum