'Couldn't find matching GLX visual

I'm struggling to initialise an OpenGL display using pygame and pyopengl.

import pygame
pygame.init()
pygame.display.set_mode((1920, 1080), pygame.OPENGL)

gives the error:

pygame.error: Couldn't find matching GLX visual

If I don't specify pygame.OPENGL I get a properly initialised display and a pygame window.

  • I'm using python 3 (Python 3.6.2 :: Anaconda custom (64-bit))
  • I'm on Manjaro Linux, running i3 windows manager
  • I'm on a Dell XPS laptop, which has both Intel and Nvidia graphics adapters and I'm using optirun to use the Nvidia hardware, but I get the same effect regardless of which graphics adapter I use
  • glxgears and optirun glxgears both work fine, so I believe that OpenGL is available on the machine and working fine
  • optirun glxinfo https://pastebin.com/v6VjZgBZ

In an attempt to find a suitable set of display parameters, I ran:

import pygame
from pygame.locals import *
pygame.init()
print(pygame.display.Info())
print(pygame.display.list_modes(32, pygame.FULLSCREEN))
print(pygame.display.mode_ok((1920, 1080)))
print(pygame.display.mode_ok((1920, 1080), pygame.OPENGL))

Which gave the following output:

VideoInfo(hw = 0, wm = 1,video_mem = 0
         blit_hw = 0, blit_hw_CC = 0, blit_hw_A = 0,
         blit_sw = 0, blit_sw_CC = 0, blit_sw_A = 0,
         bitsize  = 32, bytesize = 4,
         masks =  (16711680, 65280, 255, 0),
         shifts = (16, 8, 0, 0),
         losses =  (0, 0, 0, 8),
         current_w = 3200, current_h = 1800

[(3200, 1800), (2880, 1620), (2560, 1600), (2560, 1440), (2048, 1536), (2048, 1152), (1920, 1440), (1920, 1200), (1920, 1080), (1856, 1392), (1792, 1344), (1680, 1050), (1600, 1200), (1600, 900), (1400, 1050), (1400, 900), (1368, 768), (1280, 1024), (1280, 960), (1280, 800), (1280, 720), (1024, 768), (1024, 576), (960, 540), (864, 486), (800, 600), (720, 405), (640, 480), (640, 360)]
32
32

Below is an extract of optirun glxinfo, i.e. glxinfo for the Nvidia adapter, showing several GLX Visuals (full output https://pastebin.com/v6VjZgBZ):

70 GLX Visuals
    visual  x   bf lv rg d st  colorbuffer  sr ax dp st accumbuffer  ms  cav
  id dep cl sp  sz l  ci b ro  r  g  b  a F gb bf th cl  r  g  b  a ns b eat
----------------------------------------------------------------------------
0x020 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x021 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0ce 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0cf 24 tc  0  32  0 r  . .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0d0 24 tc  0  32  0 r  . .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0d1 24 tc  0  24  0 r  y .   8  8  8  0 .  .  0  0  0  0  0  0  0  0 0 None
0x0d2 24 tc  0  24  0 r  . .   8  8  8  0 .  .  0  0  0  0  0  0  0  0 0 None
0x0d3 24 tc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x0d4 24 tc  0  24  0 r  . .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x0d5 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0d6 24 tc  0  32  0 r  . .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0d7 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0d8 24 tc  0  32  0 r  . .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0d9 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0da 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8 16 16 16 16  0 0 None
0x0db 24 tc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x0dc 24 tc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8 16 16 16  0  0 0 None
0x0dd 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0de 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8 16 16 16 16  0 0 None
0x0df 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0e0 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0e1 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0e2 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0e3 24 tc  0  24  0 r  y .   8  8  8  0 .  .  0  0  0  0  0  0  0  0 0 None
0x0e4 24 tc  0  24  0 r  y .   8  8  8  0 .  .  0  0  0  0  0  0  0  0 0 None
0x0e5 24 tc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x0e6 24 tc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x0e7 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0e8 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0e9 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0ea 24 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0eb 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0ec 24 dc  0  32  0 r  . .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0ed 24 dc  0  32  0 r  . .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0ee 24 dc  0  24  0 r  y .   8  8  8  0 .  .  0  0  0  0  0  0  0  0 0 None
0x0ef 24 dc  0  24  0 r  . .   8  8  8  0 .  .  0  0  0  0  0  0  0  0 0 None
0x0f0 24 dc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x0f1 24 dc  0  24  0 r  . .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x0f2 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0f3 24 dc  0  32  0 r  . .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0f4 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0f5 24 dc  0  32  0 r  . .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0f6 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0f7 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8 16 16 16 16  0 0 None
0x0f8 24 dc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x0f9 24 dc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8 16 16 16  0  0 0 None
0x0fa 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0fb 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8 16 16 16 16  0 0 None
0x0fc 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0fd 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x0fe 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x0ff 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x100 24 dc  0  24  0 r  y .   8  8  8  0 .  .  0  0  0  0  0  0  0  0 0 None
0x101 24 dc  0  24  0 r  y .   8  8  8  0 .  .  0  0  0  0  0  0  0  0 0 None
0x102 24 dc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x103 24 dc  0  24  0 r  y .   8  8  8  0 .  .  0 24  8  0  0  0  0  0 0 None
0x104 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x105 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x106 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x107 24 dc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x06f 32 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x108 32 tc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x109 32 tc  0  32  0 r  . .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x10a 32 tc  0  32  0 r  . .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x10b 32 tc  0  32  0 r  y .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x10c 32 tc  0  32  0 r  . .   8  8  8  8 .  .  0  0  0  0  0  0  0  0 0 None
0x10d 32 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x10e 32 tc  0  32  0 r  . .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x10f 32 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None
0x110 32 tc  0  32  0 r  y .   8  8  8  8 .  .  0 24  8  0  0  0  0  0 0 None

Please help me to diagnose the problem and get an OpenGL enabled pygame window going.

Update 20190131 I tried in ipython (python 3.6.2) setting 24-bit colour mode as suggested by @hidefromkgb, but I got the same issue (I had tried this before):

In [1]: import pygame

In [2]: pygame.init()
Out[2]: (6, 0)

In [3]: pygame.display.set_mode((1920, 1080), pygame.OPENGL, 24)
---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-3-b9c85baaf5fe> in <module>()
----> 1 pygame.display.set_mode((1920, 1080), pygame.OPENGL, 24)

error: Couldn't find matching GLX visual

I am able to get OpenGL working from c++ using GLUT without problems.

Update #2 20190131

I have two minimal programs now (python, c++) with accompanying strace output (see https://paste.ee/p/ah1nq).

This python program fails with the GLX Visuals error:

import pygame
pygame.init()
pygame.display.set_mode((1920, 1080), pygame.OPENGL)

This c++ programs succeeds in creating a window:

#include <GL/glut.h>

void display(void) {
}

int
main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutCreateWindow("window initialisation test");
    return 0;
}

The c++ program was compiled with g++ test.cpp -lGL -lglut -o test.

I had a look at the strace output, but couldn't make heads nor tails of it.

Update #3 20190131

I ran ltrace on the two above programs and got

python

$ ltrace python test.py
__libc_start_main(0x400ab0, 2, 0x7ffe171cfb58, 0x400cc0 <unfinished ...>
_PyMem_SetupAllocators(0x400da8, 0x7ffe171cfb58, 0x7ffe171cfb70, 0x7f82b2fd4578) = 0
PyMem_RawMalloc(24, 0x400daf, 0x7ffe171cfb70, 6)                                = 0xf8d260
PyMem_RawMalloc(24, 0xf8d270, 0xf8d260, 0xf8d260)                               = 0xf8d280
setlocale(LC_ALL, nil)                                                          = "C"
_PyMem_RawStrdup(0x7f82b2f9c007, 0, 0, 0xf8d280)                                = 0xf8d2a0
setlocale(LC_ALL, "")                                                           = "LC_CTYPE=en_AU.utf8;LC_NUMERIC=e"...
Py_DecodeLocale(0x7ffe171d1310, 0, 0, 0)                                        = 0xf90710
Py_DecodeLocale(0x7ffe171d1317, 0, 0xf90728, 0)                                 = 0xf90740
setlocale(LC_ALL, "C")                                                          = "C"
PyMem_RawFree(0xf8d2a0, 16, 0, 0)                                               = 0
Py_Main(2, 0xf8d260, 0, 0xf8e260Traceback (most recent call last):
  File "test.py", line 4, in <module>
    pygame.display.set_mode((1920, 1080), pygame.OPENGL)
pygame.error: Couldn't find matching GLX visual
)                                               = 1
_PyMem_SetupAllocators(0x400da8, 0x7f82b2fd6710, 0, 2880)                       = 0
PyMem_RawFree(0xf90710, 0x400daf, 0, 6)                                         = 0
PyMem_RawFree(0xf90740, 0xf90760, 0, 0xf90760)                                  = 0
PyMem_RawFree(0xf8d260, 0xf90700, 0, 0xf90700)                                  = 0
PyMem_RawFree(0xf8d280, 0xf8f310, 0, 0xf8f310)                                  = 0
+++ exited (status 1) +++

c++

$ ltrace ./test
glutInit(0x7ffd507caccc, 0x7ffd507cadb8, 0x7ffd507cadb8, 128)                   = 0
glutInitDisplayMode(18, 1, 0x7fb32b5c44e0, 32)                                  = 0x7fb32b7d70e0
glutCreateWindow(0x562359efe004, 1, 0x7fb32b5c44e0, 32)                         = 1
--- SIGWINCH (Window changed) ---
+++ exited (status 0) +++

Update #4 20190213

Thanks for the input, @hidefromkgb.

I tried using pygame.OPENGL | pygame.DOUBLEBUF and also just passing 18, but got the same result.

import pygame
from pygame.locals import *

pygame.init()
pygame.display.set_mode((1920, 1080), pygame.OPENGL | pygame.DOUBLEBUF)

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-11-59807ce30659> in <module>()
      3 
      4 pygame.init()
----> 5 pygame.display.set_mode((1920, 1080), pygame.OPENGL | pygame.DOUBLEBUF)

error: Couldn't find matching GLX visual
print(pygame.OPENGL)
print(pygame.DOUBLEBUF)

2
1073741824


Solution 1:[1]

Sorry for the late answer, haven`t seen your edit before. In the future, please call people by nicknames in comments if you need to have their attention.

ltrace seems to have made the issue clearer. The first parameter to glutInitDisplayMode equals 18 which means GLUT_DOUBLE | GLUT_DEPTH, for GLUT_DOUBLE = 2, GLUT_DEPTH = 16.

In its turn, pygame.display.set_mode call lacks both of these flags during GL initialization.

Try using pygame.OPENGL | pygame.DOUBLEBUF instead of just the pygame.OPENGL.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rabbid76