In this post, we are going to discuss all about game development in C++ along with a very popular multimedia library called Simple DirectMedia Layer or SDL (version 2.0+). I am assuming that you know the basics of C++ and a bit about linking libraries. If you don't know about C++, its syntax and all such things, you should know C++ first to step ahead. My recommendation for learning C++ is to follow a free course offered by John Purcell here.
If you already know C++, then you may want to set up SDL2. I am not going to tell you the whole procedure but you can find it right here. Setting up a library is a hard process but once it is done, you should (and will) never be worried about it.
There are few concepts of SDL. The window that is formed by using SDL acts like a graph or a two dimensional Cartesian coordinate system with 0 starting from the top-left of the screen for both horizontal and vertical axis (or x and y-axis in short). SDL make things easier by having objects like SDL_Window and SDL_Renderer. The first one sets a window on the screen and the second one draws on the window.
A very brief SDL code is given below. This code shows a green color filled screen for just 3 seconds. For the sake of understanding, the code contains a lot of comments (even more than the code!)
There are still few things that may have confused you. The SDL_CreateRenderer() method have two parameters quite unusual. The one filled with '-1', is actually, selects the display driver. '-1' means to select the first display driver found on the computer. We will always use '-1' for this. The one filled with '0' is the additional settings of the renderer. By zero, we mean no additional settings. SDL_WINDOW_SHOWN is also an additional setting for the window which forces the window to be shown on the screen.
SDL_SetRenderDrawColor() method sets the draw color of the renderer. The first parameter is that of SDL_Renderer* which takes the renderer of which the draw color is to be setted. The second, third, fourth and fifth parameter is for setting colour. The second is for setting red component of the draw color, third for blue component and fourth, green. The set range is from 0 to 255. The last one sets the alpha value or transparency of the color. It may not effect the screen draw color.
NOTE:The order of destroying things is important! Generally, the trick for the order of destroying objects is to have the inverse order of creating objects. This is done to avoid memory issues.
All the other code is as clear and self-explanatory as it looks! See! SDL is very simple. But it is just a start. For more programming stuff, visit my blog: bacprogramming.wordpress.com.
And as always, Happy Coding!