Anyone successfully using SDL2 and ANGLE on MacOSX (not iOS)?


#1

Hi everyone. I have a cross-platform game I’m working on which I’d like to use ANGLE in both Windows and OSX (it’s main targets are native GLES2 on Raspberry Pi and iPhone though).

I’ve had no problem building and running the ANGLE libraries, samples and tests on both Windows and MacOS. However I’m getting (null) as a result from GL queries of GL_RENDERER, GL_VENDOR etc. on Mac in the SDL application.

Sadly, I’m not getting any errors from SDL_Error() to suggest anything is reported as wrong in SDL’s startup. Given the ANGLE samples run fine on MacOS, and don’t use SDL2, I’m guessing it’s something SDL-related?

if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
nda::Err();
}
else {
#if defined(_WIN32) || defined(MACOSX)
SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, “1”); // Force SDL to use ANGLE for it’s OpenGLES2 implementation
#endif

SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);

SDL_SetEventFilter(HandleAppEvents, NULL);

Uint32 windowFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS;

#if defined(IPHONEOS)
windowFlags |= SDL_WINDOW_FULLSCREEN | SDL_WINDOW_ALLOW_HIGHDPI;
#endif

#if defined(NDEBUG) && ( defined(_WIN32) || defined(MACOSX) )
windowFlags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
#endif

gWindow.reset(SDL_CreateWindow("Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1024, 512, windowFlags));
if (!gWindow) {
    nda::Err();
}
else {
    gRenderer.reset(SDL_CreateRenderer(gWindow.get(), -1, SDL_RENDERER_PRESENTVSYNC));
    if (gRenderer) {
        context = SDL_GL_CreateContext(gWindow.get());
        // context seems to be valid here on OSX?

The libraries linked to the executable

$ otool -L ./voxel
./voxel:
    @rpath/libGLESv2.dylib (compatibility version 0.0.0, current version 0.0.0)
    @rpath/libEGL.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/local/opt/libomp/lib/libomp.dylib (compatibility version 5.0.0, current version 5.0.0)
    @rpath/SDL2.framework/Versions/A/SDL2 (compatibility version 1.0.0, current version 10.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 23.0.0)
    @rpath/SDL2_image.framework/Versions/A/SDL2_image (compatibility version 3.0.0, current version 3.2.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)

Example output:

2019-04-06 11:53:58.550 voxel[5802:153931] INFO: GL SwapInterval (vsync) : 1
2019-04-06 11:53:58.550 voxel[5802:153931] INFO: Window: 1024, 512
2019-04-06 11:53:58.550 voxel[5802:153931] INFO: Renderer: 1024, 512
2019-04-06 11:53:58.550 voxel[5802:153931] INFO: Logical: 0, 0
2019-04-06 11:53:58.550 voxel[5802:153931] INFO: Using GL Renderer: (null)
2019-04-06 11:53:58.551 voxel[5802:153931] INFO: Using OpenGL version: (null)
2019-04-06 11:53:58.551 voxel[5802:153931] INFO: Using Vendor: (null)
2019-04-06 11:53:58.551 voxel[5802:153931] INFO: Using GLSL version: (null)
2019-04-06 11:53:58.551 voxel[5802:153931] INFO: ------------> -345639520, 32766
2019-04-06 11:53:58.551 voxel[5802:153931] INFO: MAX TEXTURE SIZE: -345639520
2019-04-06 11:53:58.551 voxel[5802:153931] INFO: GL texture allocated with ID: 0
2019-04-06 11:53:58.554 voxel[5802:153931] INFO: Cleaned up SDL_Surface…
2019-04-06 11:53:58.554 voxel[5802:153931] INFO: GL texture allocated with ID: 372523514
2019-04-06 11:53:58.555 voxel[5802:153931] INFO: Cleaned up SDL_Surface…

This is by no means an urgent issue. :slight_smile: Plenty of options for just using GLEW and a compatibility profile, but would certainly appreciate any help from someone who is currently using ANGLE on OSX.


#2

Just posting the fix for this in case anyone has this issue in future. I say fix, I mean user error. :wink:

Be very careful that if you use CMake in your project, be vigilant for it pulling an ancient version of SDL that you may have installed in ~/Library/Frameworks many years ago and totally forgotten about, rather than the one you may have built recently for /usr/local/lib. Somehow I missed this in my build output.

Latest SDL2 does, of course, work out of the box with ANGLE on MacOSX.