I’m trying to pass attributes of vertices in my application to the vertex shader.
Here is the code for attribute passing:
GLuint inCentroidNormal =
vec4 * centroidNormals = (*it)->getFlatShadingNormals();
GLsizei totalNormals = (*it)->getFlatShadingNormalsSize();
glVertexAttribPointer(inCentroidNormal, 4, GL_FLOAT, GL_FALSE, 0,0);
But it is quite obvious from the output of the program that the outputs do not pass correctly since the color of the rendered triangle is different from what I expect, and when I hardcode into the shader, I DO get the expected result, so obviously the data is not passing as I expect it…
Is there anything wrong with the way I pass the vertex attribute “centroidNormal”?
The single vertex array I use is bound at the top of the code…
it’s looks correct to me… but it’s the only attribute that you pass?
No position, no color, no uv? My fear is that you are binding different buffer data for the same drawcall.
In that case you have to search the error elsewhere.
Try to read this if you didn’t already
I definitely bind more vertex attributes.
For each of them I use the same set of calls, indeed.
For the normals above, there are also the centroids of the triangles from wich the normals are emitting.
Position of eachvertex is passed also. And indeed I’m binding buffer data using different buffers for the same draw call.
Actually three attributes of each vertex are passed using different buffer objects. What can be the problem with that?
When I tried using glVertexAttrib4f(…) it worked, though it was as if all the triangles had the same normals, it was correct because I rendered a single triangle…
All the data is of type vec4…
I was wrong, as the specifics say (2.9.6) data can be read from different buffers, I never tried it. I prefer to pack vertex data in a single buffer, is more cache friendly.
Before drawing try to check:
glGetVertexAttribIuiv(inCentroidNormal, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, *returnValue);
assert(returnValue == buffer[TNORMAL_BUFFER_IDX]);
other check you can do…
is totalNormals == number of vertex you draw?
check is glGetError return some error.
Without more information I can’t say anything.
It was something different.
actually in the shader I treated a vertex attribute declared as:
in vec4 vSomeAttrib
as a global veriable in a user defined function which had to calculate the vertex color relying on the light sources (uniform array) and the material oqualities (declared as varying “in” variable). For some reason when I passed the varying variable as a parameter to the function the results were as expected.
Thanks a lot for the assistance.