【发布时间】:2019-08-17 14:03:51
【问题描述】:
我在 Unix 19.04 操作系统中将 Qt 5.13 与 opengl 4.4 和 3.3 用于 GLSL。
请注意,我使用 QOpenGLWindow 作为 Qt 应用程序的主窗口。
我正在尝试正确链接 opengl 顶点着色器的输入。我尝试了这两种方法:
1.使用GLSL中的“location”关键字,我写了这个顶点着色器,但在编译这个顶点着色器时仍然遇到问题:
#version 330 core\n
layout (location = 0) in vec3 vertex_position;\n
layout (location = 1) in vec3 vertex_color;\n
layout (location = 2) in vec2 vertex_texcoord;\n
out vs_position;\n
out vs_color;\n
out vs_texcoord;\n
void main() {\n
vs_position = vertex_position;\n
vs_color = vertex_color;\n
vs_texcoord = vec2(vertex_texcoord.x, vertex_texcoord.y*-1.0f);\n
gl_Position = vec4(vertex_position, 1.0f);\n
}
在尝试编译所有这些之后,我从信息日志中得到了这个错误:
0:5(16): 错误:语法错误,意外';',期待'{'。
2-我尝试的另一种尝试是使用“属性”关键字,
相同的代码,但编辑以“布局”字开头的三行:
attribute vec3 vertex_position;\n
attribute vec3 vertex_color;\n
attribute vec2 vertex_texcoord;\n
之后,我使用 glBindAttribLocation() 将属性与它们的位置绑定:
...
m_functions->glBindAttribLocation(vertex_shader, 0, "vertex_position");
m_functions->glBindAttribLocation(vertex_shader, 1, "vertex_color");
m_functions->glBindAttribLocation(vertex_shader, 2, "vertex_texcoord");
m_functions->glAttachShader(shader_program, vertex_shader);
m_functions->glLinkProgram(shader_program);
...
(其中 m_functions 是:
initializeGL() {
m_functions = context->functions();
...}
)
仍然出现同样的错误!
我尝试了上面提到的方法,但都对我不起作用!
我使用的是传统方式(函数以 gl... 开头),而不是使用 Qt 中提供的类!
【问题讨论】: