[英]Error compiling QOpenGLshader from source file
I am trying to implement a code from a paper .我正在尝试从论文中实现代码。 Compiling all the C++ code and everything is fine, but I encountered an error while trying to compile the shaders.
编译所有 C++ 代码,一切正常,但我在尝试编译着色器时遇到错误。
I understand QT-Desktop version append these three lines to the head of my file我了解 QT-Desktop 版本将这三行附加到我的文件头部
#define lowp
#define mediump
#define highp
but it seems to append directly after my #version line, which causes parsing error.但它似乎直接附加在我的 #version 行之后,这会导致解析错误。 Any clues?
有什么线索吗?
Sys Specs:系统规格:
This is the relevant code snippet that triggers the error (while adding shader from source code)这是触发错误的相关代码片段(同时从源代码添加着色器)
if (!program->addShaderFromSourceFile(QOpenGLShader::Vertex, shaderFolder + shaderName + "_vertex_shader.glsl")) {
cout << "error adding vertex shader from source file" << endl;
return false;
}
And this is the error message.这是错误信息。
***
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);
}
Update - I have solved the problem using 2 fixes.更新 - 我已经使用 2 个修复程序解决了这个问题。
When adding the shader, I rewrote the code to essentially use the function QOpenGLShader::CompileSourceCode instead of QOpenGLShaderProgram::addShaderfromSourceFile .添加着色器时,我重写了代码,基本上使用函数QOpenGLShader::CompileSourceCode而不是QOpenGLShaderProgram::addShaderfromSourceFile 。 I used the code snippet from reference below to read the source file as a string, and then feed that string into the CompileSourceCode function.
我使用下面参考中的代码片段将源文件作为字符串读取,然后将该字符串提供给CompileSourceCode函数。
I used我用了
#version 410
instead of代替
#version 330
This was done due to the incompatibility with the layout() syntax that was used.这样做是因为与所使用的 layout() 语法不兼容。
Reference: Vertex shader error C5145: must write to gl_Position using QShaderProgram参考: 顶点着色器错误 C5145:必须使用 QShaderProgram 写入 gl_Position
Could you show more details about the first fix? 您能否显示有关第一个修复程序的更多详细信息? I encountered the same error with the same code (RBOT), Thank you.
我用相同的代码(RBOT)遇到了相同的错误,谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.