5
$\begingroup$

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])
        glReadPixels(posX,posY,sizeX,sizeY,GL_RGB,GL_BYTE,buf)
        ... #now what do I do with buf?
$\endgroup$
4
  • $\begingroup$ Using this answer, you should be able to write an image: blender.stackexchange.com/questions/643/… $\endgroup$
    – ideasman42
    Commented Oct 4, 2013 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
    Commented Oct 4, 2013 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
    Commented Oct 4, 2013 at 6:33
  • $\begingroup$ Could you answer this with the patch you wrote. Thanks. $\endgroup$
    – iKlsR
    Commented Nov 10, 2013 at 1:06

1 Answer 1

2
$\begingroup$

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.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .