Assignment Link: Height Fields Using Shaders
Demo Video: Youtube Link
Final Grade: 110 out of 100
This program renders a height field using OpenGL shaders, allowing interactive visualization and manipulation of terrain data derived from heightmap images. It supports various rendering modes, smooth shading, and user controls for transformation and camera adjustments.
-
Multiple Rendering Modes:
- Points
- Lines
- Solid Triangles
- Smoothed Height Field
- Wireframe Overlay
-
Interactive Transformations:
- Rotation
- Translation
- Scaling
-
Camera Controls:
- Zoom In and Zoom Out
- Auto-Rotate Feature
-
Color Options:
- Grayscale based on heightmap
- Custom coloring using an external color image
-
Screenshot Functionality:
- Take a single screenshot
- Capture a sequence of 300 screenshots over 20 seconds
-
Rendering Modes:
- Press
1: Render the height field as points. - Press
2: Render the height field as lines. - Press
3: Render the height field as solid triangles. - Press
4: Render a smoothed height field. - Press
5: Render wireframe overlay on top of solid triangles.
- Press
-
Scaling and Elevation:
- Press
+or=: Increase scale, making the terrain taller. - Press
-or_: Decrease scale, making the terrain flatter. - Press
9: Increase exponent, enhancing elevation contrast. - Press
0: Decrease exponent, reducing elevation contrast.
- Press
-
Camera Controls:
- Press
o: Zoom in the camera. - Press
p: Zoom out the camera. - Press
r: Toggle auto-rotation of the terrain.
- Press
-
Coloring:
- Press
c: Toggle color mode using an external color image.
- Press
-
Screenshot Functions:
- Press
x: Take a screenshot and save it asscreenshot.jpg. - Press
s: Start capturing 300 screenshots over 20 seconds.- Screenshots are saved in the
screenshotdirectory, named from000.jpgto299.jpg.
- Screenshots are saved in the
- Press
-
Rotation:
- Left Mouse Button: Rotate about the X and Y axes.
- Middle Mouse Button: Rotate about the Z axis.
-
Scaling:
- Left Mouse Button +
SHIFT: Scale along the X and Y axes. - Middle Mouse Button +
SHIFT: Scale along the Z axis.
- Left Mouse Button +
-
Translation:
- Left Mouse Button +
tkey: Translate along the X and Y axes. - Middle Mouse Button +
tkey: Translate along the Z axis. - (Note: The
CTRLkey may not work as expected on macOS; thus, thetkey is used for translation.)
- Left Mouse Button +
To run the program, use the following command:
./hw1 <heightmap image file>Examples:
./hw1 heightmap/spiral.jpg
./hw1 heightmap/GrandTeton-128.jpg
./hw1 heightmap/GrandTeton-256.jpg
./hw1 heightmap/OhioPyle-256.jpg
./hw1 heightmap/OhioPyle-512.jpg-
Element Arrays with
glDrawElements:- Used for rendering lines, triangles, and smoothed height fields efficiently.
- Implemented custom
ebo.handebo.cpphelper classes.
-
Coloring with External Image:
- Vertices are colored based on an external image.
- The color image does not need to match the heightmap's dimensions; rescaling is handled.
- Still support the height-based coloring after applying colors from extermal image.
-
Wireframe Overlay:
- Renders a wireframe overlay on top of solid triangles.
- Utilizes
glPolygonOffsetto avoid z-buffer fighting.
-
Camera Zooming:
- Implemented zoom in and zoom out functionality for the camera.
- Adjusted camera position to allow closer or farther viewing of the terrain.
-
Automated Screenshot Capture:
- Captures 300 screenshots over 20 seconds.
- Useful for creating animations or analyzing terrain over time.
- Screenshots are saved in the
screenshotdirectory, named from000.jpgto299.jpg.
-
Automated Rotation:
- Automatically rotate the terrain after press 'r'.
- Able to turn off auto rotate when press again.

