CUDA to OpenGL texture

I have an image in a CUDA pointer object thingy (or whatever the correct lingo is) and I want to either use it as an OpenGL texture or copy it to a texture but mapping a texture gives me some strange “cudaArray” thing that I cant do anything with, I have tried various methods of copying the data to it but nothing works.

So how do I copy data from CUDA to a mapped OpenGL texture? thanks.

one possible method is covered here. That doesn’t depend on cudaArray.

If you wish to copy directly to an underlying cudaArray resource, a possible method is covered here

You may want to look at various CUDA sample codes such as simpleCUDA2GL and others.

I setup the texture like this:
glGenTextures(1, &m_iTexture);
glBindTexture(GL_TEXTURE_2D, m_iTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nImageWidth, nImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, whiteimg);
cudaGraphicsGLRegisterImage(&resource, m_iTexture, GL_TEXTURE_2D, cudaGraphicsRegisterFlagsNone);

texture parameters omitted

and attempt to copy to it like this every frame:
cudaGraphicsMapResources(1, &resource);
cudaArray* texarray;
cudaGraphicsSubResourceGetMappedArray(&texarray, resource, 0, 0);
auto width = 0;
auto height = 0;
GrabFrame(&width, &height);
CopyFrame(texarray);
cudaGraphicsUnmapResources(1, &resource);

where CopyFrame is this:
cudaMemcpy2DToArray(texarray, 0, 0, reinterpret_cast<void*>(pDevGrabBuffer), frameGrabInfo.dwWidth*4, frameGrabInfo.dwWidth*4, frameGrabInfo.dwHeight, cudaMemcpyDeviceToDevice);

but the original white image remains.

Problem solved, not quite sure how I fixed it.

Following cudaGraphicUnmapResources() it supposed to be a process that would draw this new texure to replace that original white image.

If you had done that, then nothing looks problematic. Maybe you can copy texarray to host and see if the CopyFrame done successfully.

That is not complete code, as I said I fixed it.