SDL 2.0.0 is out after many years in development
lists.libsdl.org
lists.libsdl.org
The SDL development still impresses me and 2.0.0 is a major milestone and multiple windows, new OpenGL, touch support, Android and iOS support are here to keep SDL alive with all the new frameworks and "engines". I hope it does well!
I was wondering how SDL 2.0 stacks up against SFML? Does anyone know much about it?
I'm only doing 2D game development, so SDL's "simple 2D rendering API that can use Direct3D, OpenGL, OpenGL ES, or software rendering behind the scenes" is perfect for my needs. However it needs to support two basic things:
* Rotation (additional matrix transformation like scaling & shearing would be nice as as well)
* Transparency (being able to apply a color filter not necessarily limited to the alpha channel, like an RGBA filter would be nicer)
Does it support the above? (I'm guessing it does -- just want to be sure.)
Also, I know Android/iOS support for SFML is in the pipeline, but the fact that it's not ready yet is another reason it might be good to switch to SDL 2.
I think I'm going to switch to SDL, primarily for the Android/iOS support!
[1] http://wiki.libsdl.org/moin.fcg/SDL_RenderCopyEx
[2] http://wiki.libsdl.org/moin.fcg/CategoryRender
http://stackoverflow.com/questions/2842198/which-is-better-s...
>This means that it's okay to statically link SDL2 into your game, instead of needing to ship a folder full of shared libraries! xD
source: [1]: http://www.reddit.com/r/gamedev/comments/1k9ila/sdl_20_has_b...
"Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It is used by video playback software, emulators, and popular games including Valve's award winning catalog and many Humble Bundle games."
Nevertheless, I will give it a shot again.
Good work Sam!
Edit: Ah, if the main loop you refer is SDL_Event loop, as exDM69 said, SDL always supported passive event functions that can be called at your original idle function. SDL 2.0 adds an active event watcher (SDL_AddEventWatch etc.) as an alternative though.
Evil or not, it solves a practical problem that you would have to work around if SDL did not. And AFAIK, you have always had the option of not using SDL_main if you wish to solve the problem on your own.
On desktop platforms the program entry point is pretty easy to solve (main vs. WinMain) with an SDL_main-style macro or command line args on win32 compilers. But when you start working with iOS and Android, it gets more hairy.
It was annoying to me because I worked on a application that did the same thing internally and where SDL was not a hard dependency. But well, it's not that bad as I make it sound.
SDL has never hijacked the main loop, unlike e.g. GLUT. SDL has SDL_WaitEvent and SDL_PollEvent and leaves the main loop to you.
It's amazing because I did it for fun and I used some data structures I would have never expect to be so portable (ie. using a double linked list of objects in static memory instead of alloc/free). I wonder if that's why it works even in very limited hardware.
My favourite, the game running on a TI-Nspire calculator: http://www.youtube.com/watch?&v=acdAqxiwG7I&t=15
OpenGL by itself is useless, it just does 3D graphics, and its GLUT library is too bare-bones to be of much use. SDL is a good, portable chassis for OpenGL application that don't need native GUI integration. An SDL OpenGL app will compile and run almost anywhere, with minimal fuss. Compare that to using OpenGL contexts inside platform-specific toolkits.
It's very, very barebones (just enough to GL up to do a thing), but it's quite good in that role.
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
if (!glfwInit())
return -1;
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window) {
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
/* Render here */
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
VS #include <GL3/gl3.h>
#include <SDL.h>
/* Our program's entry point */
int main(int argc, char *argv[])
{
SDL_Window *mainwindow;
SDL_GLContext maincontext;
SDL_Event event;
int running = 1;
if (SDL_Init(SDL_INIT_VIDEO) < 0)
exit(1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
mainwindow = SDL_CreateWindow(PROGRAM_NAME, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
512, 512, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
if (!mainwindow)
exit(1);
maincontext = SDL_GL_CreateContext(mainwindow);
SDL_GL_SetSwapInterval(1);
while (running) {
while (SDL_PollEvent(&event) {
if ( event == SDL_WINDOWEVENT_CLOSE ) {
running = 0;
break;
}
/* render */
}
SDL_GL_SwapWindow(mainwindow);
}
SDL_GL_DeleteContext(maincontext);
SDL_DestroyWindow(mainwindow);
SDL_Quit();
return 0;
}
It's got SDL beat a bit in simplicity for OpenGL, sorry dude.There's nothing wrong with using SDL for making a game (well, maybe a couple of things, but that's not relevant here), but it simply isn't the smallest GL scaffolding library out there.
But I got bit by half-assed "GL" ways of doing things before. SDL has everything, in layers, so you can grow into it. Unlike "portable GL" libraries which are discrete, isolate dead-ends.
GLFW does not attempt to handle OpenGL for you, it handles windowing and input for you. I personally really don't want SDL anywhere near my projects because it imposes its own structure upon me. (I don't use Allegro, even for 2D code, for similar reasons.) I am simply not all that fussed by writing up a VBO handler and some pretty simple OpenAL code myself--it isn't difficult enough for me to warrant the huge blob of extraneous SDL stuff.
window = glfwCreateWindow(640, 480, "Hello World", glfwGetPrimaryMonitor(), NULL);
Requesting a specific version with a particular depth: glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_DEPTH_BIT, 24);
There you go.When wrapping OpenGL code myself, at least the dubious design decisions are my own and I understand them intuitively.
However, if you're using OpenGL, there are at least two libraries you'll probably want to make heavy use of (because SDL doesn't do anything worth mentioning in those regards):
FreeImage for image loading ( http://freeimage.sourceforge.net/ )
AssImp for model loading ( http://assimp.sourceforge.net/ )
Both are amazingly handy, have good licenses, and have excellent documentation (FreeImage is one of my favorite tech writing examples of all time).
But as others here have noted I migrated over to use SFML, mainly because of its nice object-oriented implementation as well as the additional convenience features such as rotation and better alpha support.
You can hardly blame SDL for this, games are not really what X11 was designed for. Setting up full screen and asking for exclusive access to the keyboard will prevent the window manager from doing anything to it.
My solution for this problem: use a window manager that can full screen any window and switch back.
> and the joystick will still not be recognized if you plug it in after the game starts.
To be fair, 99% of AAA games don't support joystick hotplugging either. It's really annoying.
Since you have not checked whether this is actually the situation and do not properly understand the other components in the equation, I find your attitude offensive.
It's funny how the Windows version of the game usually works just fine in Wine, minimization and window switching included.
> Setting up full screen and asking for exclusive access to the keyboard will prevent the window manager from doing anything to it.
Then why are they asking for exclusive access to the keyboard in the first place? X has rich input protocols (XInput2 was recently designed).
> Since you have not checked whether this is actually the situation
True, but I have read the changelog, and it doesn't mention any of these two annoying problems to be fixed. Part of the reason I made this comment is to see if someone else knows whether they were fixed.
For an SDL2-using game, I tried BrütalLegend and alt-tab works as you'd expect when using OpenBox. I usually just run games in a separate X server with just OpenBox to isolate them from messing with my main desktop. Plus, they can't block ctrl+alt+F7.
Even though I believe I do, this is irrelevant, all the end user sees is that it doesn't work, he doesn't care about the architectural problems of the window system. It's extremely annoying when you have to exit the game to look something up (probably related to the game itself), or do anything else, especially considering how long modern games take to load.
I'm not sure how it handles it, but kerbal space program doesn't have this problem in linux.