Does SDL2 Have Function To Open URL In Browser?


#1

Hi,

I am preparing our SDL2 game “LettersFall 5” for the official Windows 10 Store.
I would like to have an icon on the title screen which would open our website in the Internet browser.
Does current SDL2 have a function to open a URL link in the default Internet browser?
If no then can someone point to a cross-platform method to do the above?
Thanks!

JeZxLee
16BitSoft Inc.
Video Game Design Studio
www.16BitSoft.com


#2

There has been an SDL_OpenURL() proposal, but I don’t know what happened to it.

There is code for this in various places. Here’s one of my versions; not yet including OS X, unfortunately:


#3

(On Mac, you can just call system(“open https://icculus.org/”) and it will send the request to the user’s preferred browser and return immediately, fwiw.)


#4

Hi,

I can’t get the URL to open in browser on my Linux, what am I doing wrong?

#ifdef _WIN32
    #include <windows.h>
    #include <shellapi.h>
#else
    #include <stdio.h>
    #include <stdlib.h>
#endif

void Data::DisplayWebsite(void)
{
    #ifdef _WIN32
        ShellExecute(NULL, "open", "http://www.16bitsoft.com", NULL, NULL, SW_SHOWNORMAL);
    #else
        char buf[1024];
        snprintf(buf, sizeof(buf), "xdg-open %s", "http://www.16bitsoft.com");
    #endif
}

Thanks!

JeZxLee


#5

printing the command into a buffer doesn’t execute it.


#6

Hi,

The following code crashes my KDE Linux desktop:

#ifdef _WIN32
    #include <windows.h>
    #include <shellapi.h>
#else
    #include <stdio.h>
    #include <stdlib.h>
#endif

//...

void Data::DisplayWebsite(void)
{
    #ifdef _WIN32
        ShellExecute(NULL, "open", "http://www.16bitsoft.com", NULL, NULL, SW_SHOWNORMAL);
    #else
        char buf[1024];
        snprintf(buf, sizeof(buf), "xdg-open %s", "http://www.16bitsoft.com");
        system(buf);
    #endif
}

Any ideas?
Thanks!

JeZxLee


#7

I have implementations for macOS, Windows, UWP, and Linux here: https://bitbucket.org/rude/love/src/b2e868ac8ed36efacb47b107a6ff0706bd7a6512/src/modules/system/System.cpp?at=minor&fileviewer=file-view-default#System.cpp-78

An iOS implementation here:
https://bitbucket.org/rude/love/src/b2e868ac8ed36efacb47b107a6ff0706bd7a6512/src/common/ios.mm?at=minor&fileviewer=file-view-default#ios.mm-315

And an Android implementation in these two files:
https://bitbucket.org/rude/love/src/b2e868ac8ed36efacb47b107a6ff0706bd7a6512/src/common/android.cpp?at=minor&fileviewer=file-view-default#android.cpp-121
https://bitbucket.org/MartinFelis/love-android-sdl2/src/a1aca69aa453ad41f45234c8d7739136637acc72/love/src/main/java/org/love2d/android/GameActivity.java?at=master&fileviewer=file-view-default#GameActivity.java-194


#8

This is the last discussion thread on it that I remember.
https://forums.libsdl.org/viewtopic.php?p=45743&sid=242467567a31023d8e6a4b63e95ff7ba

This is the SDL bugzilla which contains an implementation.
https://bugzilla.libsdl.org/show_bug.cgi?id=2783

Maybe we should make a push to get this into 2.0.6 too?

Thanks,
Eric


#9

Are you by any chance still in fullscreen mode when attempting to open the browser? I don’t remember exactly what happened in my case (it tends to differ between video drivers, desktop environments etc), but there’s a reason Kobo makes sure it’s in windowed mode first. :slight_smile: