Problem with CUDA/OPENGL Interoperability

Hi!

I have big problem with my OpenGL/CUDA program.

That’s what i have to do:

OpenGL

  1. Compute Vertex

  2. Make Sphere from these vertex

  3. texture this sphere from image read from file

above points i made without any problem.

here is my openGL code:

http://pastebin.com/YH1Gnq7V

I have problem, when i want make interoperability with cuda.

I executed kernel, which computed vertex.

But, when I’m run program, i see only black openGl window…

I have to finish that quickly, because its my school project.

Here is mu CU file with kernel:

http://pastebin.com/eXpNGiRQ

Could someone help me?

I have to finish that quickly…

PS. Sorry for my english, I’m foreigner

You’re using a number of CUDA functions I’m unfamiliar with, but I can show you how I to OpenGL interop. Creat the context:

cudaSetDevice( cutGetMaxGflopsDeviceId() );

cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() );

Create a buffer in OpenGL and register it:

// Create a pixel unpack buffer to store the perspective texture

glGenBuffers ( 1, &glPerspectiveBufferPos );

glBindBuffer ( GL_PIXEL_UNPACK_BUFFER, glPerspectiveBufferPos );

glBufferData( GL_PIXEL_UNPACK_BUFFER, GL_IMAGE_SIZE, 0, GL_DYNAMIC_COPY );

glBindBuffer ( GL_PIXEL_UNPACK_BUFFER, 0);

// set pixel alignments

glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );

glPixelStorei ( GL_PACK_ALIGNMENT, 1 );

// register buffer object with CUDA

cutilSafeCall ( cudaGLRegisterBufferObject( glPerspectiveBufferPos ));

glut Idle func I do some operation on the buffer:

unsigned char *perspectiveCudaGlBuf;

cutilSafeCall( cudaGLMapBufferObject( (void**)&perspectiveCudaGlBuf, glPerspectiveBufferPos ) );

// some stuff with perspectiveCudaGlBuf as a device memory pointer

// unmap buffer object

cutilSafeCall( cudaGLUnmapBufferObject( glPerspectiveBufferPos ) );

And glut display just use the OpenGL texture buffer as normal:

// bind the perspective texture to the active GL texture

glBindBuffer ( GL_PIXEL_UNPACK_BUFFER, glPerspectiveBufferPos );

glTexImage2D ( GL_TEXTURE_2D, 0, 4 /* RGBA */, GL_IMAGE_WIDTH, GL_IMAGE_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0 );	

glBindBuffer ( GL_PIXEL_UNPACK_BUFFER, 0 );

// first draw the perspective texture

glBegin ( GL_QUADS );

	glTexCoord2f ( 1, 1 );   glVertex2f ( GL_IMAGE_WIDTH, GL_IMAGE_HEIGHT );

	glTexCoord2f ( 1, 0 );   glVertex2f ( GL_IMAGE_WIDTH, 0.0 );

	glTexCoord2f ( 0, 0 );   glVertex2f ( 0.0, 0.0 );

	glTexCoord2f ( 0, 1 );   glVertex2f ( 0.0, GL_IMAGE_HEIGHT );

glEnd();