How to start with Game loop?

Hello. I am Enrique. I am a programmer of C++. I set up properly my environment. I decided to build a game that is a satellite moving. I followed some tutorials on internet but they have to use SDL Image and other libs that i can not set up properly yet.

How i can start?? It is about the game loop.

I have read previously how to use some methods and i am sure that i am able to use the API. But i don’t know how to structure it in a logical code that i can write.

Lets me know with a piece of code commented, only focused in the functions used, to put it easy for you.

Is SDL plain supporting png images?? Or i should to move to bitmap??

Thank you by your help.

If you make game loop then you can watch Youtube awesome tutorial and it is very helpfully.

Link to YouTube: Click here

Of course SDL2 support with png too If you have advanced method with Cairo or GDI ( Windows API - Graphic Drawing Image )

Or using SDL2_Image you can use too…

I am sure for that.

If you find integrating SDL2_Image too hard, give SDL_stbimage.h a try: https://github.com/DanielGibson/Snippets/blob/master/SDL_stbimage.h

Just put it and stb_image.h in your source directory, and in one of your .cpp source files do:

#define SDL_STBIMAGE_IMPLEMENTATION
#include "SDL_stbimage.h"

then you can use it in your code, like

    const char* imageFilePath = "myimage.png";
    SDL_Surface* surf = STBIMG_Load( imageFilePath );
    if( surf == NULL ) {
      printf( "ERROR: Couldn't load %s, reason: %s\n", 
               imageFilePath, SDL_GetError() );
      exit(1);
    }
    // do something with surf

    SDL_FreeSurface( surf ); // once you don't need it anymore, free it

(if you want to use it in multiple source files, just #include it there as well, but without the #define)

1 Like