Page 1 of 1

SFML and SDL2

PostPosted: 13 Aug 2019, 00:47
by dulsi
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.)

Re: SFML and SDL2

PostPosted: 13 Aug 2019, 01:57
by fluffrabbit
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.

Re: SFML and SDL2

PostPosted: 13 Aug 2019, 05:08
by Lyberta
Deleted.

Re: SFML and SDL2

PostPosted: 13 Aug 2019, 09:23
by drummyfish
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.

Re: SFML and SDL2

PostPosted: 13 Aug 2019, 11:02
by freemedia2018
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.

Re: SFML and SDL2

PostPosted: 13 Aug 2019, 11:30
by drummyfish
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.

Re: SFML and SDL2

PostPosted: 13 Aug 2019, 12:07
by fluffrabbit
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.