Reputation: 391
I am using Qt 5.13 with opengl 4.4 and 3.3 for GLSL in a Unix 19.04 operating system.
Note that I am using the QOpenGLWindow as a mainwindow for the Qt application.
I am trying to link the input of opengl vertex-shader correctly. I tried these two ways :
1.Using the "location" keyword in GLSL, I wrote this vertex shader and still having a problem when trying to compile this vertex shader :
#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
}
After trying to compile all of this, I got this error from the infolog :
0:5(16): error: syntax error, unexpected ';', expecting '{'.
2-The other attempt that I tried out is using 'attribute' keyword,
Same code but editing the three lines starting with 'layout' word :
attribute vec3 vertex_position;\n
attribute vec3 vertex_color;\n
attribute vec2 vertex_texcoord;\n
After that, I used glBindAttribLocation() to bind the attributes with their locations :
...
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);
...
(Where m_functions is :
initializeGL() {
m_functions = context->functions();
...}
)
And still getting the same error!
I tried the mentioned ways above, but both didn't work for me!
I am using the traditional way (functions starting with gl...), not using the classes that are provided in Qt!
Upvotes: 2
Views: 416
Reputation: 211135
The error is not related to the layout location qualifier or the vertex shader input variables respectively attributes.
But the type specification is missing in the declaration of the vertex shader output variables:
out vs_position; out vs_color; out vs_texcoord;
It has to be:
out vec3 vs_position;
out vec3 vs_color;
out vec2 vs_texcoord;
Note, 0:5(16)
in the error message 0:5(16): error: syntax error, unexpected ';', expecting '{'.
. means the 5th line and the 16th sign.
The 16th sign in the 5th line is the semicolon (;
), which is unexpected, because out vs_position
is not a valid declaration.
Upvotes: 2