Course: Computer Graphics
Institution: National Taipei University of Technology (NTUT / 臺北科技大學)
Academic Year: 113 (2024-2025)
This repository contains lab assignments for the Computer Graphics course, implementing various OpenGL rendering techniques and algorithms.
Fundamental 3D graphics exercise implementing cube transformations:
- Custom rotation, translation, and scaling matrices implementation
- Arbitrary axis rotation using user-defined vectors
- Orbital animation around custom axes
- Colored cube rendering with six distinct faces
- Interactive keyboard controls for real-time transformations
- XYZ coordinate axes visualization
- gluLookAt camera setup for 3D viewing
A fundamental 2D graphics exercise implementing an interactive grid system with:
- Dynamic grid rendering with adjustable dimensions (10×10, 13×13, 15×15)
- Mouse click detection for selecting and filling grid cells
- Right-click context menu for dimension switching
- Coordinate system transformation between window and OpenGL coordinates
A comprehensive 3D model viewer application featuring:
- OBJ file parsing and rendering (supports multiple models: teddy, gourd, octahedron, teapot)
- Multiple rendering modes (wireframe, solid, etc.)
- Complete camera control system (pan, rotate, zoom)
- Model transformation controls (rotate, translate)
- Automatic bounding box calculation and model fitting
- 3D vector math utilities for graphics operations
Implementation of the Midpoint Line Algorithm for line rasterization:
- Support for all eight octants (0° - 360°)
- Region-based color coding for different line slopes
- Visual demonstration of pixel selection during line drawing
- Interactive point selection via mouse clicks
Polygon rasterization using the Half-Space (Edge Function) Method:
- Interactive polygon vertex input
- Inside/outside testing using cross product (edge functions)
- Visual representation of filled polygons with color coding
- Extension of the midpoint line algorithm for polygon boundaries
Enhanced polygon filling with real-time animation:
- Timer-based animation for visualizing the fill process
- Step-by-step cell filling demonstration
- Improved understanding of rasterization algorithms
- Interactive polygon creation with animated results
Implementation of the Scanline Fill Algorithm with advanced features:
- Edge Table (ET) and Active Edge Table (AET) construction
- Gradient color filling based on X/Y position (red-green horizontal, blue-yellow vertical)
- Animated scanline visualization with step-by-step filling
- Extreme point highlighting (gold color) for each scanline
- Proper handling of horizontal edges and edge intersections
- Support for arbitrary convex/concave polygon input
- Interactive polygon creation with mouse clicks
3D sphere rendering using icosahedron subdivision:
- Recursive triangle subdivision for smooth sphere approximation
- Adjustable subdivision levels (0-5) with +/- keys
- Three viewport display: Flat Shading | Smooth Shading | Subdivided
- Right-click menu for wireframe/fill mode switching
- OpenGL lighting and material configuration
- Arrow keys for interactive model rotation
Implementation of planar shadow mapping technique:
- 3D jet aircraft model with detailed geometry (nose, body, wings, tail)
- Shadow matrix calculation based on light position and ground plane
- Four switchable light positions (keys 1-4 or F1-F4)
- Green gradient ground plane for depth perception
- Real-time jet rotation with arrow keys
- Yellow sphere indicator for current light position
- Custom 3D math library (vectors, matrices, plane equations)
Advanced 3D scene with texture mapping and planar shadows:
- TGA texture loading (grass ground, wood, orb textures)
- Animated 3D robot character with hierarchical transformations
- Articulated limb animation (arms and legs swing with sine wave)
- Orbiting textured sphere around the robot
- Planar shadow projection using shadow matrix
- Stencil buffer for proper shadow rendering (semi-transparent shadows)
- Camera movement controls (GLFrame with arrow keys)
- Real-time animation with timer functions (33ms interval)
- Pause/resume animation with 'P' key
Comprehensive 3D model loading and rendering system:
- OBJ file parsing for complex 3D models (Viper, castle, fish, human, whale, etc.)
- OpenCV-based texture loading (JPG/PNG format support)
- Multiple texture types (background, cartoon water, galaxy, grid, orange skin)
- GLU tessellator for non-triangular polygon faces
- Normal and UV coordinate handling from OBJ files
- Dynamic model and texture file discovery from folders
- Shadow projection for loaded models
| Dependency | Description |
|---|---|
| OpenGL | Core graphics library (pre-installed on macOS) |
| FreeGLUT | OpenGL Utility Toolkit for window management |
Install FreeGLUT via Homebrew:
brew install freeglutgcc lab2.cpp -o lab2 -I/opt/homebrew/include -L/opt/homebrew/lib -lglut -framework OpenGL./lab2opengl_lab/
├── README.md
├── lab1.cpp # 3D Cube Transformations & Orbital Motion
├── lab2.cpp # Interactive Grid System
├── lab3_mid.cpp # 3D OBJ Model Viewer (Mid-term)
├── lab4.cpp # Midpoint Line Algorithm
├── lab5.cpp # Half-Space Polygon Fill
├── lab6.cpp # Animated Polygon Fill
├── lab7.cpp # Scanline Polygon Fill Algorithm
├── lab8.cpp # Icosahedron Sphere Subdivision
├── lab9.cpp # Planar Shadow Projection (Jet)
├── lab10/
│ ├── lab10.cpp # Textured Robot Scene with Shadows
│ ├── grass.tga # Ground texture
│ ├── wood.tga # Wood texture
│ └── orb.tga # Sphere texture
└── lab11_final/
├── lab11.cpp # OBJ Model Loader
├── model/
│ ├── Viper.obj # Spaceship model
│ ├── castle.obj # Castle model
│ ├── fish.obj # Fish model
│ ├── human1.obj # Human model 1
│ ├── human2.obj # Human model 2
│ ├── human3.obj # Human model 3
│ ├── whale.obj # Whale model
│ └── ... # Other OBJ models
└── texture/
├── background.jpg
├── cartoon_water_blue.jpg
├── galaxy_blue_red.jpg
└── ... # Other textures
| Key | Action |
|---|---|
W/A/S/D |
Model/Object rotation |
Q/E |
Z-axis rotation |
I/J/K/L |
Model translation |
+/- |
Zoom in/out |
Arrow Keys |
Camera/View rotation |
ESC |
Exit program |
Right-click |
Context menu (where applicable) |
- 2D/3D Coordinate Systems
- Rasterization Algorithms (Line, Polygon)
- Geometric Transformations (Translation, Rotation, Scaling)
- 3D Model Loading and Rendering
- Camera and View Transformations
- Lighting and Shading
- Texture Mapping
- Shadow Techniques
- Tessellation and Subdivision Surfaces
This repository is for educational purposes as part of the NTUT Computer Graphics course curriculum.