Some time ago, I was able to take screenshot from my webGL 3D model using the toDataURL
function, but suddenly this stopped working, and now I am not able to get an image from any 3D model.
Please see bellow for more insights:
In all previous examples I didn't get the image, I get either a black or transparent image
Only the 2D exemple gave back the correct image
document.getElementsByTagName('canvas')[0].toDataURL();
Any idea of what I am doing wrong?
I've tried this on a MacBook Pro: Chrome and FireFox, and on FireFox on Windows 8.1 and I got the same result
I've found a fix for this problem in my Threejs app, the solution was as simple as putting a flag to true, so in my threejs instanciation I added preserveDrawingBuffer
:
var renderer = new THREE.WebGLRenderer({
preserveDrawingBuffer : true // required to support .toDataURL()
});
And this is it for the model that uses ThreeJs, so I think the problem is related to a configuration setting and there must be some option for using plain WebGl or other libraries.
Thank you for reading, and I hope this helps someone in future.