X-Git-Url: http://uxul.de/gitweb/?p=uxul-world.git;a=blobdiff_plain;f=opengl.lisp;fp=opengl.lisp;h=61c8e909355298220c6b43856bdc53441a480968;hp=5337ae7b4ec8e07d143394e5402328020a82ba00;hb=fe47814b2cd1ec57db67e494ff48faae46ffe21c;hpb=470725f4a2f682d02fb15183cc596c7fa5c7b761 diff --git a/opengl.lisp b/opengl.lisp index 5337ae7..61c8e90 100644 --- a/opengl.lisp +++ b/opengl.lisp @@ -15,13 +15,26 @@ (gl:flush) id)) -(defun make-quad (id x y w h) - (setf x (- x +screen-width+ )) - (setf y (- y +screen-height+)) - (gl:bind-texture :texture-2d id) - (gl:with-primitive :quads - (gl:tex-coord 0 0) (gl:vertex x (+ y h)) - (gl:tex-coord 1 0) (gl:vertex (+ x w) (+ y h)) - (gl:tex-coord 1 1) (gl:vertex (+ x w) y) - (gl:tex-coord 0 1) (gl:vertex x y))) +(defun load-spritesheet () + (let* + ((id (car (gl:gen-textures 1))) + (wh (cadr *spritesheet*)) + (pix (car *spritesheet*))) + (gl:bind-texture :texture-2d id) + (gl:tex-image-2d :texture-2d 0 :rgba8 wh wh 0 :bgra :unsigned-byte pix) + (gl:tex-parameter :texture-2d :texture-min-filter :linear) + (gl:tex-parameter :texture-2d :texture-mag-filter :linear) + (gl:flush) + id)) + +(defun make-quad (imgs x y w h) + (destructuring-bind (x1 y1 x2 y2) imgs + (setf x (- x +screen-width+)) + (setf y (- y +screen-height+)) + (gl:bind-texture :texture-2d *spritesheet-id*) + (gl:with-primitive :quads + (gl:tex-coord x1 y1) (gl:vertex x (+ y h)) + (gl:tex-coord x2 y1) (gl:vertex (+ x w) (+ y h)) + (gl:tex-coord x2 y2) (gl:vertex (+ x w) y) + (gl:tex-coord x1 y2) (gl:vertex x y))))