Hi,
we’re trying to create a script to capture screenshots from the application canvas,
according to what we found on the web, when using a WebGL renderer, one has to tell this renderer to preserve the draw buffer, otherwise the screenshot will be empty.
This is also what we experience, here is out attempt so far:
initialize: function ()
{
app.keyboard.on(pc.EVENT_KEYDOWN, this.takeScreenshot, this);
},
takeScreenshot: function(event)
{
if (event.key === pc.KEY_S)
{
var canvas = document.getElementById('application-canvas');
var context = canvas.getContext("experimental-webgl", {preserveDrawingBuffer: true});
var dataURL = canvas.toDataURL();
$(document.body).append("<img id='screenshot' src='" + dataURL + "'>");
$("#screenshot").css('z-index',9999999999999999999);
$("#screenshot").css('position','absolute');
$("#screenshot").css('left','50%');
$("#screenshot").css('top','50%');
$("#screenshot").css('transform','translate(-50%, -50%)');
$("#screenshot").css('width','50%');
$("#screenshot").css('height','50%');
$("#screenshot").css('border','6px solid white');
}
}
Now my question is: How could we reach the renderer?
Where is it located in the API hierarchy?
Or is there maybe a better / other sollution to this?
Thanks in advance!
EDIT: Corrected script from
$("#screenshot").src = dataURL;to$(document.body).append("<img id='screenshot' src='" + dataURL + "'>");