SOFTWARE 3D RENDERER TUTORIAL

At first this project was aimed to be an implementation of things shown in One Lone Coder video series called “3D Graphics Engine”. But when my project continued to inflate more and more and code comments started to span across several screens I decided that it might be a good idea to put all of that knowledge into an article of some sort, so that it can maybe pop out of Internet search to somebody new to 3D graphics who is trying to figure out how everything works.

As it usually happens, when you decide to research some topic of interest you’ll end up going down the rabbit hole of different complexity: you start from something simple (in your opinion) but then everything branches out and sometimes so much that it’s easy to get lost.

This is no exception.

I mean, everybody knows that 3D graphics basically means drawing lots of triangles to the screen. What could possibly be easier? So you go to YouTube and try to find some tutorial videos there (or even text stuff, but who wants to read text?). But what tutorials do you need? How to write your own raytracer? No, that’s probably too complicated for a first tutorial project. How to render simple 3D cube? OK, sounds good, but very soon you’ll start asking other questions: how does projection work? Why perspective projection matrix is the way it is? And what about shading and textures? How do you do that?

Lots of questions, but you have to start from somewhere.

Also, it’s obvious that you can’t show and explain everything in one YouTube video, for example, so authors end up concentrating on one subject while completely leaving out something else, which could be exactly the thing you’re trying to understand right now. And so you quickly find yourself all over the Internet, searching and aggregating bits of information from different sources, trying to make sense of all that at the same time.

In this series of articles I’m going to learn the topic myself and implement stuff as I go, hopefully with some ups and downs along the way, so you can see what problems one may encounter and how to deal with them. Although probably there won’t be that many of such cases, apart from the first few chapters. Hopefully this will also show how small things evolve and slowly complicate themselves.

We’ll be using SDL2 to draw graphics because it’s the most “low level” as you can get in a sense that we only can draw pixels to the screen with specified color and that’s it. This will also showcase how all 3D stuff gets build from ground up and what unobvious problems might arise in the process. I’ll also be using C++ because all of the learning materials used it, but I guess you can port everything to PyGame or whatever without much effort if you want to use something else. I’d say whatever graphics library / framework you have that allows you to paint pixels on the screen will do. It might not be a good idea performancewise, but we all know the famous quote from Donald Knuth, right?

Codebase is extensively commented, so you can check it out as well.

Even though English is not my native language I’ll be writing everything in it for 2 reasons:

  1. Remember AD&D and what’s called “common language”? Well, it’s quite obvious that English became that in our real life. And by obvious reasons also there’s overwhelmingly much more actual information available in English regarding IT related topics.
    By writing in a language other than English you write only for those who know it, but by writing in English you write for everyone.

  2. "Понты дороже денег" which can roughly be translated as “Showing off is priceless”. XD

I hope I won’t make lots of grammar and spelling mistakes by doing so. )

Any comments / remarks / hints regarding this are appreciated though.

And before I forget, here’s the list of sources I used in my research:

Well, I guess that’s about it. I might update this list in the future if needed, since at the moment of writing these lines my renderer is still incomplete.

So, if you’d like to join me on this adventure, you’re welcome!

Table of Contents:


Next up: Preparations


Back to index page