something wrong with OpenGL interoperate

My kernel function needs to get the OpenGL buffer data to do something…
When I call the “cudaGLRegisterBufferObject”…
It shows “Cuda error in file ‘OK.cu’ in line 383 : invalid resource handle.”
I have checked it for many times…
But…nothing happened… External Image

Does anyone know how to solve it…?

*************** My Program ********************

============= Host =================

//*** Create 2 OpenGL Buffer Object and ***//
GLuint *texname = NULL ;
texname = (GLuint )malloc(2sizeof(GLuint));
glBindTexture(GL_TEXTURE_2D, texname[0]);
glBindTexture(GL_TEXTURE_2D, texname[1]);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
UNSIGNED_BYTE, Image_1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
GL_UNSIGNED_BYTE, Image_2);
.
.
.

//*** call function from *.cu ***//
Test_cu_function (texname ) ;

//============ *.cu ==================

void Test_cu_function (GLuint *Tex )
{
CUDA_SAFE_CALL(cudaGLRegisterBufferObject(Tex [0])); //<—ERROR
CUDA_SAFE_CALL(cudaGLRegisterBufferObject(Tex [0]));
.
.
}

Hi, you are using the interoperability in a wrong way. The ‘postProcessGL’ example of the SDK explains how to use the interoperability with OpenGL

I have checked “postProcessGL” project and
tested my program for many times…
But the problem still existed…

My OpenGL Texture memory is 2D…
So…that’s because I can’t call the “cudaGLRegisterBufferObject” successfully?

:sad:

cudaGLRegisterBufferObject needs a pixelBufferObject as a parameter, not a texture name.

You have to create a pixel buffer object and copy the image to it.

GLuint* bufferObject;

glGenBuffers(1, bufferObject);

glBindBuffer(GL_ARRAY_BUFFER, *bufferObject);

glBufferData(GL_ARRAY_BUFFER, memSize, NULL, GL_DYNAMIC_DRAW);