Ported to OpenGL
[uxul-world.git] / opengl.lisp
diff --git a/opengl.lisp b/opengl.lisp
new file mode 100644 (file)
index 0000000..907aa6d
--- /dev/null
@@ -0,0 +1,27 @@
+;; Copyright 2010-2011 Christoph Senjak\r
+\r
+(in-package :uxul-world)\r
+\r
+(defun load-bmp-blob-into-texture (blob)\r
+  (let*\r
+      ((id (car (gl:gen-textures 1)))\r
+       (pix (bmp-pixel-data blob))\r
+       (w (bmp-width blob))\r
+       (h (bmp-height blob)))\r
+    (gl:bind-texture :texture-2d id)\r
+    (gl:tex-image-2d :texture-2d 0 :rgba8 w h 0 :bgra :unsigned-byte pix)\r
+    (gl:tex-parameter :texture-2d :texture-min-filter :linear)\r
+    (gl:tex-parameter :texture-2d :texture-mag-filter :linear)\r
+    (gl:flush)\r
+    id))\r
+\r
+(defun make-quad (id x y w h)\r
+  (setf x (- (+ x x) +screen-width+ ))\r
+  (setf y (- (+ y y)  +screen-height+))\r
+  (gl:bind-texture :texture-2d id)\r
+  (gl:with-primitive :quads\r
+    (gl:tex-coord 0 0) (gl:vertex x (+ y h))\r
+    (gl:tex-coord 1 0) (gl:vertex  (+ x w) (+ y h))\r
+    (gl:tex-coord 1 1) (gl:vertex (+ x w) y)\r
+    (gl:tex-coord 0 1) (gl:vertex x y)))\r
+\r