Well, if you’re already using some sort of text writing system (like
SDL_ttf), you could easily make a small function:
void SDL_MsgBox( const char *title, const char *msg )
{
SDL_Window *msgbox = SDL_CreateWindow( title, SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED, 300, 100, SDL_WINDOW_SHOWN );
SDL_Renderer *msgboxR = SDL_CreateRenderer( msgbox,
0, SDL_RENDERER_ACCELERATED );
SDL_Color color={255,255,255};
SDL_Surface *text_surface = NULL;
SDL_RenderClear( msgboxR );
if((text_surface=TTF_RenderText_Solid( your_font,msg,color)) != NULL) {
SDL_Texture *texture = NULL
if((texture = SDL_CreateTextureFromSurface( msgboxR, text_surface ) !=
NULL) {
SDL_RenderCopy( msgboxR, texture, NULL, NULL );
SDL_RenderPresent( msgboxR );
SDL_DestroyTexture( texture );
}
SDL_FreeSurface(text_surface);
}
}
… and in your SDL event loop:
case SDL_WindowEvent:
if ( e->window.event == SDL_WINDOWEVENT_CLOSE ) {
if ( e->window.windowID != SDL_GetWindowID( your_main_SDL_Window_ptr )
) {
// Must be your message box
SDL_Window *wnd = SDL_GetWindowFromID( e->window.windowID );
SDL_DestroyRenderer( SDL_GetRenderer( wnd ) );
SDL_DestroyWindow( wnd );
}
}
break;
It’s not that bad at all 
-AlexOn Tue, Oct 23, 2012 at 12:36 PM, Sik the hedgehog < sik.the.hedgehog at gmail.com> wrote:
Well, including a full-fledged GUI library just to output a message
box in case of error (when the rest of the program is made with only
SDL, which is the case for most games) is just plain overkill, not to
mention said library may as well fail to initialize, ruining
everything 
Using stderr could be done but should be used as a last resort,
because it requires the console to be opened. Considering SDL programs
usually are meant to be non-console programs, we can’t really rely on
this and should use a better way to communicate the problem if
available.
Making use of the OS API directly defeats the whole point of why one
would want to use SDL in the first place, i.e. portability. Sure, it
would be just a small piece of code you could wrap in #ifdefs, but I
think my solution would be cleaner in the long term (especially since
in some cases it may get tricky to cope with all the issues, e.g.
Windows message boxes only support UTF-16 instead of UTF-8 so you’d
have to convert the strings, etc.).
Allegro used to have an allegro_error function exclusively for this
purpose (no idea what it’s called in Allegro 5 now), I don’t see why
SDL can’t have a similar function.
2012/10/23 Alex Barry <@Alex_Barry>:
I completely understand the suggestion here, as it’s very useful for
getting
your app up and running with some quick error checking, BUT it really
sits
on the fence as far as if it’s something overly appropriate for the SDL
api,
because it’s more of an OS/Gui function which doesn’t sit at the same
low-level that the rest of SDL tends to operate.
The typical solution to this from what I’ve seen is either
having/building
an in-app gui of some sort, or write to stderr/a custom file with an
error
message. If you’re creating a C++ app, you could wrap most of your code
in
try/catch statements, and either do as I suggested, or include the OS-gui
and show a messagebox, which is at least pretty simple on windows (I
can’t
speak for unix-based systems).
Otherwise, I wouldn’t be opposed to something like SDL_MsgBox, but I
don’t
know if it would belong in the core of SDL, or as some sort of extension
library.
Just my thoughts, anyway.
-Alex
On Tue, Oct 23, 2012 at 11:58 AM, Sik the hedgehog <sik.the.hedgehog at gmail.com> wrote:
Quick function suggestion: some function to show a message box (or
whatever is relevant in the current OS, maybe even stderr as a last
resort). Think MsgBox on Windows. This function should work even when
SDL isn’t working. The idea is to allow the program to show an error
message if something goes wrong.
I suppose the syntax could be similar to this (first parameter is the
title, second parameter is the message itself):
SDL_MsgBox(“Error”, “Could not load level”);
Name was just a placeholder for the example, come up with a better one
if needed 
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org