OF_FULLSCREEN screenshots fail on Windows - fix?

If I set ofSetupOpenGL(1400, 1000, OF_FULLSCREEN); in WinMain on Windows, then when I press Print Screen to take a screenshot, it shows the very first frame drawn (the image from the first time ofApp::Draw() was called), not the current frame.

If I switch to OF_WINDOW mode, then it will save a current screenshot as expected.

Is there a way to avoid this behavior, and so be able to take screenshots in OF_FULLSCREEN mode using the Print Screen key?

hey @Drazinut,
EDIT: sorry, I think I misunderstood your problem… That seems the same that you are doing.

you can get more info on the key events like this:
(and then to save the screenshot like that or using another faster-threaded method)

//void ofApp::keyPressed(int key) {
void ofApp::keyPressed(ofKeyEventArgs &eventArgs) {
	const int key = eventArgs.key;
	const int keycode = eventArgs.keycode;
	const int scancode = eventArgs.scancode;
	const uint32_t codepoint = eventArgs.codepoint;

    cout << endl; 
	cout << __FUNCTION__ << " key: " << key << endl;
	cout << __FUNCTION__ << " keycode: " << keycode << endl;
	cout << __FUNCTION__ << " scancode:" << scancode << endl;
	cout << __FUNCTION__ << " codepoint:" << codepoint << endl;

	if (key == 0 && keycode == 283 && scancode == 311 && codepoint == 0) {
		cout << __FUNCTION__ << "Pressed [print screen] key" << endl;

		//take screenshot
			ofImage img;
			img.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
			string _pathFolder = "captures/";
			string _fileName = "snapshot_" + ofGetTimestampString() + ".png";
			string _pathFilename = ofToDataPath(_pathFolder + _fileName, true);//bin/data
			bool b = img.save(_pathFilename);
			if (b) cout << __FUNCTION__ << " Saved screenshot successfully: " << _pathFilename << endl;
			else cout << __FUNCTION__ << " Error saving screenshot:" << _pathFilename << endl;
1 Like

Thanks for providing that code!

I expect it will work to use that grabScreen & save technique.

I wasn’t actually doing anything like that. I was just talking about Windows’ built-in PrintScreen key behavior, which for some reason in OF_FULLSCREEN mode is ending up with a screenshot of the first frame the program drew, instead of the current screen, unlike what it does on MacOS (or in Windows when in windowed mode), where it gets the current screen image.

Just to update my own thread in a way that may hopefully be useful to others.

This WAS working fine, until I switched to ofSetBackgroundAuto(false), which makes screenshots not work again in a similar way.

I searched for the issue, found several threads, the most helpful of which I found had a suggestion by Arturo to draw the screen to an fbo before the screen, so the screen image could be saved from the fbo.

Not having learned enough to understand how to do that, and it sounding not trivial to me, I instead did something else which worked, which was to have the print screen key instead set ofSetBackgroundAuto(true) for one Draw frame, then save the screenshot, and then set BackgroundAuto back to false.