From 6444bf3fe340e66e5701a0e962dafff7718fc699 Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Tue, 5 May 2015 19:47:00 -0700 Subject: [PATCH] working on supporting custom shaders. --- src/play_clj/core.clj | 5 +++-- src/play_clj/core_graphics.clj | 25 +++++++++++-------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index cc03c52..248dda8 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -17,7 +17,7 @@ VertexAttributes$Usage] [com.badlogic.gdx.graphics.g2d Batch ParticleEffect] [com.badlogic.gdx.graphics.g3d ModelBatch] - [com.badlogic.gdx.graphics.glutils ShapeRenderer] + [com.badlogic.gdx.graphics.glutils ShapeRenderer ShaderProgram] [com.badlogic.gdx.input GestureDetector GestureDetector$GestureListener] [com.badlogic.gdx.maps MapLayer MapLayers MapObject MapObjects @@ -35,7 +35,8 @@ [com.badlogic.gdx.scenes.scene2d.utils ActorGestureListener ChangeListener ClickListener DragListener FocusListener] [com.badlogic.gdx.utils ScreenUtils Timer$Task] - [play_clj.entities BundleEntity ShapeEntity])) + [play_clj.entities BundleEntity ShapeEntity] + )) (load "core_basics") (load "core_cameras") diff --git a/src/play_clj/core_graphics.clj b/src/play_clj/core_graphics.clj index 937c4aa..8204a8a 100644 --- a/src/play_clj/core_graphics.clj +++ b/src/play_clj/core_graphics.clj @@ -486,28 +486,25 @@ with the tiled map file at `path` and `unit` scale. entities) (defmethod draw! Stage - [{:keys [^Stage renderer ^Camera camera] :as screen} entities] + [{:keys [^Stage renderer ^Camera camera ^ShaderProgram shader] :as screen} entities] (let [^Batch batch (.getBatch renderer)] (.setProjectionMatrix batch (.combined camera)) (.begin batch) - (doseq [{:keys [additive? opacity colorize?] :as entity :or {opacity 1.0}} entities + (when shader + (.setShader batch shader)) + (doseq [{:keys [additive? opacity ^float r ^float g ^float b ^float hue-amount ^float multiply-amount] :as entity :or {opacity 1.0}} entities :when (> opacity 0.0)] - + (when shader + (.setUniformf shader "multiply_amount" (float (or multiply-amount 1.0))) + (.setUniformf shader "hue_amount" (float (or hue-amount 1.0)))) (when additive? (.setBlendFunction ^Batch batch (gl :gl-src-alpha) (gl :gl-one))) - (if colorize? - (do (.setBlendFunction ^Batch batch (gl :gl-dst-color) (gl :gl-one-minus-src-alpha)) - (.setColor batch (color 1 1 1 opacity)) - (e/draw! entity screen batch) - (.setColor batch (color 1 1 1 (* opacity 0.25))) - (.setBlendFunction ^Batch batch (gl :gl-src-alpha) (gl :gl-one)) - (e/draw! entity screen batch)) - (do (.setColor batch (color 1 1 1 opacity)) - (e/draw! entity screen batch) - (.setColor batch (color 1 1 1 1)))) + (do (.setColor batch (color (or r 1.0) (or g 1.0) (or b 1.0) opacity)) + (e/draw! entity screen batch) + (.setColor batch (color 1 1 1 1))) - (when (or additive? colorize?) + (when (or additive?) (.setBlendFunction ^Batch batch (gl :gl-src-alpha) (gl :gl-one-minus-src-alpha)))) (.end batch)) entities)