Can't run OpenGL on WSL2
Asked Answered
C

1

7

I am trying to run an OpenGL code on WSL2 but am getting the following error on trying to run the executable:

GLFW error 65543: GLX: Failed to create context: GLXBadFBConfig
Unable to create GLFW window

This is the code I am using to create a window:

....
GLFWwindow* initialize() {
      int glfwInitRes = glfwInit();
      if (!glfwInitRes) {
         fprintf(stderr, "Unable to initialize GLFW\n");
         return nullptr;
      }

      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
      glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

      GLFWwindow* window = glfwCreateWindow(1280, 720, "InitGL", nullptr, nullptr);
      if (!window) {
         fprintf(stderr, "Unable to create GLFW window\n");
         glfwTerminate();
         return nullptr;
      }

      glfwMakeContextCurrent(window);

      ....
      return window;
   }
   ....

GLFWwindow* window = initialize();

I am using VcxSrv as my X server.

Following is from the output for glxinfo

direct rendering: No (LIBGL_ALWAYS_INDIRECT set)
server glx vendor string: SGI
server glx version string: 1.4
client glx vendor string: Mesa Project and SGI
client glx version string: 1.4
GLX version: 1.4
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 940MX/PCIe/SSE2
OpenGL version string: 1.4 (4.6.0 NVIDIA 457.30)
Christhood answered 5/3, 2021 at 17:39 Comment(2)
Because of direct rendering: No your OpenGL version is stuck at 1.4 see also, so version 3.2 features will not work for you.Crotch
I have no idea what you need to do on WSL2 to get direct rendering, let's see if someone else knows.Crotch
C
20

The following fix worked for me.

As @dratenik mentioned above, the problem persists because of direct rendering: No. To solve this, do the following:

In the bashrc/zshrc file, add the following:

export LIBGL_ALWAYS_INDIRECT=0

Or you could just remove export LIBGL_ALWAYS_INDIRECT=1 line from your bashrc/zshrc file if you have added it.

Then, start a new instance of VcxSrv with and unselect the Native opengl box on the Extra Settings page, and select the Disable access control box. VcxSrv Extra Settings

After doing this, direct rendering should be turned on, and you should get the following on running glxinfo:

direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
...
Christhood answered 6/3, 2021 at 13:23 Comment(1)
FTR, now that WSL2 lets you run X clients (also with GL) natively (no more 3rd-party X servers, yay!), this was exactly what I need to set (apart from DISPLAY=:0) for my X app to actually start working finally.Gotten

© 2022 - 2024 — McMap. All rights reserved.