Skip to content

Commit b2d4c4e

Browse files
committed
Go back to using viewport attributes for screenshot
1 parent c7946f1 commit b2d4c4e

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

demosys/view/controller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def key_event_callback(window, key, scancode, action, mods):
148148

149149
# Screenshots
150150
if key == glfw.KEY_X and action == glfw.PRESS:
151-
screenshot.create(WINDOW)
151+
screenshot.create()
152152

153153

154154
def mouse_event_callback(window, x, y):

demosys/view/screenshot.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from demosys.conf import settings
66

77

8-
def create(window, format='png'):
8+
def create(format='png'):
99
"""
1010
Create a screenshot
1111
:param format: formats supported by PIL (png, jpeg etc)
@@ -20,15 +20,13 @@ def create(window, format='png'):
2020
else:
2121
print("SCREENSHOT_PATH {} does not exist. Using cwd as fallback".format(settings.SCREENSHOT_PATH))
2222

23-
# x, y, width, height = GL.glGetIntegerv(GL.GL_VIEWPORT)
24-
# print("Screenshot viewport:", x, y, width, height)
25-
# FIXME: Snap to viewport
26-
print("Screenshot viewport:", window.buffer_width, window.buffer_height)
23+
x, y, width, height = GL.glGetIntegerv(GL.GL_VIEWPORT)
24+
print("Screenshot viewport:", x, y, width, height)
2725
GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1)
2826

29-
data = GL.glReadPixels(0, 0, window.buffer_width, window.buffer_height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE)
27+
data = GL.glReadPixels(x, y, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE)
3028

31-
image = Image.frombytes("RGB", (window.buffer_width, window.buffer_height), data)
29+
image = Image.frombytes("RGB", (width, height), data)
3230
image = image.transpose(Image.FLIP_TOP_BOTTOM)
3331
name = "{}.{}".format(datetime.now().strftime("%Y-%m-%d-%H-%M-%S"), format)
3432
image.save(os.path.join(dest, name), format=format)

demosys/view/window.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def __init__(self):
7474
# This is important for some displays like Apple's Retina as reported window sizes are virtual
7575
self.buffer_width, self.buffer_height = glfw.get_framebuffer_size(self.window)
7676
print("Frame buffer size:", self.buffer_width, self.buffer_height)
77-
# GL.glViewport(0, 0, self.buffer_width, self.buffer_height)
7877

7978
w, h = glfw.get_window_size(self.window)
8079
print("Actual window size:", w, h)

0 commit comments

Comments
 (0)