SFML community forums

General => General discussions => Topic started by: timebender on October 05, 2022, 08:18:25 pm

Title: Difficuly of porting SFML to SDL
Post by: timebender on October 05, 2022, 08:18:25 pm
Hello,
during the summer break, I started coding in SFML, only to recently learn that we use SDL / OpenGL in school. But I don't want to switch so fast, because I just got used to SFML and yeah.

I don't need to make the jump right now. This year, we are supposed to make a game and hand it in in April. Before that, I don't need any knowledge of SDL.
So my question is; How difficult would it be, if I made the game in SFML first and then port it to SDL after it is all finished? Or are there significant issues in doing so?

The game should be quite simple. There will be no shaders or anything of the sort. Just sprites, basic transformations and the sort.

Thank you in advance!
Title: Re: Difficuly of porting SFML to SDL
Post by: eXpl0it3r on October 06, 2022, 08:41:48 am
Haven't really done much SDL development, especially not in the past few years, so might not be the best to answer this.
You'll most likely need to rewrite all the nice SFML abstractions such as sf::Sprite or sf::RectangleShape etc. and figure out the equivalent functions for the operations in SFML (e.g. how to change a view or handle events or open a window, etc.).
Since SDL is C, you may also want to introduce some classes to deal with RAII, as to ensure that the destroy functions are already called.
Title: Re: Difficuly of porting SFML to SDL
Post by: Jim Marsden on November 11, 2022, 08:57:25 pm
The short answer is some, how events are done are different. But unless you did a lot of abstracting everything that touches SDL I think you'd run into some pain. They have so much overlap, and interface very differently. One is a great C library and the other is a fantastic C++ library.

If I were to do it, I would do templates, and c++20 concepts. That way I could rely on polymorphism to do the magic for me.
Title: Re: Difficuly of porting SFML to SDL
Post by: Elias Daler on November 30, 2022, 01:33:02 pm
I'd recommend reading my post on my experiences of porting my engine from SFML to SDL: https://eliasdaler.github.io/porting-to-sdl/

Basically, the more you wrap SFML types/functions into abstractions, the easier it will be to port. I'd also recommend to use something like glm instead of sf::Vector/sf::Rect everywhere.