gpt4 book ai didi

glsl 着色器的 C++ Qt "unsupported version"错误

转载 作者:搜寻专家 更新时间:2023-10-31 01:33:14 26 4
gpt4 key购买 nike

我正在尝试制作 Qt 控制台应用程序,它将启动计算着色器,但在启动时会出现以下错误:

QOpenGLShader::compile(Compute): 0(1) : error C0201: unsupported version 44
0(1) : error C0206: invalid token "<invalid atom 284073152>" in version line

Shader 已经过测试并正确无误(它在我的基于 openFrameworks 的程序中运行良好)并以

开始
#version 440

在基于 Qt 的程序中,我使用以下代码在 main.cpp 中初始化 OGL 上下文

QSurfaceFormat surfaceFormat;
surfaceFormat.setMajorVersion(4);
surfaceFormat.setMinorVersion(4);
surfaceFormat.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(surfaceFormat);

QOpenGLContext openGLContext;
openGLContext.create();
if(!openGLContext.isValid())
{
qDebug()<<"Failed to create openGL context";
return 0;
}
QOffscreenSurface surface;
surface.create();
if(!surface.isValid())
{
qDebug()<<"Failed to create surface";
}

然后编译着色器

QOpenGLShaderProgram compute;
compute.addShaderFromSourceFile(QOpenGLShader::Compute,":/shaders/cull.glsl");
compute.link();

是否有任何我遗漏的特定于 Qt 的东西?

最佳答案

所以这个问题有点出乎我的意料。 Shader 文件由 Visual Studio 保存,因此它具有 windows 编码。 OpenFrameworks 程序也是由 Visual Studio 构建的,因此它在启动着色器方面没有问题,但 Qt 无法处理 windows 编码的 EOL。以 UTF-8 格式重新保存着色器文件已修复问题。

关于glsl 着色器的 C++ Qt "unsupported version"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41713296/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com