为什么glXGetVisualFromFBConfig总是无法从我的FBConfig中找到有效的visual?

2024-06-16 10:56:20 发布

您现在位置:Python中文网/ 问答频道 /正文

有人能解释一下为什么glXGetVisualFromFBConfig失败了,我得到的FBConfig似乎是有效的,并且与我的请求相匹配,但是将FBConfig传递给glXGetVisualFromFBConfig并没有返回visual,我无法找出原因。在

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()

Tags: fromimportselfaddconfigvaluecountextension
1条回答
网友
1楼 · 发布于 2024-06-16 10:56:20

在我的案例中,我决定这些结构OpenGL.原始._GLX.LP结构图103当无效的响应实际上不是时,我想我已经假设anon是匿名的,并且在最初检查一个错误的响应时,只有一些结果是无效的。在

似乎OpenGL.原始._GLX.LP结构图103是有效的,但是你需要确保结果.内容值不是空指针。在

相关问题 更多 >