我正在尝试从论文中实现代码。编译所有C++代码,一切都很好,但是我在尝试编译着色器时遇到了错误。
我了解QT-Desktop版本将这三行附加到我的文件头部
#define lowp
#define mediump
#define highp
但它似乎直接附加到我的 #version 行之后,这会导致解析错误。有什么线索吗?
系统规格:
- OpenGL 4.60, Nvidia 390.87, QT 4.8.7
这是触发错误的相关代码片段(从源代码添加着色器时(
if (!program->addShaderFromSourceFile(QOpenGLShader::Vertex, shaderFolder + shaderName + "_vertex_shader.glsl")) {
cout << "error adding vertex shader from source file" << endl;
return false;
}
这是错误消息。
***
error adding vertex shader from source file
QOpenGLShader::compile(Vertex): 0(36) : error C0206: invalid token "<invalid atom 50446656>" in version line
*** Problematic Vertex shader source code ***
/**
* #, #, CCCCCC VV VV MM MM RRRRRRR
* % %( #%%# CC CC VV VV MMM MMM RR RR
* % %## # CC V V MM M M MM RR RR
* ,% % CC VV VV MM MM MM RRRRRR
* (% %, CC CC VVVV MM MM RR RR
* #% %* CCCCCC VV MM MM RR RR
* .% %/
* (%. Computer Vision & Mixed Reality Group
* For more information see <http://cvmr.info>
*
* This file is part of RBOT.
*
* @copyright: RheinMain University of Applied Sciences
* Wiesbaden Rüsselsheim
* Germany
* @author: Henning Tjaden
* <henning dot tjaden at gmail dot com>
* @version: 1.0
* @date: 30.08.2018
*
* RBOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RBOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RBOT. If not, see <http://www.gnu.org/licenses/>.
*/
#version 330#define lowp
#define mediump
#define highp
#line 37
uniform mat4 uMVMatrix;
uniform mat4 uMVPMatrix;
uniform mat3 uNormalMatrix;
in vec3 aPosition;
in vec3 aNormal;
out vec3 vNormal;
void main() {
vNormal = normalize(uNormalMatrix * aNormal);
// vertex position
gl_Position = uMVPMatrix * vec4(aPosition, 1.0);
}
更新 - 我已经使用 2 个修复程序解决了这个问题。
-
添加着色器时,我重写了代码,基本上使用函数QOpenGLShader::CompileSourceCode而不是QOpenGLShaderProgram::addShaderfromSourceFile。我使用下面参考中的代码片段将源文件作为字符串读取,然后将该字符串输入CompileSourceCode函数。
-
我用了
#version 410
而不是
#version 330
这是由于与所使用的 layout(( 语法不兼容而完成的。
参考: 顶点着色器错误 C5145:必须使用 QShaderProgram 写入gl_Position