How to save from the "Front Buffer"

BlitzMax Forums/BlitzMax Beginners Area/How to save from the "Front Buffer"

Eck(Posted 2006) [#1]
Would like to add a save screenshot to my game, the player would pause the game then press "S" for example.

But I can only seem to save the backbuffer image and not from the frontbuffer meaning the player ends up with a screenshot exactly 1 frame behind the frame they wanted.


kfprimm(Posted 2006) [#2]
I think if you get hDC of the window, then copy the content to a pixmap you could save it. MSDN is being a broken piece of crap so I can't provide an example right now...


tonyg(Posted 2006) [#3]
Immediately after a flip and before you draw anything else to the backbuffer your 'frontbuffer' and 'backbuffer' should be the same.... shouldn't they?
Use grabpixmap and savepixmappng for a screenshot.


xlsior(Posted 2006) [#4]
...If your game is 'paused' anyway, wouldn't the next frame still be identical anyway, provided you redraw it and not change anything?


ImaginaryHuman(Posted 2006) [#5]
If you're using OpenGL you can do glReadBuffer(GL_FRONT) and then glReadPixels() (or maybe grab pixmap).

Alternatively, if you decouple your logic from your graphics refresh, you should be able to re-render the previous frame into the backbuffer - ie when they press pause you skip doing the logic and just redraw the graphics again, then the backbuffer image will be the same as the one they saw.

Also NO, the backbuffer is totally unpredictable after a flip. It could be the same, it could be totally trash, it could be part of a chain of backbuffers which might contain images from several frames ago.


skidracer(Posted 2006) [#6]
The back buffer is undefined after a flip, it may contain the previous frame, the frame before that or random noise depending on the graphics architecture of the particular system. Always use grabpixmap just before flip, which is where I suggest you check for the user keypress.


tonyg(Posted 2006) [#7]
Doesn't that mean the user will get a screenshot of the next frame rather than the one they've just looked at?


TomToad(Posted 2006) [#8]
I guess you could always look for the "capture screen" keypress first each loop and if pressed, redraw the screen with the same data as the previous frame, capture, update the screen with the current frame, then flip.


skidracer(Posted 2006) [#9]
Unless the human is a computer I suggest there will be atleast a 3 frame lag between his brain firing the neuron and their finger depressing the key so I can't quite see the relevance of the original question.

Capturing a sequence of pixmaps while the capture button is down might also be useful or at least on the keyup which I would imagine will give them a slightly faster "shutter speed".


Eck(Posted 2006) [#10]
I think the best suggestion is to redraw the whole screen to the back buffer as normal then grab it before the flip.

Just seems a strange when old BlitzBasic could save either buffer with just one command.

Thanks.


skidracer(Posted 2006) [#11]
I think that was DirectDraw, DirectX has a performance penalty warning for creating a display that is lockable (required for capturing front buffer).