how to output a vtkTextureObject as jpg, png, bmp, etc?

how to output a vtkTextureObject as jpg, png, bmp, etc? there is not api in vtkTextureObject can do this. thanks!

Hello,

I can think of one dirty way to do it. vtkTextureObject has the overloaded CopyToFrameBuffer() method (https://vtk.org/doc/nightly/html/classvtkTextureObject.html#a3801bf2e51d41a5cc9f617146a1685b2) you can use to copy the texture’s fragments as pixels to the OpenGL’s frame buffer (used to contain the rendered pixels). Then, you can use some method based on OpenGL calls to save the frame buffer’s pixels as some image file: c++ - Save OpenGL rendering to an image file - Stack Overflow . After you save the image, just command another render to restore the original rendered scene.

take care,

PC

Thanks! thought VTK already had API for this :laughing:
there is no way to get vtkImageData or other things from vtkTexture to directly save out?

You’re quite welcome! There is a more elegant way to do it I think. You can use vtkTextureObject’s GetHandle() method to get its OpenGL handle id. Then use it with non-rendering OpenGL calls to save it to a file: save texture to a file - OpenGL: Basic Coding - Khronos Forums

best,

PC