Building my own rasteriser: part 14 - it moves! it moves!
I decided it would be a very nice feature if, instead of only rendering one frame, I could have an animation loop. Handily, CImg provides a way to display a window and update its contents.
The first step was to split more pieces out of the main renderer.cpp file. I defined a struct [class] to contain the command line arguments with the command line parser as its constructor.
The second was to split out most of the geometry commands in the main function into a drawing function in drawing.cpp.
This is barely different to the version of these commands in int main.
Finally, this let me write a simple animation loop.
This uses the standard library <chrono> header to get a very precise clock, and thus frames will be drawn correct to the actual frame rate for a spin rate of 1 radian per second.
Sadly I can’t easily show the result of this, unless of course you download the code and compile it for yourself :)
The framerate depends, naturally, on your computer and the complexity of the scene. On my fairly old laptop, I only get around 4fps on Suzanne, and fluctuations in the range 20-120fps on the square depending of course on how much of the screen it took up.
I made a small optimisation by adding backface culling to the algorithm: a triangle will only be drawn if the z component of its normal is positive. This gave me a couple more FPS on Suzanne; the framerate soared to 400fps or so when the square was turned away from the camera.
I’d have to do more coding to make animated file output, so I can’t really show off the results except to say “download and compile it and run it for yourself”.
Next up: depending on what I feel like doing, either shadow maps or smooth shading and texture coordinates.