Copying the screen to a cuda context

I’m trying to find out how to copy the full screen (or more generally each of the two screens in a two screen system) to something that CUDA can access. I need to do some processing of the screen data and later on send it back to the cpu (CUDA post processing of the actual screen image). I understand from the references I found that this involves at least one copy (good for me since the screen would still be drawing during processing, probably with OpenGL, in a different context I don’t have access to) which I would rather keep inside the gpu without passing it to the cpu first.

I don’t know OpenGL which doesn’t help and I understand that CUDA doesn’t have direct access to the screen. I found some references about getting OpenGL rendering context into CUDA but can’t seem to find anything about reading the actual screen with OpenGL or how to copy the result into CUDA.

I tried as an initial test to use glReadPixels to try to get the data into the CPU to see that I’m reading something before looking at communicating with CUDA but that returns an empty buffer as well.

I’ll be thankful for some examples/pointers or at least references regarding what I should be looking for.

Thanks