When I was teaching the labs for COMP-3520 with Dr. Robert Kent, I put together a little demo to help explain certain concepts during the labs. It is a 2.5D software rendered engine. That is, there’s no OpenGL or Direct3D or Vulkan or anything like that involved: this renders directly to an array, treating it as though it were a linear framebuffer (2D array of pixels). Each lab, I would demonstrate a new concept using some addition to the demo. The purpose of this was to help explain the math behind 3D rendering without any magic involved: how do we render a triangle? How do we do depth sorting? How do we do clipping? These were all topics we addressed in the course.
The demo is presented below (WASM-capable browser required):
Controls are your mouse + WASD. Click the mouse to “lock” it and make it easier to move around, click again to “unlock it”
Depth sorting is demonstrated for sprites, but not for walls. An outcome of the course was adding a spatial partitioning scheme to do depth sorting across the entire scene (i.e., BSP and other methods were discussed). Everything was presented in 2.5D to make the math and code easier to explain, which we would then discuss in 3D later once the students had a better handle on things. For example, I taught projective geometry and homogeneous coordinates using 3D instead of 4D homogeneous coordinates at first just to help get perspective division understood, then generalized to the 4D homogeneous coordinates later once students had a better grasp of what was going on. Some famous bit-level trickery was pointed out as well in the process (e.g, snippets from the Doom and Quake source code). Each function in the code was thoroughly broken down in each lab.
The Source code is available, and will work in both native and WebAssembly environments, but includes no dependencies. It’s not the cleanest code, but it was a Computer Graphics course, not a Software Engineering course :) The relevant code is in main.cpp.
A separate repository exists for the same project but structured as a Visual Studio project for convenience with all dependencies integrated.