Taking screenshots of an SDL window.

Discussion in 'Mac Programming' started by Tirhakah, Mar 7, 2009.

  1. Tirhakah macrumors newbie

    Mar 7, 2009
    I've written a project using SDL, and for the testing section of the evaluation I need many screenshots of it. I've been using the built-in mac screencapture (cmd-shift-4), but the default mode (click & drag to select area) means that I need to crop each image to the window borders. I'd far rather use the alternative mode (spacebar to select the whole window), but strangely when I try that I just get a blank window, attached below.
    My question is whether there exists any easy way to get the SDL surfaces to display in the screenshot properly. I've found a couple of ways to output the current screen buffer using SDL, but most of them seem to depend on SDL libraries not easily available for the mac. Also, some of the actions that I need to demonstrate testing (such as resizing the window) wouldn't come across so easily this way.

    (note: yes this is for a school project, but as this doesn't affect the function of the project my tutor confirms it's fine to request help)

    Attached Files:

  2. kainjow Moderator emeritus


    Jun 15, 2000
    Every time you take a screenshot it comes out blank? Even when taking the entire screen? I'm guessing SDL draws via OpenGL, but screenshots should work with OpenGL. I wonder if SDL is using a weird mode that isn't supported by Apple's screenshot tool. You could try the screencapture command-line tool but I'm guessing that is what Apple uses when taking screenshots via the keyboard.
  3. Tirhakah thread starter macrumors newbie

    Mar 7, 2009
    When I take the whole screen, or a selection that includes the SDL window, it all shows up fine. Unfortunately, as I need roughly 60 or so screenshots that means I'd need to crop each of those to include just the window, so I was trying to save time by taking advantage of the feature in screencapture that allows you to capture just the window that the mouse is over, and it's the pictures that come from this that are turning out blank (or rather the edges of the window and the shadow are there, as above, it's just the SDL content that is missing)
  4. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    I'm guessing the keyboard commands do the same thing, but have you tried getting a window with grab?

  5. Tirhakah thread starter macrumors newbie

    Mar 7, 2009
    Just tested with all three: terminal commands, keyboard shortcuts and grab. Any mode which includes more than one window works fine; I guess that it takes the info from the screen's display buffer. However, in all three, trying to capture just the window I need comes up blank.
  6. angelwatt Moderator emeritus


    Aug 16, 2005
    Well as a kind of workaround you can capture the entire screen for now and keep the window you want centered. Then afterwords use Automator to do the cropping for you. I've done this before and it worked nicely. That way you won't have to manually crop them yourself. Just make sure to keep the window being captured in the same spot.
  7. lazydog macrumors 6502a

    Sep 3, 2005
    Cramlington, UK
    Hi Tirhakah

    You might be better off putting the capture directly into your app and activating it through a key combination or something like that. If you're using OpenGL then it's simply a matter of reading pixels directly, glReadPixels(), from your front buffer and then saving them out to a file. If you're not using OpenGL then you can read the screen directly. There is a sample project on the Apple dev site which shows you how to implement a screen capture utility. Sorry I can't remember the name of the project, but one of the files is called OpenGLScreenReader.m/.h. Ah, and yes, you use OpenGL to do the reading!

    b e n

Share This Page