ReadPixels

Monkey Targets Forums/XNA/ReadPixels

pantson(Posted 2015) [#1]
Hi
I want to grab an area of the game screen every frame and display it altered on top of everything in the game.
I assumed I could use ReadPixels as this will copy an area of the render screen and then I can convert to image and the draw that image.
What I'm finding though is that ReadPixels is not only copying the pixels, but also flushing the render area, so the original render screen is no longer there. Thus making the actual game not display.

I have written the below example to show it in action. Hit the mouse to start grabbing the pixels and you will see the text disappear. I would expect the text to always display.

I've only had chance to try this on XNA, so it would be nice if anyone can see this happening in other targets


pantson(Posted 2015) [#2]
for the time being, I've solved this by drawing everything twice.
once before the readpixels and once after the readpixels.


ImmutableOctet(SKNG)(Posted 2015) [#3]
So, this seems to be a bug with the XNA target.

Here's a fun refactored version of your example:


Press left-click to capture the screen. On XNA specifically, you can hit right-click to disable the re-draw fix.

You should probably report this to Mark in the "Bugs" section. It doesn't even redraw as black, either, it's the default XNA color from the look of it. Also, I think I found a different bug, the XNA target doesn't care if you use 'SetUpdateRate' before running, it will just run regardless.

P.S. Please use the 'codebox' tag for long pieces of code, that way I don't have to scroll all the way through it.


pantson(Posted 2015) [#4]
thanks Anthony
Ive been on this forum for such a long time and never knew about codebox ;-) I'll be using that from now on.

I can see that you are redrawing (calling onRender again) to fix the issue after grabbing the pixel data, a bit like my current fix in my game.

I'll report it as a bug.

Many thanks for testing and confirming.