I want to draw a textured quad but there is nothing drawn and the setup should be right. This is my vertex shader:
#version 330
in vec2 position;
in vec2 texel;
out vec2 texCoord;
void main() {
texCoord = texel;
gl_Position = vec4(position, 0.0, 1.0);
}
This code is producing no output on screen. Now comes the crazy stuff. If I add the following,
#version 330
in vec2 position;
in vec2 texel;
in vec2 foo;
out vec2 texCoord;
void main() {
texCoord = texel;
gl_Position = vec4(position + foo, 0.0, 1.0);
}
everything is as it should be.
I am pretty sure that my setup is correct. I have checked the values of the vertex attributes by passing them as texCoord instead of the uv coordinates, and assigning them to my fragment color output in the fragment shader. In both cases this produces the expected color gradient. The extra uninitialized attribute foo must be zero, because its rendered as the vertex color.
So the thing is, nothing is drawn unless I add an vertex attribute to position. It doesn't matter if I add texel or the mysterious, uninitialized vertex attribute. The output is the same.
update:
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), sizeof(glm::vec2);
This is my vertex struct:
struct Vertex {
glm::vec3 pos;
glm::vec2 tex;
glm::vec3 normal;
Vertex(const glm::vec3& _pos,const glm::vec2& _tex,const glm::vec3& _normal):
pos(_pos),tex(_tex),normal(_normal){}
Vertex(const Vertex&)=default;
Vertex& operator=(const Vertex&)=default;
};
The buffer is correct. I have mapped the vertex buffer and put it on the standard output. All numbers are correct.