I'm trying to pass a bunch of consecutive unsigned ints as attribute to my GLSL shader.
So far I came up with
s_number = glGetAttribLocation(shader, "number");
numberData = new GLuint[dotAmount];
for (GLuint i = 0; i < dotAmount; i++) {
numberData[i] = i;
}
glGenBuffers(1, &vertBuf);
glBindBuffer(GL_ARRAY_BUFFER, vertBuf);
glBufferData(
GL_ARRAY_BUFFER,
sizeof(dotAmount),
numberData,
GL_STATIC_DRAW
);
The rendering function is
glUseProgram(shader);
[..]
glEnableVertexAttribArray(s_number);
glBindBuffer(GL_ARRAY_BUFFER, vertBuf);
glVertexAttribPointer(
s_number,
1,
GL_UNSIGNED_INT,
GL_FALSE,
0,
BUFFER_OFFSET(0)
);
glDrawArrays(GL_POINTS, 0, dotAmount);
I try to use the number in the vertex shader like this:
attribute uint number;
(The name 'vertBuf' is actually a bit misleading since it's not vertex data I want to pass)
I'm using OpenGL 3 and shader versions 1.3.
What I am trying to achieve is, I want the shaders to be executed dotAmount
times. The positioning is done mathematically within the shader. But all I get is a blank screen...
I am quite sure that the problem does not lie in the shaders. I want to draw points, and if I put gl_Position = vec4(0.0, 0.0, 0.0, 0.0);
in the vertex shader, I assume it should draw something.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…