Screenshot in webgl in creator


#1

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.


#2

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.


#3

Can you expand on how you use cc.Director.EVENT_AFTER_DRAW ?

Thanks


#4

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.


#5

@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 ?


#6

@shishir451 You’re right , I did it . Just call the function after the event. Thanks dude.