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.
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:
Used the default install, which is Ubuntu. Changed nothing from defaults
apt-get update && apt-get upgrade && apt-get autoremove
apt-get install build-essential libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
To compile, g++ -g -c backquotesdl2-config --cflagsbackquote myprog.cpp
(I can't do backquote here, so I typed out backquote)
To link, g++ -g myprog.o backquotesld2-config --libsbackquote
That is, since it seems to be a setup issue, make sure you're all plain-vanilla setup and see if it works.