I want to draw instanced figures, using glDrawElementsInstanced. So I set Uniform buffer block that way:
struct data
{
float px, py, pz;
};
static data *buffer;
buffer = new data[100];
for(int i = 0; i < 10; i++)
{
for(int j = 0; j < 10; j++)
{
static int a = 0;
buffer[a].px = float(i);
buffer[a].py = float(j);
buffer[a].pz = 0.0f;
a++;
}
}
glGenBuffers(1, &bufd);
glBindBuffer(GL_UNIFORM_BUFFER, bufd);
glBufferData(GL_UNIFORM_BUFFER,
sizeof(buffer),
buffer,
GL_DYNAMIC_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, bufd);
And after this in vertex shader Uniform block is empty. All figures draw in the same place, like all of the have world coord 0.0, 0.0, 0.0. My Vertex shader:
#version 430
in vec4 position;
struct lol//lack of idea
{
vec3 pozycja;//pozycja means position
};
layout (binding = 0) uniform dane
{
lol bufin[100];
};
layout ( location = 0 ) uniform mat4 proj_matrix;
layout ( location = 1 ) uniform mat4 camera_matrix;
void main(void)
{
mat4 mv_matrix = {vec4(1.0, 0.0, 0.0, 0.0),
vec4(0.0, 1.0, 0.0, 0.0),
vec4(0.0, 0.0, 1.0, 0.0),
vec4(bufin[gl_InstanceID].pozycja, 1.0)};
gl_Position = proj_matrix * camera_matrix * mv_matrix * position;
}