Hi,
Can anyone help to take a screenshot in webgl in cocos.
Through googling I got to know that for webgl ,you need to enable preserveDrawingBuffer flag to true,
so that to get DataURL.
Can anyone guide me how to achieve this in creator.
I thought of creating a new topic for this.
1 Like
Found a solution.
Just needed to call canvas.toDataURL just after renderer draw to canvas.
and cocos provide this callback…
cc.director.on(cc.Director.EVENT_AFTER_DRAW, callback);
Cheers.
Can you expand on how you use cc.Director.EVENT_AFTER_DRAW
?
Thanks
you just copy paste this line in onload of any loaded script:
var callback =function(){
console.log(“canvas redrawn”);
}
cc.director.on(cc.Director.EVENT_AFTER_DRAW, callback);
and whenever canvas is redrawn it will execute this callback.
@shishir451 I got white image after call canvas.getDataURL() . I noticed that the preserveDrawingBuffer flag was still false . Do you know the problem ? Were you able to take the screen shoot with webgl now ?
@shishir451 You’re right , I did it . Just call the function after the event. Thanks dude.