Can't run OpenGL on WSL2

Viewed 6467

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)
1 Answers

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
...
Related