From d8be26efe64adbafdb91c5504ec6f318f110736a Mon Sep 17 00:00:00 2001 From: ohadrau Date: Sun, 20 Jan 2019 15:33:40 -0500 Subject: [PATCH] Add Window.takeScreenshot --- src/Core/Window.re | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Core/Window.re b/src/Core/Window.re index 9d86926b2..9464d2c04 100644 --- a/src/Core/Window.re +++ b/src/Core/Window.re @@ -326,11 +326,17 @@ let getDevicePixelRatio = (w: t) => { let takeScreenshot = (w: t, filename: string) => { open Glfw; - let {width, height}: Window.frameBufferSize = glfwGetFramebufferSize(w.glfwWindow); + let width = w.framebufferWidth; + let height = w.framebufferHeight; let image = Image.create(~width, ~height, ~numChannels=4, ~channelSize=1); let buffer = Image.getBuffer(image); + /* WebGL is weird in that we can't capture with glReadPixels during + a render operation. Instead, we want to wait till it's over (we + can force this by triggering a new render) and then taking the + screenshot */ + render(w); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); Image.save(image, filename);