Table of Contents
Choosing a library: not easy!
As I told you just now, there are thousands and thousands of libraries to download.
Some of them are simple, others more complex. Some are so big that even a whole course like the one you are reading wouldn’t be enough!
Making a choice is therefore hard. Plus, it’s the first library you’ll learn to use (if you don’t count the standard library), so it’s best to start with a simple library.
I quickly found that the majority of my readers were interested in learning how to open windows, create games, etc. Finally, if you like the console, we can go on for a long time, if you want… No? Ah, well, it’s curious!
SDL is a good choice!
- It’s a library written in C, so it can be used by C programmers like you. Note that like most libraries written in C, it is possible to use them in C ++ as well as other languages.
It is a free and open library: it will save you from having to invest. Contrary to what one might think, finding open and free libraries is not very difficult, there are many available today. A free library is simply a library from which you can obtain the source code. As far as we are concerned, seeing the source code of the SDL will not interest us. However, the fact that the library is free guarantees you several things, in particular its durability (if the main developer stops taking care of it, other people will be able to continue it in its place) as well as that it is usually free. The library is therefore not in danger of disappearing overnight.
- Vous pouvez réaliser des programmes commerciaux et propriétaires avec. Certes, c’est peut-être un peu trop vouloir anticiper, mais autant choisir une bibliothèque gratuite qui vous laisse un maximum de libertés. En effet, il existe deux types de bibliothèques libres :
-GPL licensed libraries: they are free and you can have the source code, but you are obliged in return to provide the source code of the programs you make with it;
-LGPL licensed libraries: it’s the same thing, except this time you don’t have to provide source code for your programs. You can therefore create proprietary programs with it.
- It is a multi-platform library. Whether you are on Windows, Mac or Linux, SDL will work in your home. This is even what makes this library impressive in the eyes of programmers: it works on a very large number of operating systems. There are Windows, Mac and Linux sure, but it can also work on Atari, Amiga, Symbian, Dreamcast, etc. Clearly, your programs could work very well on old machines like the Atari! However, it would be necessary to make some small adjustments and perhaps use a special compiler. We will not discuss it here.
- Finally, the library allows you to do fun things. I’m not saying that a math library that can solve fourth degree equations isn’t interesting, but I want this course to be as fun as possible in order to motivate you to program.
The possibilities offered by the SDL:
- A low level library: it is a library with very basic functions. There are generally few functions because you can do everything with them. As the functions remain basic, they are very fast. The programs produced using such a library are therefore generally the fastest.3
- A high level library: it has many functions capable of performing many actions. This makes it easier to use.
However, a library of this kind is generally “big”, therefore more difficult to study and fully understand. Also, it is often slower than a low level library (although sometimes it is not really visible).
Of course, we must qualify. We cannot say “a low level library is better than a high level library” or vice versa. Each of the two types has its strengths and weaknesses. The SDL that we are going to study is more of a low level library.
It should therefore be remembered that the SDL mainly offers basic functions. For example, you have the possibility to draw pixel by pixel, draw rectangles or even display images. That’s all, and that’s enough.
- By moving an image, you can make a character move.
- By displaying several images in a row, you can create animation.
- By combining several images side by side, you can create a real game.
The important thing to understand is that it all depends on you and possibly your team. You can make games even more beautiful if you have a talented graphic designer on hand.
The only limitation of SDL is 2D. It is indeed not designed for 3D. Here is a list of games that we can perfectly design in SDL (this is only a small list, everything is possible a priori as long as it remains 2D):
-platform games: Super Mario Bros, Sonic, Rayman …
-2D RPG: Zelda, the first Final Fantasy, etc.
It is impossible for me to make a complete list, the only limit here being the imagination. I saw one of the readers of this course making a daring cross between a breaker and a Tetris.
Let’s go back to Earth and pick up the thread of this course. We are now going to install SDL on our computer before going any further.