Is there a way to pass a PIL/(Pillow) Image to blender game engine video texture / texture.ImageBuff() or and https://www.blender.org/api/blender_python_api_2_76_0/bge.texture.html function?
I am making something like photoshop in the bge.
Is there a way to pass a PIL/(Pillow) Image to blender game engine video texture / texture.ImageBuff() or and https://www.blender.org/api/blender_python_api_2_76_0/bge.texture.html function?
I am making something like photoshop in the bge.
You can it like this:
def set_image(obj, image):
'''Sets the image used as a background. Expects an instance of PIL.Image
CAUTION: THIS OPERATION IS SLOW'''
if image is None:
# Sets the image to all black
buff = bgl.Buffer(bgl.GL_BYTE, 3) # Blank, really small image
width, height = [1, 1]
else:
width, height = image.size
imdata = numpy.asarray(image.convert('RGB')).ravel() # SLOW
buff = bgl.Buffer(bgl.GL_BYTE, width*height*3, imdata)
image_buffer = bge.texture.ImageBuff(1, 1) # Very small image
image_buffer.load(buff, width, height) # Overwritten with PIL one
if 'TEX' not in obj:
obj['TEX'] = bge.texture.Texture(obj, 0) # 0 is the texture ID
tex = obj['TEX']
tex.source = image_buffer
tex.refresh(False)
Moguri says you can use PYopenGL and the Post render callback to draw on a face using a PIL image. I will edit this comment and provide more details as I find them.