Может ли кто-нибудь объяснить, почему glXGetVisualFromFBConfig терпит неудачу, FbConfigs я, кажется, действителен и соответствует тому, что я запрашиваю, но передача FBConfig в glXGetVisualFromFBConfig не возвращает визуальный результат, и я не смог понять, почему.Почему glXGetVisualFromFBConfig всегда не может найти действительный визуал из моего FBConfig?
import sys
import xcb
import xcb.glx
import xcb.composite
import xcb.xproto as xproto
import Xlib
from Xlib.display import Display
from ctypes import *
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL import GLX
try:
from OpenGL.GLX import struct__XDisplay
except ImportError as err:
from OpenGL.raw._GLX import struct__XDisplay
class alpha_glx_example:
xlib = cdll.LoadLibrary('libX11.so')
xlib.XOpenDisplay.argtypes = [c_char_p]
xlib.XOpenDisplay.restype = POINTER(struct__XDisplay)
xdisplay = xlib.XOpenDisplay(None)
display = Xlib.display.Display()
attrs = []
def __init__(self):
self.xserver = xcb.connect()
self.xclient = self.xserver.core
self.setup = self.xserver.get_setup()
self.canvas = self.setup.roots[0]
self.root_window = self.canvas.root
self.depth = self.setup.roots[0].root_depth
self.visual = self.setup.roots[0].root_visual
composite_ext = self.load_extension('Composite', xcb.composite.key)
render_ext = self.load_extension('RENDER', xcb.render.key)
glx_ext = self.load_extension('GLX', xcb.glx.key)
""" lets setup are opengl settings and create the context for our window """
self.add_attribute(GLX.GLX_RENDER_TYPE, GLX.GLX_RGBA_BIT)
self.add_attribute(GLX.GLX_DRAWABLE_TYPE, GLX.GLX_WINDOW_BIT)
self.add_attribute(GLX.GLX_X_RENDERABLE, True)
self.add_attribute(GLX.GLX_RED_SIZE, 8)
self.add_attribute(GLX.GLX_GREEN_SIZE, 8)
self.add_attribute(GLX.GLX_BLUE_SIZE, 8)
self.add_attribute(GLX.GLX_ALPHA_SIZE, 8)
#~ self.add_attribute(GLX.GLX_DEPTH_SIZE, 24)
#~ self.add_attribute(GLX.GLX_DOUBLEBUFFER, True)
config_count = c_int()
configs = GLX.glXChooseFBConfig(self.xdisplay, self.display.get_default_screen(), self.get_attributes(), byref(config_count))
if config_count.value is 0 or configs.__class__ is "<class 'OpenGL.raw._GLX.LP_struct_anon_103'>":
sys.exit('no matching configs found')
print self.attrs
print '\nfind visual from choose fbconfig %s found' % config_count.value
count = 0
# lets poke the configs to make sure we are getting what we expect from glXChooseFBConfig
for i in range(0, config_count.value):
config = configs[i]
count += 1
print 'count %d' % count
xrender = c_int()
GLX.glXGetFBConfigAttrib(self.xdisplay, config, GLX.GLX_X_RENDERABLE, byref(xrender))
print 'xrender = %d' % xrender.value
red_size = c_int()
print GLX.glXGetFBConfigAttrib(self.xdisplay, config, GLX.GLX_RED_SIZE, byref(red_size))
print 'red size = %s' % red_size.value
test = c_int()
print GLX.glXGetFBConfigAttrib(self.xdisplay, config, GLX.GLX_ALPHA_SIZE, byref(test))
print 'alpha size = %d' %test.value
picture_formats = render_ext.QueryPictFormats().reply()
# for some reason glXGetVisualFromFBConfig fails to find any visuals
for i in range(0, config_count.value):
count += 1
config = configs[i]
visual = GLX.glXGetVisualFromFBConfig(self.xdisplay, config)
print visual
if 'OpenGL.raw._GLX.LP_struct_anon' in str(visual.__class__):
continue
def glx_visual_info(self, visual):
print('GLX Visual Info')
print('rgb depth = %s' % visual.depth)
print('red mask = %s' % visual.red_mask)
print('green mask = %s' % visual.green_mask)
print('blue mask = %s' % visual.blue_mask)
print('colour map = %s' % visual.colormap_size)
print('screen id = %s' % visual.screen)
print('bits per rgb = %s' % visual.bits_per_rgb)
print('visual = %s' % visual.visual)
print('visual id = %s' % visual.visualid)
def add_attribute(self, setting, value=None):
"""just to nicely add opengl parameters"""
self.attrs.append(setting)
if value:
self.attrs.append(value)
def get_attributes(self):
""" return our parameters in the expected structure"""
attrs = self.attrs + [0, 0]
return (c_int * len(attrs))(*attrs)
def load_extension(self, name, xcb_key):
# test extension is present
extension = self.xclient.QueryExtension(len(name), name).reply()
if extension.present != 1:
print("%s not available" % name)
return
print('Using %s extension' % name)
return self.xserver(xcb_key)
if __name__ == "__main__":
alpha_glx_example()