satoshinm / NetCraft

Web-based fork of fogleman/Craft ⛺
https://satoshinm.github.io/NetCraft/
MIT License
57 stars 13 forks source link

F2 key shortcut to take screenshots #119

Closed satoshinm closed 7 years ago

satoshinm commented 7 years ago

Although screenshots can be taken by the player using operating system functionality, sometimes it is more convenient to take them within the game; ought to add a shortcut to do this. Write out the image buffer to a file (or a data URL in the browser then window.open or download it).

satoshinm commented 7 years ago

Either render to a framebuffer and serialize the texture to png (using the newly-added miniz https://github.com/satoshinm/NetCraft/pull/125 which has png writing capabilities), or on the web platform something like this:

window.open(document.getElementsByTagName("canvas")[0].toDataURL())

however this opens an image, it is completely blank despite 16,380 bytes and 1313x711 pixels?

unknown


http://stackoverflow.com/questions/31710748/todataurl-of-webgl-canvas-returning-transparent-image says to either enable preserveDrawingBuffer, or call it before the requestAnimationFrame callback returns.