c++windows-subsystem-for-linuxsdlsdl-2

SDL2 on WSL not working, trying to create a renderer causes libEGL warnings?


I'm trying to simply create a window, running in wsl2, but I'm unable to. Every function call is fine until renderer = SDL_CreateRenderer(). This causes it to spit out:

libEGL warning: failed to open /dev/dri/renderD128: Permission denied

libEGL warning: failed to open /dev/dri/renderD128: Permission denied

libEGL warning: failed to open /dev/dri/card0: Permission denied

No window is created. I have no idea what this means or why this happens, and I have trouble finding anyone online who is in a similar situation.

I am able to run both gedit and glxgears flawlessly.

If I run my program with sudo I get different libEGL warnings:

libEGL warning: MESA-LOADER: egl: failed to open vgem: driver not built!

libEGL warning: NEEDS EXTENSION: falling back to kms_swrast

This is my code:

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

int main() {
    SDL_Window* window = nullptr;
    SDL_Renderer* renderer = nullptr;
    SDL_Init(SDL_INIT_VIDEO);
    window = SDL_CreateWindow("atomer", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 500, 500, 0);
    renderer = SDL_CreateRenderer(window, -1, 0);
    SDL_RenderPresent(renderer);
    SDL_Delay(10000);
    return 0;
}

I've looked up these errors and it feels like a driver issue or something and something to do with how WSL is setup.


Solution

  • I just tried it on a relatively new (last 2 weeks) install of WSL on Windows 11. Since it worked, I suggest a reinstall of WSL. Here's what I did:

    That is, since it seems to be a setup issue, make sure you're all plain-vanilla setup and see if it works.