void GLWidget::initializeGL(){ glClearColor(0.0, 0.0, 0.0, 1.0); glDisable(GL_DEPTH_TEST); // viewport glViewport(0, 0, window_width, window_height); // projection glMatrixMode(GL_PROJECTION); glLoadIdentity(); initglew(); createVBO(&vboPos, &cuda_vbo_resource_pos,2); createVBO(&vboColor, &cuda_vbo_resource_color,2); runCudaPos(&cuda_vbo_resource_pos); runCudaColor(&cuda_vbo_resource_color);}
void runCudaColor(struct cudaGraphicsResource **vbo_resource){ float4 *dptr; checkCudaErrors(cudaGraphicsMapResources(1, vbo_resource, 0)); size_t num_bytes; checkCudaErrors(cudaGraphicsResourceGetMappedPointer((void **)&dptr, &num_bytes, *vbo_resource)); launch_kernel_color(dptr, dmesh_width, dmesh_height, g_fAnim); // unmap buffer object checkCudaErrors(cudaGraphicsUnmapResources(1, vbo_resource, 0));}
void display(GLuint *vboPos, GLuint *vboColor){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set view matrix glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // render from the vbo glEnableClientState ( GL_VERTEX_ARRAY ); glBindBuffer(GL_ARRAY_BUFFER, *vboPos); glVertexPointer(4, GL_FLOAT, 0, 0); glEnableClientState ( GL_COLOR_ARRAY ); glBindBuffer(GL_ARRAY_BUFFER, *vboColor); glColorPointer(4, GL_FLOAT, 0, 0); //glColor3f(1.0, 0.0, 0.0); glDrawArrays(GL_POINTS, 0, dmesh_width * dmesh_height); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_COLOR_ARRAY); }void GLWidget::paintGL(){ display(&vboPos, &vboColor); swapBuffers();}