Skip to content

Add F2 shortcut to take screenshots. Closes GH-119#127

Merged
satoshinm merged 8 commits intomasterfrom
screenshot
May 15, 2017
Merged

Add F2 shortcut to take screenshots. Closes GH-119#127
satoshinm merged 8 commits intomasterfrom
screenshot

Conversation

@satoshinm
Copy link
Copy Markdown
Owner

@satoshinm
Copy link
Copy Markdown
Owner Author

Works on the web version, but it opens a new window - can the app instead cause a file download, as to not interrupt gameplay? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a documents the download attribute "If the attribute has a value, it is used as the pre-filled file name in the Save prompt (the user can still change the file name if they want).", can it be programmatically clicked?

@satoshinm
Copy link
Copy Markdown
Owner Author

<a download> click() works well, this was saved as screenshot-netcraft-Sun May 14 2017 16_48_04 GMT-0700 (PDT).png:

screenshot-netcraft-sun may 14 2017 16_48_04 gmt-0700 pdt

@satoshinm
Copy link
Copy Markdown
Owner Author

Now for native support. Could change to render to a texture, but as seen in #89 many platforms don't support drawBuffers() (hmm, but that's on the web, mobile?). http://stackoverflow.com/questions/5844858/how-to-take-screenshot-in-opengl suggests using glReadPixels() on the rendered frame instead.

@satoshinm
Copy link
Copy Markdown
Owner Author

satoshinm commented May 15, 2017

miniz's png writer produces .. what looks like a png file:

native-build $ file screenshot-netcraft.png 
screenshot-netcraft.png: PNG image data, 2048 x 0, 8-bit/color RGBA, non-interlaced

but its 555 KB and I can't render it:

screenshot-netcraft

pngcrush tells what is wrong:

libpng warning: Image height is zero in IHDR
While converting NetCraft/native-build/screenshot-netcraft.png to /tmp/foo:
  pngcrush caught libpng error:
   Invalid IHDR data

   Critical chunk length, method 151 (ws 0 fm 0 zl 0 zs 0) =        0
   CPU time decoding 0.000, encoding 0.000, other 0.002, total 0.002 seconds

pngcheck is more specific - somehow it is 2048x0?!:

native-build $ pngcheck screenshot-netcraft.png 
screenshot-netcraft.png  invalid IHDR image dimensions (2048x0)
ERROR: screenshot-netcraft.png

supposed to be 2048x1536, that's g->width x g->height, where did it go wrong?


Oh this was already fixed upstream in miniz: https://github.com/richgel999/miniz/pull/65/files - it was a bug in miniz 2.0.5 beta.

@satoshinm
Copy link
Copy Markdown
Owner Author

Now only needs to have the filename timestamped on native (preferably, share date function from native and web, but if not no big deal), then this is ready to merge.

@satoshinm satoshinm changed the title [WIP] Add F2 to take screenshots. Closes GH-119 Add F2 shortcut to take screenshots. Closes GH-119 May 15, 2017
@satoshinm
Copy link
Copy Markdown
Owner Author

screenshot-netcraft-2017-05-15t00-47-25 419z

@satoshinm satoshinm merged this pull request into master May 15, 2017
@satoshinm satoshinm deleted the screenshot branch May 15, 2017 00:48
satoshinm added a commit that referenced this pull request May 15, 2017
* Add F2 to take screenshots. Closes GH-119

* Download named file screenshot.png by clicking <a download> link

* Add timestamp to screenshot filenames

* Native screenshots: glReadPixels() + miniz png writer

* Apply fix from miniz for png header height

richgel999/miniz@7ecd1b3

* Fix flipped image in native screenshots png

* Use ISO-8601 timestamps for screenshots

* Refactor screenshot() into util.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant