GLFW with Angle / EGL on Linux

I’m having some trouble getting started with GLFW and Angle.
Angle builds and the samples run. I have copied libGLESv2.so and libEGL.so to my project directory as well as the includes as advised from the Angle dev documentation.

If I build the following code with:
gcc main.c /usr/local/lib/libglfw3.a -o main -I./include -ldl -lpthread -lm -lGLESv2 -lEGL
It works as expected and glGetString functions for vendor, etc. all show correct output for the Nvidia ES3.2 implementation.

I’m trying to build for Angle with the following:
gcc main.c /usr/local/lib/libglfw3.a -o main -I./include -L./ -Wl,-rpath=./ -ldl -lpthread -lm -l:libEGL.so -l:libGLESv2.so

ldd shows that the two commands link the system and local versions of libGLESv2.so respectively, but the Angle build shows a black window and glGetString returns null. (libEGL.so does not appear to link in either case)

GLFW was pulled from the git repo a couple of days ago and I built Angle around the same time.

If someone could get me pointed in the correct direction I would really appreciate it.

#include <stdio.h>
#include <stdlib.h>

#define GLFW_INCLUDE_NONE
#include "angle_gl.h"
#include <GLFW/glfw3.h>

static void error_callback(int error, const char* description)
{
    fprintf(stderr, "Error: %s\n", description);
}

static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GLFW_TRUE);
}

int main()
{
    GLFWwindow* window;
    glfwSetErrorCallback(error_callback);

    glfwInitHint(GLFW_ANGLE_PLATFORM_TYPE, GLFW_ANGLE_PLATFORM_TYPE_OPENGL);

    if (!glfwInit())
    {
        exit(EXIT_FAILURE);
    }

    glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
    glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

    window = glfwCreateWindow(640, 480, "Test GLES", NULL, NULL);

    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    glfwSetKeyCallback(window, key_callback);

    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);

    const GLubyte* renderer = glGetString(GL_RENDERER);
    const GLubyte* version = glGetString(GL_VERSION);
    const GLubyte* vendor = glGetString(GL_VENDOR);
    printf("Renderer: %s\n", renderer);
    printf("OpenGL version supported %s\n", version);
    printf("OpenGL vendor: %s\n", vendor);

    while (!glfwWindowShouldClose(window))
    {
        float ratio;
        int width, height;

        glfwGetFramebufferSize(window, &width, &height);
        ratio = width / (float) height;
        glViewport(0, 0, width, height);
        glClearColor(0.6f, 0.8f, 0.4f, 1.0f);
        glClear(GL_COLOR_BUFFER_BIT);

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}

Hi @josheb

Welcome to the GLFW forum.

I’ve not tried Angle on Linux and it’s been some time since I tried Angle on Windows so I have forgotten most of what I did.

One thing I would do is try removing the unrequired window hint for GLFW_SAMPLES as I do not know if ANGLE and/or your GPU will support this.

Thanks for the welcome and the response.

I’ve removed the samples hint and it does the same thing.
The initialization code is from an older example of GLFW and Angle on MacOS that I found on github.

Note that you shouldn’t need to link against libEGL.so since GLFW dynamically does this itself in _glfwInitEGL() (this is called internally when you set the context creation hint to GLFW_EGL_CONTEXT_API ):

For reference purposes for an OpenGL ES example take a look at GLFW’s triangle-opengles.c.

Beyond this I don’t think I can provide much help as I haven’t got any experience with Angle on your platform.

I will check out that example and dig into it deeper.
Thank you for your help.

Once I started digging into egl_context.c I discovered that it was looking for libEGL.so.1, which was not so named in my project directory.
I made a symlink with the correct name and it’s loading Angle correctly.

Thanks again for your help.

Excellent, glad you resolved this.

I’m surprised you managed to get a window created if the correct libEGL wasn’t present, as _glfwInitEGL returns false in this case, and then glfwCreateWindow will also return false without creating a window. So perhaps libEGL.so.1 is present on your system as well as the library in your project directory?

That’s correct, there is an Nvidia implementation installed. That’s basically what I was using to test with the different build configurations. I had even tried LD_PRELOAD but with the wrong filename for libEGL I think it was only loading the Angle libGLESv2.so.