【发布时间】:2017-10-19 16:43:28
【问题描述】:
我在 Mac 上使用 PyOpenGL。默认情况下,使用 OpenGL 2.1。但是,根据我的研究和 OpenGL Extension Viewer,我应该能够使用 OpenGL 4.1。 我正在尝试将 QGLFormat 传递给我的 QGLWidget,正如我在这里的许多线程上看到的那样,但是上下文版本没有改变。如果我尝试强制它,它会告诉我上下文无效。 我一直在做很多实验——这里有一个非常简单的例子来说明我的问题:
from PyQt4 import QtGui, QtCore, QtOpenGL
import sys
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
glFormat = QtOpenGL.QGLFormat()
glFormat.setVersion(4,1)
glFormat.setProfile(QtOpenGL.QGLFormat.CoreProfile)
glFormat.setSampleBuffers(True)
glFormat.setDefaultFormat(glFormat)
print("Format version: " + str(glFormat.majorVersion()))
myW = QtOpenGL.QGLWidget(glFormat)
print ("Widget context valid: " + str(myW.context().isValid()))
print ("Widget format version: " + str(myW.format().majorVersion()))
print ("Widget context format version: " + str(myW.context().format().majorVersion()))
myW.context().setFormat(glFormat)
print ("Forced format valid: " + str(myW.context().isValid()))
print ("Forced format version: " + str(myW.format().majorVersion()))
myW.show()
sys.exit(app.exec_())
这是输出:
Format version: 4
Widget context valid: True
Widget format version: 1
Widget context format version: 1
Forced format valid: False
Forced format version: 4
知道我的问题出在哪里吗?难道我做错了什么? 我使用的是 macOS Sierra 版本 10.12.6。 我使用 Qt 版本 4.8.7、sip 版本 4.19.3 和 pyqt 版本 4.12,以防万一。 这里是what OpenGL Extension Viewer tells me。
任何帮助将不胜感激!
编辑:
我在这里发现了与 C++ 类似的问题。我不确定如何将解决方案翻译成 PyQt,但我会研究一下: Changing the OpenGL Context Version for QGLWidgets in Qt 4.8.6 on OS X.
编辑 3:
在尝试@ekhumoro 提供的补丁(第二版)时,我得到以下输出:
patching file qpy/QtOpenGL/core_profile_attributes.mm
patching file qpy/QtOpenGL/qpyopengl.pro
patching file sip/QtOpenGL/qgl.sip
patch unexpectedly ends in middle of line
Hunk #3 FAILED at 493.
1 out of 3 hunks FAILED -- saving rejects to file sip/QtOpenGL/qgl.sip.rej
qpyopengl.pro 现在已正确修补,但 qgl.sip 仍然失败。
更新:
这是 qgl.sip 的拒绝文件的内容:
***************
*** 478,481 ****
%ModuleHeaderCode
#include <qpyopengl_api.h>
--- 493,498 ----
%ModuleHeaderCode
#include <qpyopengl_api.h>
+ typedef struct GDevice** GDHandle;
+ void* select_3_2_mac_visual();
出于好奇,我运行了 configure-ng.py 并尝试编译。我收到以下错误:
[...]/PyQt4_gpl_mac-4.12.1/sip/QtOpenGL/qgl.sip:269:5: error: 'virtual' can only appear on non-static member functions
virtual void* chooseMacVisual(GDHandle handle)
^
[...]/PyQt4_gpl_mac-4.12.1/sip/QtOpenGL/qgl.sip:271:16: error: use of undeclared identifier 'select_3_2_mac_visual'
return select_3_2_mac_visual();
^
[...]/PyQt4_gpl_mac-4.12.1/sip/QtOpenGL/qgl.sip:269:44: warning: unused parameter 'handle' [-Wunused-parameter]
virtual void* chooseMacVisual(GDHandle handle)
【问题讨论】:
-
您需要在 OSX 上创建 forward-compatible 上下文。
-
@derhass:你能说得更具体点吗?
标签: python macos opengl pyqt4 qglwidget