SFML and SDL2

SFML and SDL2

Postby dulsi » 13 Aug 2019, 00:47

rubenwardy and others have mentioned using SFML for new projects particularly instead of SDL2. I looked around for what advantages it has over SDL2. The big difference is obviously the C++ implemention. Is there some other features of SFML that stand out from SDL2? Is it just the preference for OOP? It has more built in where SDL2 needs SDL2_image, SDL2_ttf, etc.

My experience with SFML comes from OstrichRiders. It was written for SFML1.x. When I tried to compile it with SFML2 it didn't compile. The programmer decided that he didn't like his naming convention for function names so he changed them all. Updating the code mostly involved changing every reference to SFML functions. That make me distrust a library. SDL2 broke backward compatibility because the old API couldn't support new hardware. They change only what was needed. SFML seems to have decided to head in a different direction "breaking changes should be able to happen more frequently and within a manageable scope" link. I understand the reasoning but it isn't what I want from a library. The library is supposed to reduce my work not cause something to break regularly.

(If someone can explain this from the C++ standard update please do. "Remove component-wise overloads in favor of initializer lists: setPosition(x,y) -> setPosition({x,y})" I do not understand why you would want to do this. I don't know why "setPosition({x,y})" would be advantageous.)
dulsi
 
Posts: 353
Joined: 18 Feb 2016, 15:24

Re: SFML and SDL2

Postby fluffrabbit » 13 Aug 2019, 01:57

SFML comes with spartial audio out-of-the-box. It also has some hacky GPU selection stuff for Windows, and C++ is the language of linalg.h and GLM. See where I'm going with this? SFML is a good alternative to SDL if you're making the kind of game that I like.

Generally with these libraries you're supposed to make your own renderer using the system graphics API, so if the library's built-in drawing commands break it's no big deal. But if you're making an unambitious 2D project I can't recommend anything specific; I just use SDL for those. SFML has 2D shader support though.
fluffrabbit
 
Posts: 570
Joined: 11 Apr 2019, 11:17

Re: SFML and SDL2

Postby Lyberta » 13 Aug 2019, 05:08

dulsi {l Wrote}:"Remove component-wise overloads in favor of initializer lists: setPosition(x,y) -> setPosition({x,y})" I do not understand why you would want to do this.


I assume it takes some kind of 2D point. This can be better so you don't have to modify the rest of the API when you modify a struct. Also, you can do nice things such as setPosition({ .x = 1, .y = 2}) in C++20 (might require explicit struct name though).
User avatar
Lyberta
 
Posts: 663
Joined: 19 Jun 2013, 10:45

Re: SFML and SDL2

Postby drummyfish » 13 Aug 2019, 09:23

Though nowadays I prefer C to C++, I think SFML is great actually. It's been some time but I remember I have once chosen it over SDL because it can do rotations, scaling and other transforms of sprites, which if I remember correctly SDL can't do out of the box, or at least not in an easy way. I think it also generally has more of these higher level functions and is friendlier to use.
socialist anarcho-pacifist
Abolish all IP laws. Use CC0.
http://www.tastyfish.cz
User avatar
drummyfish
 
Posts: 227
Joined: 29 Jul 2018, 20:30
Location: Moravia

Re: SFML and SDL2

Postby freemedia2018 » 13 Aug 2019, 11:02

drummyfish {l Wrote}:which if I remember correctly SDL can't do out of the box


Closest thing I know to this is: https://stackoverflow.com/questions/118 ... -using-sdl (for reference, not to dispute what you're saying.)

Use SDL in OpenGL mode and render your sprites to primitives, applying rotation to the primitives.
User avatar
freemedia2018
 
Posts: 119
Joined: 21 Jul 2019, 07:30

Re: SFML and SDL2

Postby drummyfish » 13 Aug 2019, 11:30

Yes, there are third party libraries etc., but as I see it you're not supposed to use SDL as a rendering engine, just a display engine for what you render in another engine. This was the game I was working on:

https://hooktube.com/watch?v=4uq1jaJ3Hsc

In SDL I coudn't find an easy way to transform the road strips to create the perspective effect. In SFML I just subclassed something from the library and modified a few lines.
socialist anarcho-pacifist
Abolish all IP laws. Use CC0.
http://www.tastyfish.cz
User avatar
drummyfish
 
Posts: 227
Joined: 29 Jul 2018, 20:30
Location: Moravia

Re: SFML and SDL2

Postby fluffrabbit » 13 Aug 2019, 12:07

Use SDL in OpenGL mode and render your sprites to primitives, applying rotation to the primitives.

The default mode works fine, and a backend will be chosen based on what is available (be it software, OpenGL, Vulkan, etc.)

As for perspective effects, I haven't tried to fudge it with a 2D library since the good old days, but you would have to use 4x4 matrix math to do it properly with SDL as SDL really just draws stuff.
fluffrabbit
 
Posts: 570
Joined: 11 Apr 2019, 11:17

Who is online

Users browsing this forum: No registered users and 1 guest