Skip to content

Commit

Permalink
Add Window.takeScreenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
OhadRau committed Jan 21, 2019
1 parent e763bbe commit d8be26e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Core/Window.re
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit d8be26e

Please sign in to comment.