I am looking for a way to capture just a portion of the screen in the game engine. I was using the built-in render.makeScreenshot(path), which only captures a full-screen PNG.

I am exploring the following approach but have no idea how to save the list data into an image format. Any help would be appreciated.

from bgl import *
def captureCropped(posX, posY, sizeX, sizeY):
        buf = Buffer(GL_BYTE, [sizeX,sizeY,3])
        ... #now what do I do with buf?
  • $\begingroup$ Using this answer, you should be able to write an image: blender.stackexchange.com/questions/643/… $\endgroup$
    – ideasman42
    Oct 4 '13 at 0:58
  • $\begingroup$ I want to avoid using bpy if possible. My understanding is that it is not (or should not be) available in the game engine/blenderplayer. $\endgroup$
    – Mike Pan
    Oct 4 '13 at 2:20
  • $\begingroup$ in that case Im not sure how you would do this besides writing the raw data directly, which - I should add, is not as hard as you might expect - see: stackoverflow.com/questions/902761/… $\endgroup$
    – ideasman42
    Oct 4 '13 at 6:33
  • $\begingroup$ Could you answer this with the patch you wrote. Thanks. $\endgroup$
    – iKlsR
    Nov 10 '13 at 1:06

One solution is to uses plain Python to write out the PNG file.

Another solution is to extend render.makescreenshot(filename) to accept additional optional argument in the form of render.makescreenshot(filename, x, y, width, height) The work-in-progress patch is here: http://www.pasteall.org/47215/diff

Note: The patch currently does not work correctly in Blender, it only works in BlenderPlayer.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.