Hi all, I’m trying to write a cuda path tracer and use opengl to display the renderer results. This is the tutorial I’m following. So I stored my results as a cuda built-in float3 pointer, the x and y values are the pixel coordinate values, the z value is the RGBA value, but stored as a float. Then I mapped that to a VBO.
I was using nsight graphics to debug, and I can see that the VBO stores the correct values, but somehow I can’t draw it. Does anyone have a clue? Thanks for the help!
GLuint vbo;
float3* finaloutputbuffer = NULL; // The pointer to store the xy coordinate as xy and RGBA color as z
// Initialize VBO
void createVBO(GLuint* vbo)
{
//Create vertex buffer object
glGenBuffers(1, vbo);
glBindBuffer(GL_ARRAY_BUFFER, *vbo);
//Initialize VBO
unsigned int size = scr_width * scr_height * sizeof(float3);
glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//Register VBO with CUDA
cudaGLRegisterBufferObject(*vbo);
}
// The display function
void disp(void) {
cudaDeviceSynchronize();
cudaGLMapBufferObject((void**)&finaloutputbuffer, vbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
render_gate(finaloutputbuffer);
cudaDeviceSynchronize();
cudaGLUnmapBufferObject(vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexPointer(2, GL_FLOAT, 12, (GLvoid*)0);
glColorPointer(4, GL_UNSIGNED_BYTE, 12, (GLvoid*)8);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glDrawArrays(GL_POINTS, 0, scr_width * scr_height);
glDisableClientState(GL_VERTEX_ARRAY);
glutSwapBuffers();
}