[英]QOpenGLFunctions and PySide2
How to use QOpenGLFunctions
from PySide2
?如何使用
QOpenGLFunctions
的PySide2
?
The problem is with the GLEnum
, which the API documentation mentions but doesn't tell from where one could take it.问题在于
GLEnum
,API 文档中提到了它,但没有说明可以从哪里获取它。
For example, I would like to call glGetString(),
I try:例如,我想调用
glGetString(),
我尝试:
from OpenGL import GL
from PySide2.QtGui import QOpenGLFunctions as GLF
GLF.glGetString(GL.GL_VERSION))
But it produces an error.但它会产生错误。
TypeError: descriptor 'glGetString' requires a 'PySide2.QtGui.QOpenGLFunctions' object but received a 'IntConstant'
You have to use a QOpenGLFunctions associated with a current QOpenGLContext, for example you can use the following code:您必须使用与当前 QOpenGLContext 关联的 QOpenGLFunctions,例如您可以使用以下代码:
from OpenGL import GL
from PySide2 import QtGui
if __name__ == "__main__":
app = QtGui.QGuiApplication()
off_screen = QtGui.QOffscreenSurface()
off_screen.create()
if off_screen.isValid():
context = QtGui.QOpenGLContext()
if context.create():
context.makeCurrent(off_screen)
f = QtGui.QOpenGLFunctions(context)
print(f.glGetString(GL.GL_VERSION))
Output:输出:
3.0 Mesa 20.1.6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.