# GLFW with Angle / EGL on Linux

**URL:** <https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402>\
**Category:** support\
**Created:** [June 25, 2023, 8:22pm UTC](https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402 "2023-06-25T20:22:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![josheb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/josheb/32/790_2.png) [@josheb](https://discourse.glfw.org/u/josheb)\
**Post date:** [June 25, 2023, 8:22pm UTC](https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402/1 "2023-06-25T20:22:09Z")

</div>

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.

```auto
#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);
}

```

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [June 26, 2023, 10:42am UTC](https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402/2 "2023-06-26T10:42:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![josheb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/josheb/32/790_2.png) [@josheb](https://discourse.glfw.org/u/josheb)\
**Post date:** [June 26, 2023, 11:10am UTC](https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402/3 "2023-06-26T11:10:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [June 26, 2023, 1:17pm UTC](https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402/4 "2023-06-26T13:17:32Z")

</div>

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` ):

> <https://github.com/glfw/glfw/blob/3fa2360720eeba1964df3c0ecf4b5df8648a8e52/src/egl_context.c#L360-L392>

For reference purposes for an OpenGL ES example take a look at GLFW’s [triangle-opengles.c](https://github.com/glfw/glfw/blob/3fa2360720eeba1964df3c0ecf4b5df8648a8e52/examples/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.

---

<div class="post-metadata">

**Author:** ![josheb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/josheb/32/790_2.png) [@josheb](https://discourse.glfw.org/u/josheb)\
**Post date:** [June 27, 2023, 12:24am UTC](https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402/5 "2023-06-27T00:24:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![josheb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/josheb/32/790_2.png) [@josheb](https://discourse.glfw.org/u/josheb)\
**Post date:** [June 27, 2023, 9:25pm UTC](https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402/6 "2023-06-27T21:25:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [June 28, 2023, 9:56am UTC](https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402/7 "2023-06-28T09:56:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![josheb](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/josheb/32/790_2.png) [@josheb](https://discourse.glfw.org/u/josheb)\
**Post date:** [June 28, 2023, 11:15am UTC](https://discourse.glfw.org/t/glfw-with-angle-egl-on-linux/2402/8 "2023-06-28T11:15:11Z")

</div>

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.
