Can the framebuffer of Graphic Card be copy to texture buffer of OpenGL directly?

I want to use the whole Screen of windows(and X Window) as a texture of an opengl program. I do it by grabing the screen first and then puting it to texture buffer, however it is quite slow. I wish I can copy these framebuffer in Graphic Card directly. Is this possible?

glCopyTexSubImage() (which is faster than glCopyTexImage() in nVidia hardware) copies data from GL_READ_BUFFER to the active texture.

So make your window the current read buffer, activate your texture and copy the data over…

But… don’t try to copy the texture to system memory with glGetTexImage() because that will be horribly slow (at least on my hardware it the copies with less than 5MiB/s)

But how to make the current window as the read buffer? I mean the current GUI window or the whole desktop of system.

You must not (cannot) use OpenGL to grab the screen contents of other processes windows. Period. Your approach is doomed.

For that to work you would have to have a valid pixelformat and an OpenGL context on other processes windows including the desktop window and that is not under your control.
Read the chapter about pixelownership in the OpenGL spec!
Even worse, SetPixelFormat works only once during the lifetime of a window. You would need to reboot to clean up the desktop’s pixelformat for a second try if you actually were succesful.
Happy debugging…

Keep using the standard 2D methods to grab the screen and download it to your texture.

Well, there used to be a way to grab the Desktop with OpenGL…
If I remember correctly you can grab the “screen” before doing any clear operation in OpenGL. So, open up a window filling the screen and do a glCopyPixels() befor everything else. Don’t remember if it has to be the front or the back buffer…

Maybe this works for you!

Originally posted by def:
If I remember correctly you can grab the “screen” before doing any clear operation in OpenGL. So, open up a window filling the screen and do a glCopyPixels() befor everything else.
Ick! I wouldn’t go there if I were you. Even if this does turn out to work on your particular machine, the result of such a readback operation is undefined according to the OpenGL spec, and hence is unlikely to be the same on all implementations. It will probably vary from one HW vendor to another, and is even subject to change between driver versions.

Thank you. In fact I do grab the desktop using GUI system call, such as XCopyImage and then put it to opengl texture. I have a dual head graph card GForce 5200, and I grab the GUI of one head and show it in the second. However it’s quite slow – only about 4~5 fps. The most time consuming part is to transfer the frame buffer of GUI to main memory and then put back it to texture buffer. So I want to know can I copy the buffer in the card directly without move them out to main memory?

Originally posted by Relic:
[b]You must not (cannot) use OpenGL to grab the screen contents of other processes windows. Period. Your approach is doomed.

For that to work you would have to have a valid pixelformat and an OpenGL context on other processes windows including the desktop window and that is not under your control.
Read the chapter about pixelownership in the OpenGL spec!
Even worse, SetPixelFormat works only once during the lifetime of a window. You would need to reboot to clean up the desktop’s pixelformat for a second try if you actually were succesful.
Happy debugging…

Keep using the standard 2D methods to grab the screen and download it to your texture.[/b]

Perhaps a mapped PBO (pixel buffer object) can help you out?

Could you do me a favor to give me more detailed advices?

Originally posted by Hampel:
Perhaps a mapped PBO (pixel buffer object) can help you out?