A program that reads in an .obj triangle mesh to an image through software rasterization.
- Folder (src) with all the source code
- Folder (resources) with all the obj meshes tested
As input, the rasterization program takes in six command arguments:
- OBJ file name
- Name of the image to output
- Desired image width
- Desired image height
- Mode for coloring (0, 1, or 2)
- 0 for per-vertex colors
- 1 for depth colors
- 2 for y-axis gradient colors
For output, the program will create the image with the desired name (and format).
Utilizing Syoyo's Obj Loader, we first load the mesh into our program and store the vertex positions into a buffer, taking every three consecutive vertices and creating a single triangle from them.
With the triangles now forming a 3D object, we create a bounding box for every triangle and build another for the entirety of the object, allowing us to display the object in such a way where it fills as much of the screen as possible without distoriton.
Using our previously created bounding boxes, we utilize barycentric coordinates in order to change the shape of our bounding boxes into a triangle that matches the actual 3D object.
Creating a buffer containing the z-coordinate of every pixel, we then store the interpolated z-coordinate of every vertex using the pixel's barycentric coordinates.
And with Nothing's Image Writer, we finally draw every triangle, pixel-by-pixel, into an output file.