Rendering Kinect Point Cloud com Vertex Buffer Object (VBO)
Estou tentando criar um visualizador dinâmico de nuvens de pontos. Os pontos são atualizados a cada quadro com o Kinect Sensor. Para pegar os quadros, estou usando o OpenCV e o GLUT para exibir. A API do OpenCV retorna 640 x 480 (flutuante *), para a posição xyz dos pontos, e 640 x 480 (int *) para os dados de cores rgb. Para obter o máximo desempenho, estou tentando usar o objeto de buffer do vértice no modo de fluxo em vez de uma simples matriz de vértices. Estou conseguindo renderizá-lo com o Vertex Array, mas nada está sendo renderizado com minha implementação do VBO. Tentei várias ordens diferentes nas declarações, mas não consigo encontrar o que está faltando. Alguém pode tentar me indicar a direção certa? Aqui está o código simplificado: (Reescrevi a versão errada, conforme solicitado por Christian Rau, para que vocês possam entender meus erros)
int main()
{
//Delaring variables, inittiating glut, setting camera and checking the compatibility as http://www.songho.ca/opengl/gl_vbo.html
glutDisplayFunc(displayCB);
glutIdleFunc(displayCB);
...
//Inittiating the vertex buffers
if(vboSupported)
{
glGenBuffers(1, &vertex_buffer);
glBindBuffer(GL_ARRAY_BUFFER_ARB, buffer);
glBufferData(GL_ARRAY_BUFFER_ARB, (sizeof(GLfloat) * 640 * 480 * 3), 0, GL_STREAM_DRAW_ARB);
glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, (sizeof(float) * 640 * 480 * 3), point_cloud.points_position);
glGenBuffers(2, &color_buffer);
glBindBuffer(GL_ARRAY_BUFFER_ARB, buffer);
glBufferData(GL_ARRAY_BUFFER_ARB, (sizeof(GLbyte) * 640 * 480 * 3), 0, GL_STREAM_DRAW_ARB);
glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, (sizeof(char) * 640 * 480 * 3), point_cloud.points_color);
}
//glutMainLoop(), cleaning memory, ending main
..
}
//Updating the screen
void displayCB()
{
point_cloud.update();
// clear buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
// save the initial ModelView matrix before modifying ModelView matrix
glPushMatrix();
glBindBuffer(GL_ARRAY_BUFFER_ARB, color_buffer);
glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, (sizeof(char) * 640 * 480 * 3), point_cloud.points_color);
glColorPointer(3, GL_UNSIGNED_BYTE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER_ARB, vertex_buffer);
glBufferSubData(GL_ARRAY_BUFFER_ARB, 0, (sizeof(float) * 640 * 480 * 3), point_cloud.points_position);
glVertexPointer(3, GL_FLOAT, 0, 0));
// enable vertex arrays
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_POINT, 0, 640*480);
glDisableClientState(GL_VERTEX_ARRAY); // disable vertex arrays
glDisableClientState(GL_COLOR_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);
glPopMatrix();
glutSwapBuffers();
}