从Python调用OpenGL扩展

2024-10-01 07:45:59 发布

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

我在ubuntunaty上使用pyopengl3。在

我想使用^{}函数。在

我可以在glxinfo输出中看到它,所以我知道我的卡上有它。在

但是,我找不到如何实际调用它。当我import OpenGL.GL时,如果我尝试使用它,我会得到一个NameError。(不同于None)。在


Tags: 函数importnoneopengl我会glnameerrorglxinfo
2条回答

OpenGL扩展必须由绑定本身提供,PyOpenGL不支持“链加载”新的扩展;虽然可以实现这样的扩展,但是这样做是不值得的。在

也许你只是没有正确地接入分机。opengl解释了opengl的几种方法

http://pyopengl.sourceforge.net/documentation/opengl_diffs.html

Extensions and Conditional Functionality PyOpenGL has support for most OpenGL extensions. Extensions are available as "normal" function pointers by importing the constructed package name for the extension, for instance:

from OpenGL.GL.ARB.vertex_buffer_object import * buffer = glGenBuffersARB(1)

there is no need to call initialization functions or the like for the extension module. You can, if you like, call the "init" function for the extension to retrieve a boolean indicating whether the local machine supports a given extension, like so:

if glInitVertexBufferObjectARB():     
     ...

However, it is normally clearer to test for the boolean truth of the entry points you wish to use:

if (glGenBuffersARB): 
    buffers = glGenBuffersARB( 1 )

There are often a number of entry points which implement the same API, for which you would like to use whichever implementation is available (likely with some preference in order). The OpenGL.extensions module provides an easy mechanism to support this:

from OpenGL.extensions import alternate
glCreateProgram = alternate( 'glCreateProgram', glCreateProgram, glCreateProgramObjectARB)
glCreateProgram = alternate( glCreateProgram, glCreateProgramObjectARB)

If the first element is a string it will be used as the name of the alternate object, otherwise the name is taken from the first argument.

尝试通过扩展名导入函数:

>>> from OpenGL.GL.ARB.draw_elements_base_vertex import *
>>> glDrawElementsBaseVertex
<OpenGL.platform.baseplatform.glDrawElementsBaseVertex object at 0x031D7B30>

相关问题 更多 >