Cannot get MacOS + libANGLE + SDL2 to work


I am trying to get SDL2 to work with libANGLE for GLES on MacOS. This is what I have done so far:

  • Built Angle and copied libGLESv2.dylib and libEGL.dylib to /usr/local/lib
  • Also tested the angle build with the tests ./angle_deqp_khr_gles3_tests, most tests pass.
  • Built my own SDL2 from sources with the EGL, GLES2 and GLES3 present on my system at /usr/local/include. Build options was with default configuration, thus on make install put the libs and headers in /usr/local.

Now, the code I use to create a GLES context with SDL, I have used the following:

if (SDL_Init(SDL_InitEverything) < 0)
     std::cerr << "\nFailed on SDL_Init\n";
     return -1;

m_window = SDL_CreateWindow("",
                              SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);

if (m_window == nullptr)
      std::cerr << "\nFailed on SDL_SetVideoMode\n";
      return -1;


m_ctx = SDL_GL_CreateContext(m_window);

if (m_ctx == nullptr)
    std::cerr << SDL_GetError() << "\n";
    return -1;

when building the program, in addition to the flags from pkg-config, I’ve added the link -lEGL -lGLESv2

Program builds with no issue, otool -l confirms that libSDL2.dylib, libEGL.dylib and libGLESv2.dylib are dependencies. However, running is sad:

  • ANGLE_DEFAULT_PLATFORM=metal ./program gives “Could not create EGL context (call to eglCreateContext failed, reporting an error of EGL_BAD_CONFIG)”
  • ANGLE_DEFAULT_PLATFORM=gl ./path_testGLES-debug gives “Could not get EGL display”
  • ./program gives “Could not create EGL context (call to eglCreateContext failed, reporting an error of EGL_BAD_CONFIG)”

so what am I doing wrong?


I recently successfully set up ANGLE with SDL2 on macOS. Here’s my minimal working example:

However, I didn’t build SDL2 from source but obtained it through brew instead.


Try adding this hint before your SDL_CreateWindow() to ensure you get an OpenGLES context:

SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles");

I’m not sure it will help (as you’re not calling SDL_CreateRenderer()).

So, I managed to stumble to a solution which is basically have the


before the call to SDL_CreateWindow(). With that, I can got it to work with ANGLE_DEFAULT_PLATFORM=metal, though ANGLE_DEFAULT_PLATFORM=gl gave me a blank screen (and not a single error). The main purpose was to make it work through metal so I am semi-happy. This is what DrNoob’s link does.

I am not fully happy because I still cannot get the application to use the integrated GPU instead (where as for GL I can force it to use with a crafted Info.plist file and unplugging my MacbookPro from the monitor and power).

Last addendum, using brew’s SDL2 also worked fine with me as well once I moved those calls before SDL_CreateWindow().

With OpenGL, macOS decides which GPU to use. With Metal, it’s up to the application which to use. So Angle is probably choosing the discrete GPU.

When you say ANGLE_DEFAULT_PLATFORM=metal, is that an option you set during the compilation of ANGLE or is that something you can #define/set after compilation, e.g. before including “angle_gl.h”?

ANGLE_DEFAULT_PLATFORM is an environmental variable that Angle reads to decide on the backend unless an application uses the EGL extension that Angle provides to let an application specify the backend. I found the gl backend to give a blank screen on the application I am making where as teh metal backend worked fine.