Skip to content

Commit c7946f1

Browse files
committed
Use actual buffer size when taking screenshot
1 parent 6e081d9 commit c7946f1

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
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()
151+
screenshot.create(WINDOW)
152152

153153

154154
def mouse_event_callback(window, x, y):

demosys/view/screenshot.py

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

77

8-
def create(format='png'):
8+
def create(window, format='png'):
99
"""
1010
Create a screenshot
1111
:param format: formats supported by PIL (png, jpeg etc)
@@ -20,11 +20,15 @@ def create(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)
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)
2427
GL.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1)
25-
data = GL.glReadPixels(x, y, width, height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE)
2628

27-
image = Image.frombytes("RGB", (width, height), data)
29+
data = GL.glReadPixels(0, 0, window.buffer_width, window.buffer_height, GL.GL_RGB, GL.GL_UNSIGNED_BYTE)
30+
31+
image = Image.frombytes("RGB", (window.buffer_width, window.buffer_height), data)
2832
image = image.transpose(Image.FLIP_TOP_BOTTOM)
2933
name = "{}.{}".format(datetime.now().strftime("%Y-%m-%d-%H-%M-%S"), format)
3034
image.save(os.path.join(dest, name), format=format)

demosys_test/cube/effect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import math
1+
# import math
22
from demosys.effects import effect
33
from demosys.opengl import geometry, FBO
44
# from pyrr import Vector3

0 commit comments

Comments
 (0)