Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: Grab the screen, make a a smaller version of it in a texture

  1. #1
    Intern Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66

    Grab the screen, make a a smaller version of it in a texture

    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?

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    If you want to use GLU, it has a function call gluScaleImage.
    My library also has scale function glhScaleImage_asm386.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  3. #3
    Intern Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66
    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.

  4. #4
    Intern Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66
    Oh, one other thing, just thought I'd post a link to the algorithm I found online. Here it is:

    http://tech-algorithm.com/articles/n...image-scaling/

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,181
    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.

  6. #6
    Intern Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66
    Well, I'm actually doing the scaling of the screen image in my initRendering function. Why would gluScaleImage be inappropriate during run-time?

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,181
    Quote Originally Posted by vindy View Post
    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.

  8. #8
    Intern Contributor
    Join Date
    May 2011
    Location
    Alabama, USA
    Posts
    66
    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 vindy1099@hotmail.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.

  9. #9
    Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    268
    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).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •