aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-07-27 09:18:13 -0500
committerColin Okay <colin@cicadas.surf>2022-07-27 09:18:13 -0500
commit0b743b90752bacf31923171af9af0e5ff1f08095 (patch)
tree7a4ea6ad3ebc1372f2a14dc32147b924036e23d0 /src
parentdef70bc521a71b3bfa8d8b0bb982bbcd1743bd22 (diff)
[add] alpha support to image class
Diffstat (limited to 'src')
-rw-r--r--src/application.lisp2
-rw-r--r--src/interactive/image.lisp23
2 files changed, 11 insertions, 14 deletions
diff --git a/src/application.lisp b/src/application.lisp
index 6869a56..3b531c9 100644
--- a/src/application.lisp
+++ b/src/application.lisp
@@ -116,7 +116,7 @@ those objects are currently part of the scene tree."
(gl:clear :color-buffer-bit)
(gl:enable :blend)
(gl:blend-func :src-alpha :one-minus-src-alpha )
- (dolist (unit (application-scene app))
+ (dolist (unit (reverse (application-scene app)))
(render unit))
(sdl2:gl-swap-window (application-window app))
(sleep (frame-wait app)))
diff --git a/src/interactive/image.lisp b/src/interactive/image.lisp
index 1b3a817..644c06e 100644
--- a/src/interactive/image.lisp
+++ b/src/interactive/image.lisp
@@ -6,18 +6,9 @@
"Cached for later cleanup.")
(defvar *image-vao* nil)
-(defvar *image-count* 0
- "Used by finalizers to determin if the shader should be destroyed.")
-
-(defun image-finalizer ()
- "executed after a image has been reclaimed by gc. decrements image
-count and destroys shader-program if necessary."
- (decf *image-count*)
- (unless (plusp *image-count*)
- ))
-
(defclass/std image (unit interactive)
- ((texture :ri :std (error "A image requires a texture."))))
+ ((texture :ri :std (error "A image requires a texture."))
+ (alpha :std 1.0)))
(defun make-shared-image-gpu-objects ()
(unless *image-shader-program*
@@ -31,8 +22,10 @@ count and destroys shader-program if necessary."
vert))) ;color
'(:fragment
((tc :vec2))
- ((tex :sampler-2d))
+ ((tex :sampler-2d)
+ (alpha :float))
((let ((frag (vari:texture tex tc)))
+ (setf (aref frag 3) (vari:clamp 0 (* alpha (aref frag 3)) 1))
(if (< (aref frag 3) 0.01)
(vari:discard)
frag))))))
@@ -77,7 +70,7 @@ count and destroys shader-program if necessary."
(make-shared-image-gpu-objects)))
(defmethod render ((image image))
- (with-slots (texture) image
+ (with-slots (texture alpha) image
(gl:active-texture 0)
(gl:bind-texture :texture-2d (texture-id texture))
(gl:use-program *image-shader-program*)
@@ -85,6 +78,10 @@ count and destroys shader-program if necessary."
*image-shader-program*
(gl:get-uniform-location *image-shader-program* "TRANSFORM")
(projected-matrix image))
+ (gl:program-uniformf
+ *image-shader-program*
+ (gl:get-uniform-location *image-shader-program* "ALPHA")
+ alpha)
(gl:bind-vertex-array *image-vao*)
(gl:draw-arrays :triangles 0 6)
(gl:bind-vertex-array 0)))