Qt5 OpenGL GLSL version error(Qt5 OpenGL GLSL 版本错误)
问题描述
我开始在 Qt 和着色器中使用 OpenGL(我有 OpenGL 经验,但还没有使用着色器)
I'm starting out on using OpenGL with Qt, and with Shaders (I have OpenGL experience, but not with shaders yet)
我正在学习本教程:http://releases.qt-project.org/learning/developerguides/qtopengltutorial/OpenGLTutorial.pdf(Qt5 OpenGL 官方教程).
I'm following this tutorial: http://releases.qt-project.org/learning/developerguides/qtopengltutorial/OpenGLTutorial.pdf (the official Qt5 OpenGL tutorial).
问题是,当我尝试运行我的程序时,出现黑屏并显示以下错误消息:
The problem is, that when I try to run my program, I get a black screen and the following error messages:
我的程序基于 QGLWidget
My program is based on a QGLWidget
通过在互联网上的一些浏览,我发现我需要使用 OpenGL 3.2 上下文,但 Qt 喜欢使用 OpenGL 2.x
With some browsing on the interwebs I found out that I need to use an OpenGL 3.2 context, but that Qt likes to use OpenGL 2.x
我的电脑:
- MacBook Pro Retina '15,2012 年末
- 英特尔 HD 4000
- NVIDIA GeForce 650M
那么,我怎样才能做到这一点?
So, how can I make this work?
我的版本是 3.2(通过 QGLFormat 设置),没有指定格式它使用 2.0
My version is 3.2 (set through QGLFormat), without a specified format it uses 2.0
fragmentShader.frag:
fragmentShader.frag:
vertexShader.vert:
vertexShader.vert:
错误(格式,OpenGL 3.2):
Errors (with format, OpenGL 3.2):
错误(无格式,OpenGL 2.0):
Errors (without format, OpenGL 2.0):
推荐答案
较新的 QOpenGLWidget
不支持任何带有 QGLFormat
的构造函数.相反,在您的 main.cpp
中,为所有 QOpenGLWidget
和 QOpenGLContext
指定默认的 QSurfaceFormat
如下:
Newer QOpenGLWidget
doesn't support any constructor with QGLFormat
. Instead, in your main.cpp
, specify the default QSurfaceFormat
for all QOpenGLWidget
and QOpenGLContext
as following:
现在你应该可以在你的着色器中使用类似 #version 330 core
的东西了.
Now you should be able to use something like #version 330 core
in your shader.
这篇关于Qt5 OpenGL GLSL 版本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!