added rough implementation of screen shot capturing

This commit is contained in:
Anthony Urena
2014-04-07 23:26:41 -04:00
parent 6a3bbf07b6
commit 16ba12315c
2 changed files with 32 additions and 2 deletions

View File

@@ -6,8 +6,9 @@
InputMultiplexer InputProcessor Net Screen]
[com.badlogic.gdx.audio Sound]
[com.badlogic.gdx.assets AssetManager]
[com.badlogic.gdx.files FileHandle]
[com.badlogic.gdx.graphics Camera Color GL20 OrthographicCamera
PerspectiveCamera Pixmap Texture VertexAttributes$Usage]
PerspectiveCamera Pixmap Pixmap$Format PixmapIO Texture VertexAttributes$Usage]
[com.badlogic.gdx.graphics.g2d SpriteBatch]
[com.badlogic.gdx.graphics.g3d ModelBatch]
[com.badlogic.gdx.graphics.glutils ShapeRenderer]
@@ -26,7 +27,7 @@
[com.badlogic.gdx.scenes.scene2d Actor Stage]
[com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener Align
ChangeListener ClickListener DragListener FocusListener]
[com.badlogic.gdx.utils Timer$Task]
[com.badlogic.gdx.utils ScreenUtils Timer$Task]
[play_clj.entities ShapeEntity]))
(load "core_basics")

View File

@@ -7,6 +7,35 @@
[& body]
`(app! :post-runnable (fn [] ~@body)))
(defn new-file!
"Creates a new [File](http://docs.oracle.com/javase/7/docs/api/java/io/File.html)"
([name extension]
(new-file! "./" name extension))
([path name extension]
(java.io.File. (str path name extension))))
(defn capture-screen!
"Returns a [Pixmap](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Pixmap.html) that contains a capture of the current screen.
Note that you must call [dispose](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/Pixmap.html#dispose) on the Pixmap or you will cause a memory leak on the native heap.
screenshot! captures and disposes the Pixmap automatically."
[]
(let [pixmap (Pixmap. (game :width) (game :height) (Pixmap$Format/RGBA8888))
pixel-data (ScreenUtils/getFrameBufferPixels true)
pixels (.getPixels pixmap)]
(doto pixels
(.clear)
(.put pixel-data)
(.position))
pixmap))
(defn screenshot!
"Captures a screenshot and writes it to disk."
[]
(let [pixmap (capture-screen!)
handle (FileHandle. (new-file! (str (System/currentTimeMillis)) ".png"))]
(do (PixmapIO/writePNG handle pixmap)
(.dispose pixmap))))
; static fields
(defmacro scaling