Failed to create an EGL window surface

Hello,
I have a basic SDL window application in C . It works fine in my host system . I need to run this application in imx6dl processor, for that I added SDL2 library dependency by using IMAGE_INSTALL += " libsdl2" in yocto and generated a bin file by cross compiling the application . While running the application , I am unable to create SDL window . And the error message generated by using SDL_GetError() is

failed to create an EGL window surface

I had, set added the opengl dependency in yocto by using the below lines :

IMAGE_INSTALL += " mesa"
DISTRO_FEATURES:append = " opengl egl gles2 wayland"

I am using x11 SDL_VideoDriver in my host to create SDL window, but the imx6dl processor has no x11 SDL_VideoDriver . It has wayland SDL_VideoDriver . So I created the SDL application with wayland SDL_VideoDriver, set the environment variable as wayland by using export SDL_VIDEODRIVER=wayland and tried to run in the imx6dl, but no use . Could anyone please help me on this issue ??

#include <SDL2/SDL.h>
#include <stdio.h>

int main(int argc, char* argv) {
// Set the SDL video driver to Wayland before SDL_Init
SDL_setenv(“SDL_VIDEODRIVER”, “wayland”, 1);

if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    printf("SDL_Init Error: %s\n", SDL_GetError());
    return 1;
}

int numVideoDrivers = SDL_GetNumVideoDrivers();
printf("Number of video drivers: %d\n", numVideoDrivers);
for (int i = 0; i < numVideoDrivers; ++i) {
    printf("Video driver %d: %s\n", i, SDL_GetVideoDriver(i));
}

SDL_Window *win = SDL_CreateWindow("Hello SDL2", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
if (win == NULL) {
    printf("SDL_CreateWindow Error: %s\n", SDL_GetError());
    SDL_Quit();
    return 1;
}

SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (ren == NULL) {
    SDL_DestroyWindow(win);
    printf("SDL_CreateRenderer Error: %s\n", SDL_GetError());
    SDL_Quit();
    return 1;
}

SDL_SetRenderDrawColor(ren, 255, 0, 0, 255);
SDL_RenderClear(ren);
SDL_RenderPresent(ren);

SDL_Delay(10000);

SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();

return 0;

}

I tried with above example by setting the driver to wayland .

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

The error “failed to create an EGL window surface” typically indicates an issue with the EGL setup or configuration, which is crucial for creating graphical applications that utilize OpenGL ES on embedded systems like the iMX6DL. Given that your application works on your host system but not on the iMX6DL, and considering the transition from X11 to Wayland, there are several areas to check and adjust:

  1. Ensure Wayland Support in SDL: Verify that the version of SDL2 you are using has Wayland support built-in. Not all SDL2 builds have Wayland support enabled by default. You might need to rebuild SDL2 with Wayland support explicitly enabled.

  2. Wayland Environment Variables: Setting SDL_VIDEODRIVER=wayland is correct, but ensure that your environment on the iMX6DL also has the necessary Wayland environment variables set, such as XDG_RUNTIME_DIR. This directory needs to exist and be writable by the user running the application.

  3. EGL and OpenGL ES Libraries: Since you’re using OpenGL ES (gles2), ensure that the Mesa libraries for EGL and GLES2 are correctly installed on your target system. The IMAGE_INSTALL += "mesa" line in your Yocto recipe is correct, but double-check that these libraries are indeed present and correctly configured on the iMX6DL.

  4. Wayland Permissions: Running graphical applications on Wayland sometimes requires additional permissions. If you’re running the application as a non-root user, ensure that the user has the necessary permissions to access the Wayland display server.

  5. Debugging Tips:

    • Use weston-info to verify that the Wayland compositor is running and accessible.
    • Check the output of eglinfo to see if EGL and the desired GLES2 are correctly configured and available.
    • Run your application with WAYLAND_DEBUG=1 to get detailed debug information from the Wayland client library, which might give more insights into what is failing.
  6. SDL Configuration: Before initializing SDL, you correctly set the video driver to Wayland. However, ensure that SDL does not fall back to another video driver if Wayland is not available. You can check the available video drivers with SDL_GetNumVideoDrivers() and SDL_GetVideoDriver() to ensure Wayland is recognized and used.

  7. Compatibility with iMX6DL: The iMX6DL has specific graphical capabilities and limitations. Ensure that your

Please, also check if these links can help you solve your problem:

Build Linux Kernel from Source Code | Toradex Developer Center.

Hi @Teena,

Have your tried Toradex AI suggestion?
Is issue resolved if not please share supporting logs to further check along with complete software and hardware version you are using.

Best regards
Ritesh Kumar

Hi Ritesh Kumar,
Thanks for your reply. I have tried Toradex AI suggestion, but It doesnot works for me . If the processor has x11 support I can able to create sdl window by adding SDL dependency itself . But I dont need x11 support in my imx6dl processsor except wayland support , for that I disabled x11 using DISTRO_FEATURE:remove =“x11” in local.conf file in yocto . At present , my processor has wayland support only . When I tried to run the sample SDL application , I am facing the error failed to create an EGL window surface even though I used the environment variable SDL_VIDEODRIVER=wayland . Can you please tell me how to resolve it ??