I'm trying to get some float values to my vertex shader on a per vertex basis - the float value will define the size of gl_PointSize for rendering
Here is my shader:
attribute float vSpacial;
void main(void)
{
gl_FrontColor = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_PointSize = vSpacial;
}
Here is how I set up the buffers for the verts, colours, and "spacial" point size information:
GLint spacial = glGetAttribLocation(program, "vSpacial");
float spacialData[] = {11.0f, 50.0f, 100.0f};
GLuint VBO;
glGenBuffers(1, &VBO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(positions), &positions, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
GLuint CBO;
glGenBuffers(1, &CBO);
glBindBuffer(GL_ARRAY_BUFFER, CBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(colors), &colors, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
GLuint SPO;
glGenBuffers(1, &SPO);
glBindBuffer(GL_ARRAY_BUFFER, SPO);
glBufferData(GL_ARRAY_BUFFER, sizeof(spacial), &spacial, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
and here is how I'm rendering:
// Set up projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45, 1024.0/768.0, 1, 1000);
// Set up camera view
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,0,-5,
0,0,0,
0,1,0);
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// ---
glUseProgram(program);
glPushMatrix();
glRotatef( theta, 0.0f, 0.0f, 1.0f );
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnable(GL_PROGRAM_POINT_SIZE);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glVertexPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glBindBuffer(GL_ARRAY_BUFFER, CBO);
glColorPointer(3, GL_FLOAT, 0, BUFFER_OFFSET(0));
glBindBuffer(GL_ARRAY_BUFFER, SPO);
glEnableVertexAttribArray(spacial);
glVertexAttribPointer(spacial, 1, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glDrawArrays(GL_POINTS, 0, 3);
glDisableVertexAttribArray(spacial);
glDisable(GL_PROGRAM_POINT_SIZE);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glPopMatrix();
// ---
glFlush();
SwapBuffers( hDC );
theta += 1.0f;
Currently I see nothing rendering - If I comment out the line glBindBuffer(GL_ARRAY_BUFFER, SPO); I will see one point being rendered by itself (not using the spacial value I pass in).