Hi OpenGL community!
I’m trying to instancing geometry. I’ve found this very good tutorial:
http://sol.gfxile.net/instancing.html
In the last example (ARB_instanced_arrays), the code is!
int pos = glGetAttribLocation(shader_instancedarrays.program, "transformmatrix");
int pos1 = pos + 0;
int pos2 = pos + 1;
int pos3 = pos + 2;
int pos4 = pos + 3;
glEnableVertexAttribArray(pos1);
glEnableVertexAttribArray(pos2);
glEnableVertexAttribArray(pos3);
glEnableVertexAttribArray(pos4);
glBindBuffer(GL_ARRAY_BUFFER, VBO_containing_matrices);
glVertexAttribPointer(pos1, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4 * 4, (void*)(0));
glVertexAttribPointer(pos2, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4 * 4, (void*)(sizeof(float) * 4));
glVertexAttribPointer(pos3, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4 * 4, (void*)(sizeof(float) * 8));
glVertexAttribPointer(pos4, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4 * 4, (void*)(sizeof(float) * 12));
glVertexAttribDivisor(pos1, 1);
glVertexAttribDivisor(pos2, 1);
glVertexAttribDivisor(pos3, 1);
glVertexAttribDivisor(pos4, 1);
There is a glBindBuffer so I suppose it send his matrices to a VBO before (there is not this part of the code…).
So I’m trying to sending my std::vector<Imath::M44f > so I’m doing like this:
glBufferData(GL_ARRAY_BUFFER, 16*sizeof(GLfloat)matrixArray.size(), (GLvoid)&matrixArray[0].x, GL_STATIC_DRAW);
And it crash there…
I’ve tryed many combination:
(GLvoid*)&matrixArray[0].x
(GLvoid*)&matrixArray[0].x[0]
(GLvoid*)&matrixArray[0].x[0][0]
But this still don’t work…
If I don’t use VBO:
int pos = glGetAttribLocation(shader_instancedarrays.program, "transformmatrix");
int pos1 = pos + 0;
int pos2 = pos + 1;
int pos3 = pos + 2;
int pos4 = pos + 3;
glEnableVertexAttribArray(pos1);
glEnableVertexAttribArray(pos2);
glEnableVertexAttribArray(pos3);
glEnableVertexAttribArray(pos4);
/*glBindBuffer(GL_ARRAY_BUFFER, VBO_containing_matrices);*/
glVertexAttribPointer(pos1, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4 * 4, (GLvoid*)&matrixArray[0].x[0]);
glVertexAttribPointer(pos2, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4 * 4, (GLvoid*)&matrixArray[0].x[1]);
glVertexAttribPointer(pos3, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4 * 4, (GLvoid*)&matrixArray[0].x[2]);
glVertexAttribPointer(pos4, 4, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 4 * 4, (GLvoid*)&matrixArray[0].x[3]);
glVertexAttribDivisor(pos1, 1);
glVertexAttribDivisor(pos2, 1);
glVertexAttribDivisor(pos3, 1);
glVertexAttribDivisor(pos4, 1);
This work!
Problem with std::vector<Imath::M44f > format?
Any idea?