View Full Version : Grab the screen, make a a smaller version of it in a texture
08-03-2012, 09:47 PM
Hello everyone. This is what I would like to accomplish: Use glReadPixels to grab what's currently on the screen into a texture and then shrink that texture by a certain factor. The degree to which it shrinks horizontally and vertically may be different so the aspect ratio may not be preserved. Any ideas on how to go about doing this?
08-05-2012, 10:30 AM
If you want to use GLU, it has a function call gluScaleImage.
My library also has scale function glhScaleImage_asm386.
08-05-2012, 11:47 AM
Cool! Thanks V-man! I also discovered an algorithm, probably older than I am, that uses nearest-neighbor sampling to accomplish scaling up or down of an image. Thank you for all your help.
08-05-2012, 11:50 AM
Oh, one other thing, just thought I'd post a link to the algorithm I found online. Here it is:
08-05-2012, 02:33 PM
Do you want to do this at run-time? gluScaleImage or any other method that requires reading from the framebuffer is going to be hugely inappropriate if so.
08-05-2012, 07:43 PM
Well, I'm actually doing the scaling of the screen image in my initRendering function. Why would gluScaleImage be inappropriate during run-time?
08-05-2012, 07:53 PM
Why would gluScaleImage be inappropriate during run-time?
Because it's too slow.
It's not so much gluScaleImage as it is the glReadPixels call that will be the cause of trouble at runtime (although gluScaleImage is unlikely to be well-optimized either); the way things work is that your GPU and your CPU operate asynchronously. If you try to read data back from your GPU you'll break that. Also consider that what you're doing is moving data from GPU memory to system memory and then back to GPU memory - much more efficient to leave it in GPU memory throughout the entire operation.
One way of doing this that's compatible with older hardware is to use the glCopyTexSubImage function. At startup you create a large texture, the size of your screen (or the next powers of two above it if your hardware doesn't support non-power-of-two textures). Then each frame you would call glCopyTexSubImage to copy the framebuffer to a texture. For more modern hardware you should look at framebuffer objects.
08-06-2012, 04:40 AM
Thanks mhagain. That's something I had not considered. I'll look into it. Hey, do you guys have a windows live messenger account. It would be cool to have a couple of contacts to message with who are into graphics programming. If you have a windows live account and want to add me as a friend my name is Benjamin Barrett and the email associated with me is email@example.com If you have some other instant messenger program and are open to the idea let me know what it is and your username and I'll download the program so we can chat sometime. Well, anyhow, thanks for everything guys.
08-06-2012, 07:50 AM
If you can use GL3.0 (or compatibile) then glBlitFramebuffer is the way to go, it will do everything for you in one step (both copying the content to the texture and scaling it).
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.