[英]Qt5 OpenGL GLSL version error
I'm starting out on using OpenGL with Qt, and with Shaders (I have OpenGL experience, but not with shaders yet) 我开始使用OpenGL和Qt,以及使用Shaders(我有OpenGL经验,但还没有使用着色器)
I'm following this tutorial: http://releases.qt-project.org/learning/developerguides/qtopengltutorial/OpenGLTutorial.pdf (the official Qt5 OpenGL tutorial). 我正在学习本教程: http: //releases.qt-project.org/learning/developerguides/qtopengltutorial/OpenGLTutorial.pdf(官方Qt5 OpenGL教程)。
The problem is, that when I try to run my program, I get a black screen and the following error messages: 问题是,当我尝试运行我的程序时,我得到一个黑屏和以下错误消息:
QGLShader::compile(Vertex): ERROR: 0:1: '' : version '130' is not supported
QGLShader::compile(Fragment): ERROR: 0:1: '' : version '130' is not supported
My program is based on a QGLWidget 我的程序基于QGLWidget
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 通过对浏览器的一些浏览,我发现我需要使用OpenGL 3.2上下文,但是Qt喜欢使用OpenGL 2.x
My computer: 我的电脑:
So, how can I make this work? 那么,我怎样才能做到这一点呢?
EDIT: 编辑:
My version is 3.2 (set through QGLFormat), without a specified format it uses 2.0 我的版本是3.2(通过QGLFormat设置),没有使用2.0的指定格式
fragmentShader.frag: fragmentShader.frag:
#version 130
uniform vec4 color;
out vec4 fragColor;
void main(void)
{
fragColor = color;
}
vertexShader.vert: vertexShader.vert:
#version 130
uniform mat4 mvpMatrix;
in vec4 vertex;
void main(void)
{
gl_Position = mvpMatrix * vertex;
}
Errors (with format, OpenGL 3.2): 错误(格式,OpenGL 3.2):
QGLShaderProgram: shader programs are not supported
QGLShaderProgram::uniformLocation( mvpMatrix ): shader program is not linked
The program has unexpectedly finished.
Errors (without format, OpenGL 2.0): 错误(没有格式,OpenGL 2.0):
QGLShader::compile(Vertex): ERROR: 0:1: '' : version '130' is not supported
QGLShader::compile(Fragment): ERROR: 0:1: '' : version '130' is not supported
Newer QOpenGLWidget
doesn't support any constructor with QGLFormat
. 较新的QOpenGLWidget
不支持任何带有QGLFormat
构造QGLFormat
。 Instead, in your main.cpp
, specify the default QSurfaceFormat
for all QOpenGLWidget
and QOpenGLContext
as following: 相反,在main.cpp
,为所有QOpenGLWidget
和QOpenGLContext
指定默认的QSurfaceFormat
,如下所示:
// main.cpp
QSurfaceFormat glFormat;
glFormat.setVersion(3, 3);
glFormat.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(glFormat);
Now you should be able to use something like #version 330 core
in your shader. 现在,您应该可以在着色器中使用#version 330 core
的内容。
You should create an QGLFormat
object and pass it to the QGLWidget as a constructor parameter. 您应该创建一个QGLFormat
对象并将其作为构造函数参数传递给QGLWidget。 The QGLFormat
object should be created as showed in the code below. 应创建QGLFormat
对象,如下面的代码所示。
QGLFormat glFormat;
glFormat.setVersion( 3, 2 );
glFormat.setProfile( QGLFormat::CoreProfile );
I've got the same error on my macbook (early 2011), and this answer helps me. 我的macbook上有同样的错误(2011年初), 这个答案对我有帮助。 Basically you deprecate to version120. 基本上你弃用到版本120。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.