summaryrefslogtreecommitdiff
path: root/data/shaders
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-02-15 20:14:20 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-02-16 10:46:58 -0500
commit63f096c9f1fc04fe0ae080d67b42437ca5958678 (patch)
treede6214ebc595c7ae6b57753cacd1281e318ecff7 /data/shaders
parentb1ae9699b83faee738d92f39231d7f703866996c (diff)
Use GLSL shaders for sprites.
* 2d/sprite.scm: (sprite-vertex): Remove color vertex. (r-offset): Delete it. (pack-sprite-vertices): Remove logic moved to shader. (draw-sprite-vertices): Remove color vertex array rendering. (sprite-shader): New variable. (<sprite>): Remove dirty field and adjust setters. (make-anchor): New procedure. (update-sprite-vertices!): Use new 'pack-sprite-vertices'. (make-sprite): Use 'make-anchor' and 'update-sprite-vertices!'. (dirty-sprite-setter): Delete it. (load-sprite): Formatting. (sprite-animation-texture): Delete it. (drawable-texture): New procedure. (sprite-texture): Extract body to 'drawable-texture'. (sprite-anchor-vector): Delete it. (set-sprite-anchor!): Reimplemented. (update-sprite-animator!): Update vertices. (draw-sprite): Use shader program. (<sprite-batch>, make-sprite-batch, sprite-batch?, sprite-batch-max-size, sprite-batch-size, set-sprite-batch-size!, sprite-batch-texture, set-sprite-batch-texture!, sprite-batch-vertices, sprite-batch-draw, with-sprite-batch): Delete all sprite batch code. * data/Makefile.am (shadersdir, shaders_DATA): New variables. * data/shaders/sprite-fragment.glsl: New shader. * data/shaders/sprite-vertex.glsl: New shader.
Diffstat (limited to 'data/shaders')
-rw-r--r--data/shaders/sprite-fragment.glsl8
-rw-r--r--data/shaders/sprite-vertex.glsl26
2 files changed, 34 insertions, 0 deletions
diff --git a/data/shaders/sprite-fragment.glsl b/data/shaders/sprite-fragment.glsl
new file mode 100644
index 0000000..3dd10f1
--- /dev/null
+++ b/data/shaders/sprite-fragment.glsl
@@ -0,0 +1,8 @@
+#version 120
+
+uniform sampler2D color_texture;
+uniform vec4 color;
+
+void main (void) {
+ gl_FragColor = texture2D(color_texture, gl_TexCoord[0].st) * color;
+}
diff --git a/data/shaders/sprite-vertex.glsl b/data/shaders/sprite-vertex.glsl
new file mode 100644
index 0000000..d6efd3f
--- /dev/null
+++ b/data/shaders/sprite-vertex.glsl
@@ -0,0 +1,26 @@
+#version 120
+
+uniform mat4 projection;
+uniform vec2 position;
+uniform vec2 anchor;
+uniform vec2 scale;
+uniform float rotation;
+
+void main(void) {
+ mat4 rotationMatrix = mat4(cos(rotation), -sin(rotation), 0.0, 0.0,
+ sin(rotation), cos(rotation), 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+ mat4 translationMatrix = mat4(1.0, 0.0, 0.0, position.x - anchor.x,
+ 0.0, 1.0, 0.0, position.y - anchor.y,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+ mat4 scaleMatrix = mat4(scale.x, 0.0, 0.0, 0.0,
+ 0.0, scale.y, 0.0, 0.0,
+ 0.0, 0.0, 1.0, 0.0,
+ 0.0, 0.0, 0.0, 1.0);
+
+ gl_Position = projection * (gl_Vertex * scaleMatrix *
+ rotationMatrix * translationMatrix);
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+}