glVertexAttrib4fv not working?

I have a toy vertex shader like so:

#version 430 core

uniform float offset;

void main(void) {
const vec4 v[3] = vec4[3](vec4( 0.25, -0.25, 0.5, 1.0),
vec4(-0.25, -0.25, 0.5, 1.0),
vec4( 0.25, 0.25, 0.5, 1.0));
gl_Position = v[gl_VertexID];
gl_Position.x += offset;
}

And when I set the variable with glUniform before called glDrawArrays, it works.

I then change to using in instead of uniform:

#version 430 core

in float offset;

void main(void) {
const vec4 v[3] = vec4[3](vec4( 0.25, -0.25, 0.5, 1.0),
vec4(-0.25, -0.25, 0.5, 1.0),
vec4( 0.25, 0.25, 0.5, 1.0));
gl_Position = v[gl_VertexID];
gl_Position.x += offset;
}

and use glVertexAttrib to set the variable, it doesn’t work. glDrawArrays silently doesn’t render anything.

Any ideas?

Wrong attrib location.

You’re not using explicit attrib locations so you should be calling glBindAttribLocation and remembering to do so before linking your program.

[QUOTE=mhagain;1264509]Wrong attrib location.

You’re not using explicit attrib locations so you should be calling glBindAttribLocation and remembering to do so before linking your program.[/QUOTE]

I have tried layout (location = 0) as well as glBindAttribLocation, neither works.

glDrawArrays silently doesn’t render anything.

What proof do you have that it’s not executing your vertex shader? That is, what happens if you take away the attribute usage and rely solely on gl_VertexID?

If I remove the offset, it renders as expected. If I use a uniform offset, it renders as expected. It is only when I use and try to set and read an in attribute with glVertexAttrib it does not work. I could believe it is running, but reading garbage from the in attribute hence translating by some large random vec4 and putting the offset outside the clipping area. The question is why doesn’t the data get grom glVertexAttrib to the in attribute.

It’s the same problem this person is having I think: Opengl glVertexAttrib4fv doesn't work? - Developer IT

I am trying to do the first exercise in the OpenGL SuperBible 6th ed.

Do you have by any chance a AMD GPU?
Then try another location != 0. There seems to be a driver bug for some data at location 0.

(And don’t forget to use this locationindex in glVertexAttrib as well)

[QUOTE=Betrayal;1264513]Do you have by any chance a AMD GPU?
Then try another location != 0. There seems to be a driver bug for some data at location 0.

(And don’t forget to use this locationindex in glVertexAttrib as well)[/QUOTE]

Holy cow. Betrayal for the win! Yes, I have AMD Radeon HD 7900. Location 0 doesn’t work. Changing to layout (location = 1) works. OMG, I’ve been beating my head on that one for hours.

Glad i could help.
I stumpled across this problem (same Superbible code) some time ago and also wasted hours. Found a solution by pure luck and reported it to AMD, but they don’t seem to care.

There is another Problem with AMD Drivers and Sampler Objects, keep this in mind when further reading Superbible 6: