Note: the permanent address to this tutorial is http://iki.fi/sol/gp2/ - please use that as a link.
When I wrote the first version of this tutorial, the programming landscape was quite different. The original target market for this tutorial was beginner programmers, and software rendering made kind of sense back then. Today, software rendering is pretty much dead, most people use game engines instead of rolling their own, etc.
But basics do still matter, and there's some new interest in building your own engine. What you find in this tutorial are ways to write graphics (and games) from the really ground up, with no hardware acceleration. All of the concepts are useful when using modern graphics APIs and game engines.
So, let's begin.
When I was starting graphics programming on the PC, things were a lot simpler than they are these days. For instance, if you wanted to get to a graphics mode, all you needed to do was to type in a couple of cryptic lines, like so:
_asm {
mov ax, 13h
int 10h
}
After this, the graphics mode was 320 pixels wide, 200 pixels high, had 256 colors, and the "screen" was a linear array of bytes at a static address ((unsigned char*)0xa0000)
. Note that there was no reason to actually understand what those lines did.
Okay, the mode had a palette and changing the palette was a bit trickier, but basically everything you needed to start could be explained in a dozen or so code lines.
So, I'm writing this tutorial for those who might want to take a more 'traditional' introduction to graphics, instead of taking the more common direct3d/opengl/vulkan approach. As a warning, this is not a tutorial in 'C'. However, if you're familiar with java, php, ecmascript, c# or some other language that has a similar syntax, you should be fine. However, you may want to keep a c tutorial handy.
(Some readers may find my boolean / bit masking / bit modification tutorial useful).
I'll use SDL3 as the graphics library. This means the code should work, more or less as is, on various platforms. Most of the tutorial does not care about the use of this particular library, and won't use most of its features.
I will not go into super detailed description on how to set up your development environment on all possible platforms, so if you're a beginner, you may need help getting started from someone more experienced, but once the environment is up and running, the tutorial should be easy to follow.
This tutorial is suitable for people who are learning programming by themselves, or who already know how to program but don't know much about graphics, or are interested in the very basics. Programming students may also use it as additional material for programming courses. Bored of those dry programming assignments? Maybe it's time to try something fun.
I aim to provide some simple, understandable routines, and some hints to what can be done to play with the routines. Playing here is the key; if you find that you can actually have fun programming, learning becomes much more interesting. Or, that way it has been to me.
Later on in the tutorial, we'll build one complete game, step by step, from scratch to polish.
Let's start by 01 - Setting Up SDL..
Any comments etc. can be emailed to me.
Legalese, for those who want to know:
Feel free to use this tutorial for personal education.
You have my blessing for using the techniques and source code from this tutorial in whatever way you wish. Since corporations keep patenting obvious things, it's entirely possible that I'm covering patented things, but in my opinion, everything I talk about is, or should be, general knowledge.
You can take copies of these pages for your personal use.
Please don't start any unofficial mirrors.
Feel free to use this tutorial as part of educational material in a schools or any other kind of educational institution, as long as:
If this tutorial is used in some school or other kind of educational institution (in full or in part), please let me know, both of the planned use and the results, so I can keep improving it. Publishable quotes are appreciated!
While effort has been made to make this tutorial as flawless as possible, some mistakes are bound to creep in. This is a fact of life and I'd rather not be held liable for any problems. Please let me know if you find something that's wrong!