PDA

View Full Version : glVertexAttrib4fv not working?



andrewtomazos
02-22-2015, 02:51 PM
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?

mhagain
02-22-2015, 03:58 PM
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.

andrewtomazos
02-22-2015, 05:01 PM
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.

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

Alfonse Reinheart
02-22-2015, 05:49 PM
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?

andrewtomazos
02-22-2015, 06:34 PM
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: http://www.developerit.com/2013/10/29/opengl-glvertexattrib4fv-doesnt-work

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

Betrayal
02-22-2015, 10:43 PM
I have tried `layout (location = 0)` as well as `glBindAttribLocation`, neither works.

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)

andrewtomazos
02-23-2015, 01:00 AM
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)

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.

Betrayal
02-23-2015, 01:20 AM
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:
https://www.opengl.org/discussion_boards/showthread.php/185643-sampler-object-bound-to-unit-0-affects-other-units