1- from datetime import datetime
21import os
2+ from datetime import datetime
33
4- from OpenGL import GL
54from PIL import Image
65
76from demosys .conf import settings
87from demosys import context
98
109
11- def create (format = 'png' , name = None ):
10+ def create (file_format = 'png' , name = None ):
1211 """
1312 Create a screenshot
14- :param format : formats supported by PIL (png, jpeg etc)
13+ :param file_format : formats supported by PIL (png, jpeg etc)
1514 """
1615 dest = ""
1716 if settings .SCREENSHOT_PATH :
@@ -22,17 +21,12 @@ def create(format='png', name=None):
2221 else :
2322 print ("SCREENSHOT_PATH not defined in settings. Using cwd as fallback." )
2423
25- # x, y, width, height = GL.glGetIntegerv(GL.GL_VIEWPORT)
26- x , y , width , height = 0 , 0 , context .WINDOW .buffer_width , context .WINDOW .buffer_height
27-
28- GL .glPixelStorei (GL .GL_PACK_ALIGNMENT , 1 )
29-
30- data = GL .glReadPixels (x , y , width , height , GL .GL_RGB , GL .GL_UNSIGNED_BYTE )
31-
32- image = Image .frombytes ("RGB" , (width , height ), data )
24+ fbo = context .ctx ().screen
25+ image = Image .frombytes ("RGB" , (fbo .width , fbo .height ), fbo .read ())
3326 image = image .transpose (Image .FLIP_TOP_BOTTOM )
27+
3428 if not name :
35- name = "{}.{}" .format (datetime .now ().strftime ("%Y-%m-%d-%H-%M-%S" ), format )
29+ name = "{}.{}" .format (datetime .now ().strftime ("%Y-%m-%d-%H-%M-%S-%f " ), file_format )
3630
3731 print ("Creating screenshot:" , name )
38- image .save (os .path .join (dest , name ), format = format )
32+ image .save (os .path .join (dest , name ), format = file_format )
0 commit comments