Skip to content

ez945y/opengl_lab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenGL Computer Graphics Labs

📚 Course Information

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.


🧪 Lab Descriptions

Lab 1 - 3D Cube Transformations & Orbital Motion

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

Lab 2 - Interactive Grid System

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

Lab 3 (Mid-term) - 3D OBJ Model Viewer

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

Lab 4 - Midpoint Line Drawing Algorithm

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

Lab 5 - Polygon Filling with Half-Space Method

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

Lab 6 - Animated Polygon Filling

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

Lab 7 - Scanline Polygon Fill Algorithm

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

Lab 8 - Icosahedron Sphere Subdivision & Shading

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

Lab 9 - Planar Shadow Projection (Jet Model)

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)

Lab 10 (folder: lab10) - Textured Scene with Robot Animation & Shadows

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

Lab 11 (folder: lab11_final) - OBJ Model Loader with Texture Mapping

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

📋 Requirements (macOS)

Dependencies

Dependency Description
OpenGL Core graphics library (pre-installed on macOS)
FreeGLUT OpenGL Utility Toolkit for window management

Installing Dependencies

Install FreeGLUT via Homebrew:

brew install freeglut

🛠️ Build & Run (macOS)

Compilation

gcc lab2.cpp -o lab2 -I/opt/homebrew/include -L/opt/homebrew/lib -lglut -framework OpenGL

Run

./lab2

📁 File Structure

opengl_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

⌨️ Common Controls

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)

📖 Topics Covered

  • 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

📝 License

This repository is for educational purposes as part of the NTUT Computer Graphics course curriculum.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages