I made an OpenGL-like renderer to learn Rust. Had an amazing developing experience!
TLDR: Wrote a small 3D renderer using Rust, had an awesome experience.
For several years now, I have been quite interested in Rust. Having worked with C++ several times, Rust's philosophy clicked with me. As powerful as C++ is, we all know how painful it can be sometimes, and reading about Rust's model and how it tries to tackle C/C++ problems made total sense to me.
Around a year ago, I started to learn Rust, mainly by taking online courses, going through several Rust books, and watching several tutorials, mostly Let's Get Rusty videos (shootout to Bogdan, thanks for providing such valuable content and resources), but never got hands-on with it. We all know staying in tutorial hell is not something very useful for actually learning a tool or a language, so I decided to look for some project I could build using Rust to properly learn it.
Not so long ago I discovered Build your own X, which provides you with several project ideas. Since I did a Computer Graphics-related Master's, I decided to try and implement tinyrenderer, a walkthrough for building a didactic OpenGL-like 3D renderer. The original code is written in C++, and the professor states that to fully understand how the entire process works, it is best to just follow the wiki and try to ignore the code, and what better way to prevent oneself from getting biased by the code than by implementing it in another language?
I started building the project, and although there was a little bit of friction at first, something that is expected when starting to build something new, I almost immediately started to experience all the amazing things developing something in Rust has. Rust's ownership system is what is discussed the most when talking about Rust's benefits, but it is far from being the only amazing thing Rust offers.
Firstly, the tooling. What an amazing experience Rust tooling offers. I personally use Emacs with rust-analyzer language server support, and the help all the tools provide is insane. The linter is insane. It is so useful and helps catch almost all the errors even before compiling, all while providing easy-to-understand messages and suggestions. The fact that things like jump-to-definition work right out of the box is a blessing. If you have ever worked with C/C++, you know how difficult it can be to properly set up your development environment.
Secondly, the compiler. There is little to discuss here. Rust has the best compiler ever, period. The fact that you can make your program work almost always just by following the compiler recommendations is simply mind-blowing.
Thirdly, Cargo. If you ever have had to use CMake or any C/C++ build tools, you know how painful it can be. CMake has had me crying in pain before, and I wouldn't wish it on my worst enemy. Cargo feels just like using npm but on a low-level language, which for me is insane. So easy, so simple, and so clear.
Lastly, traits. Favoring composition over inheritance for polymorphism and dynamic dispatch makes things so much clearer and easier to understand. Even for a small-sized project, inheritance hierarchies become obscure and difficult to understand very quickly. Choosing not to include that feature in the language, while providing a model that is so easy to understand is simply brilliant.
I could keep going, but I think you get my point. Rust is awesome, and I recommend learning it. I am not taking much more of your time, I just needed somewhere to share my whole experience!
Here is the repo in question: https://github.com/ema2159/tinyrenderer\_rs. If you want to give it some love or provide me with any kind of feedback, that is very much appreciated. Also, if you want to connect with me or anything, please feel free to do so!