Migrating Shootius from SDL 1.2 to SDL 2.0
As written here, I wanted to migrate my little game to new version of SDL.
Oh wow what a pain it is !
There is a lack of documentation and examples for both versions of SDL.
I should really stop using this library. I even thought of migrating Shootius on PS Vita, but then nobody would be able to try it.
Regarding Unity 3D, it seems practical for 3D but not really for 2D.
So I stayed with SDL 2.0 and this is what I’ve learned:
– It’s better and faster to use SDL_Texture instead of SDL_Surface but don’t erase them immediately ! You in fact need both.
For my case I had to first load optimized SDL_Surfaces, then apply the transparency, then convert them to texture. Then you render the texture… which makes 3 times more lines of code…
– Replace SDL_BlitSurface by SDL_RenderCopy
– Replace SDL_Flip by SDL_RenderPresent
– Replace SDL_FillRect by
SDL_SetRenderDrawColor(sdlRenderer, 50, 50, 50, 255);
for full screen OR
SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, 255);
for a specific rectangle(SDL_Rect).
Naahhh I was wrong. You can certainly do what’s above but if you have “SDL_Surface”s you can just keep them and change “SDL_BlitSurface” by “SDL_UpdateSurface”. It’s way simpler. Also some of your constants like SDL_HWSURFACE are not recognized, since they were equal to 0, you can just replace them by 0. I should still use textures but SDL_RenderCopy is giving me trouble not wanting to take my destination rectangle into account.
– You should instantiate a SDL_Window instead of a SDL_Surface. Read me.
– In SDL_SetWindowTitle, give the sdlWindow instead of the main SDL_Surface (often called “screen”).
That’s it for what I understand so far. I’m going back at it.