OpenGL and CUDA 3.0+

Hello,

I’ve been looking over the OpenGL interoperability section of the CUDA Programming Guide for CUDA 4.0, and have a few questions; specifically, in section 3.3.13.1 (OpenGL Interoperability), there’s a small code sample demonstrating the use of a cuda kernel to “dynamically modify a 2D width x height grid of vertices stored in a vertex buffer object”. My question centers around the following excerpt from the code section:

// Create buffer object and register it with CUDA 

glGenBuffers(1, positionsVBO); 

glBindBuffer(GL_ARRAY_BUFFER, &vbo); 

unsigned int size = width * height * 4 * sizeof(float); 

glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW); 

glBindBuffer(GL_ARRAY_BUFFER, 0); 

cuGraphicsGLRegisterBuffer(&positionsVBO_CUDA, positionsVBO, cudaGraphicsMapFlagsWriteDiscard);

This is the first (and only) reference to the “vbo” variable; is this a typo, and it should instead be positionsVBO, or should it indeed be a completely different GLuint variable?

Also, what does the second call to “glBindBuffer” do? Is it for the 2nd buffer used in double buffering?

I have next to no experience with OpenGL, so I apologize ahead of time if these questions are nonsensical.

I was reading a very good modern OpenGL tutorial yesterday. I a newbie on OpenGL also. It has the answers you are looking for,

The OpenGL way of manipulating objects(either buffer objects or texture objects) is defined in that way, you need to glGens first and glBind.

That’s a very good read, thanks for the link.

One more question concerning the Programming Guide’s OpenGL Interoperability, Driver API section; in the code example, it calls “cuGLCtxCreate” prior to creating it’s OpenGL window/OpenGL context. In my experience, this doesn’t work. Is this further evidence that I’m an idiot, or is this section of the programming guide flawed?

Thanks…

Thank you for bringing this documentation issue to our attention. It will be fixed in the 4.1 version of the guide.