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:
QGLShader::compile(Vertex): ERROR: 0:1: '' : version '130' is not supported
QGLShader::compile(Fragment): ERROR: 0:1: '' : version '130' is not supported
我的程序基于 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:
#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;
}
错误(格式,OpenGL 3.2):
Errors (with format, OpenGL 3.2):
QGLShaderProgram: shader programs are not supported
QGLShaderProgram::uniformLocation( mvpMatrix ): shader program is not linked
The program has unexpectedly finished.
错误(无格式,OpenGL 2.0):
Errors (without format, 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
推荐答案
较新的 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:
// main.cpp
QSurfaceFormat glFormat;
glFormat.setVersion(3, 3);
glFormat.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(glFormat);
现在你应该可以在你的着色器中使用类似 #version 330 core
的东西了.
Now you should be able to use something like #version 330 core
in your shader.
这篇关于Qt5 OpenGL GLSL 版本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Qt5 OpenGL GLSL 版本错误


基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01