summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/shaders/default-fragment.glsl8
-rw-r--r--data/shaders/default-vertex.glsl11
-rw-r--r--data/shaders/font-fragment.glsl8
-rw-r--r--data/shaders/font-vertex.glsl15
-rw-r--r--data/shaders/sprite-fragment.glsl8
-rw-r--r--data/shaders/sprite-vertex.glsl26
-rw-r--r--examples/common.scm1
-rw-r--r--sly/font.scm12
-rw-r--r--sly/shape.scm79
-rw-r--r--sly/sprite.scm15
10 files changed, 65 insertions, 118 deletions
diff --git a/data/shaders/default-fragment.glsl b/data/shaders/default-fragment.glsl
new file mode 100644
index 0000000..e90adbe
--- /dev/null
+++ b/data/shaders/default-fragment.glsl
@@ -0,0 +1,8 @@
+#version 130
+
+in vec2 frag_tex;
+uniform sampler2D color_texture;
+
+void main (void) {
+ gl_FragColor = texture2D(color_texture, frag_tex);
+}
diff --git a/data/shaders/default-vertex.glsl b/data/shaders/default-vertex.glsl
new file mode 100644
index 0000000..11f389f
--- /dev/null
+++ b/data/shaders/default-vertex.glsl
@@ -0,0 +1,11 @@
+#version 130
+
+in vec3 position;
+in vec2 tex;
+out vec2 frag_tex;
+uniform mat4 mvp;
+
+void main(void) {
+ frag_tex = tex;
+ gl_Position = mvp * vec4(position.xyz, 1.0);
+}
diff --git a/data/shaders/font-fragment.glsl b/data/shaders/font-fragment.glsl
deleted file mode 100644
index 3dd10f1..0000000
--- a/data/shaders/font-fragment.glsl
+++ /dev/null
@@ -1,8 +0,0 @@
-#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/font-vertex.glsl b/data/shaders/font-vertex.glsl
deleted file mode 100644
index 196da12..0000000
--- a/data/shaders/font-vertex.glsl
+++ /dev/null
@@ -1,15 +0,0 @@
-#version 120
-
-uniform mat4 projection;
-uniform vec2 position;
-uniform vec2 anchor;
-
-void main(void) {
- mat4 translation = 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);
-
- gl_Position = projection * (gl_Vertex * translation);
- gl_TexCoord[0] = gl_MultiTexCoord0;
-}
diff --git a/data/shaders/sprite-fragment.glsl b/data/shaders/sprite-fragment.glsl
deleted file mode 100644
index 3dd10f1..0000000
--- a/data/shaders/sprite-fragment.glsl
+++ /dev/null
@@ -1,8 +0,0 @@
-#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
deleted file mode 100644
index d6efd3f..0000000
--- a/data/shaders/sprite-vertex.glsl
+++ /dev/null
@@ -1,26 +0,0 @@
-#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;
-}
diff --git a/examples/common.scm b/examples/common.scm
index 03a0a28..07e7aae 100644
--- a/examples/common.scm
+++ b/examples/common.scm
@@ -25,7 +25,6 @@
(sly window))
(open-window)
-(enable-sprites)
(add-hook! key-press-hook (lambda (key unicode)
(when (eq? key 'escape)
diff --git a/sly/font.scm b/sly/font.scm
index fd0a304..ae80263 100644
--- a/sly/font.scm
+++ b/sly/font.scm
@@ -46,16 +46,8 @@
;;; Font
;;;
-(define font-shader #f)
-
(define (enable-fonts)
- (SDL:ttf-init)
- (set! font-shader
- (load-shader-program
- (string-append %pkgdatadir
- "/shaders/font-vertex.glsl")
- (string-append %pkgdatadir
- "/shaders/font-fragment.glsl"))))
+ (SDL:ttf-init))
(define-record-type <font>
(make-font ttf point-size)
@@ -105,7 +97,7 @@ argument with a default value of 12."
(define* (make-label font text #:optional #:key
(anchor 'top-left) (color white)
- (shader font-shader))
+ (shader (load-default-shader)))
(let ((texture (render-text font text)))
(let ((w (texture-width texture))
(h (texture-height texture))
diff --git a/sly/shape.scm b/sly/shape.scm
index 3d96ca7..1526caf 100644
--- a/sly/shape.scm
+++ b/sly/shape.scm
@@ -24,15 +24,13 @@
(define-module (sly shape)
#:use-module (sly math)
#:use-module (sly mesh)
+ #:use-module (sly shader)
#:use-module (sly texture)
#:export (make-cube))
-(define (make-cube texture shader size)
- (let* ((s1 (texture-s1 texture))
- (t1 (texture-t1 texture))
- (s2 (texture-s2 texture))
- (t2 (texture-t2 texture))
- (half-size (half size)))
+(define* (make-cube size #:optional #:key (texture #f)
+ (shader (load-default-shader)))
+ (let ((half-size (half size)))
(make-mesh
#:shader shader
#:texture texture
@@ -80,34 +78,41 @@
(vector half-size half-size (- half-size))
(vector half-size half-size half-size)
(vector half-size (- half-size) half-size)))
- ("tex" ,(vector
- ;; Front
- (vector s1 t1)
- (vector s2 t1)
- (vector s2 t2)
- (vector s1 t2)
- ;; Back
- (vector s1 t1)
- (vector s2 t1)
- (vector s2 t2)
- (vector s1 t2)
- ;; Top
- (vector s1 t1)
- (vector s2 t1)
- (vector s2 t2)
- (vector s1 t2)
- ;; Bottom
- (vector s1 t1)
- (vector s2 t1)
- (vector s2 t2)
- (vector s1 t2)
- ;; Left
- (vector s1 t1)
- (vector s2 t1)
- (vector s2 t2)
- (vector s1 t2)
- ;; Right
- (vector s1 t1)
- (vector s2 t1)
- (vector s2 t2)
- (vector s1 t2)))))))
+ ,@(if texture
+ (let ((s1 (texture-s1 texture))
+ (t1 (texture-t1 texture))
+ (s2 (texture-s2 texture))
+ (t2 (texture-t2 texture)))
+ `("texture"
+ ,(vector
+ ;; Front
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Back
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Top
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Bottom
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Left
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2)
+ ;; Right
+ (vector s1 t1)
+ (vector s2 t1)
+ (vector s2 t2)
+ (vector s1 t2))))
+ '())))))
diff --git a/sly/sprite.scm b/sly/sprite.scm
index 9427373..f92687f 100644
--- a/sly/sprite.scm
+++ b/sly/sprite.scm
@@ -34,24 +34,13 @@
#:use-module (sly mesh)
#:use-module (sly shader)
#:use-module (sly texture)
- #:export (enable-sprites
- make-sprite))
+ #:export (make-sprite))
;;;
;;; Sprites
;;;
-(define sprite-shader #f)
-
-(define (enable-sprites)
- (set! sprite-shader
- (load-shader-program
- (string-append %pkgdatadir
- "/shaders/sprite-vertex.glsl")
- (string-append %pkgdatadir
- "/shaders/sprite-fragment.glsl"))))
-
-(define (make-sprite texture shader)
+(define* (make-sprite texture #:optional #:key (shader (load-default-shader)))
(let* ((half-width (half (texture-width texture)))
(half-height (half (texture-height texture)))
(s1 (texture-s1 texture))