Copy Viewport To Clipboard as Image

   902   2   0
User Avatar
Member
4 posts
Joined: July 2019
Offline
Coming to Houdini from After Effects, where we have a wonderful plugin by Video Copilot called Fx Console. One of the features of this plugin is the ability to grab the currently rendered frame from your AE comp and copy it to your clipboard, save it as a file, etc.

Maybe there's a way to implement a similar feature in Houdini? I'm imagining that the viewport exists somewhere as a GLWindow, we'd just need to get the frame buffer for that window, convert it to float color data, etc, as described in this function:

void saveImage(char* filepath, GLFWwindow* w) {
 int width, height;
 glfwGetFramebufferSize(w, &width, &height);
 GLsizei nrChannels = 3;
 GLsizei stride = nrChannels * width;
 stride += (stride % 4) ? (4 - stride % 4) : 0;
 GLsizei bufferSize = stride * height;
 std::vector<char> buffer(bufferSize);
 glPixelStorei(GL_PACK_ALIGNMENT, 4);
 glReadBuffer(GL_FRONT);
 glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer.data());
 stbi_flip_vertically_on_write(true);
 stbi_write_png(filepath, width, height, nrChannels, buffer.data(), stride);
}

How could one access the current GL Window for a viewport view via a script in Houdini? General thoughts on this kind of approach to quickly grabbing a screenshot for a viewport in Houdini?
User Avatar
Staff
5158 posts
Joined: July 2005
Offline
You can use the Flipbook feature to do this without any scripting. It's on the left toolbar, near the bottom. You can flipbook to mplay or directly to a file.
User Avatar
Member
61 posts
Joined: Feb. 2020
Offline
malexander
You can use the Flipbook feature to do this without any scripting. It's on the left toolbar, near the bottom. You can flipbook to mplay or directly to a file.


But I'm assuming copy to OS clipboard would need to be implemented via a script?
  • Quick Links