[pal-cvs] CVS pal

tneste tneste at common-lisp.net
Fri Jul 13 21:30:59 UTC 2007


Update of /project/pal/cvsroot/pal
In directory clnet:/tmp/cvs-serv13905

Modified Files:
	package.lisp pal.asd pal.lisp todo.txt 
Log Message:
Rest of the api changes applied.

--- /project/pal/cvsroot/pal/package.lisp	2007/07/13 13:21:04	1.4
+++ /project/pal/cvsroot/pal/package.lisp	2007/07/13 21:30:59	1.5
@@ -416,9 +416,8 @@
            #:draw-line
            #:draw-arrow
            #:draw-image
-           #:draw-image-from
-           #:draw-quad
-
+           #:draw-image*
+           
            #:load-font
            #:get-font-height
            #:draw-text
--- /project/pal/cvsroot/pal/pal.asd	2007/06/28 20:14:05	1.1
+++ /project/pal/cvsroot/pal/pal.asd	2007/07/13 21:30:59	1.2
@@ -2,7 +2,10 @@
 (in-package #:asdf)
 
 (defsystem pal
-    :components
+  :description "Pixel Art Library"
+  :author "Tomi Neste"
+  :license "MIT"
+  :components
   ((:file "ffi"
           :depends-on ("package"))
    (:file "vector"
--- /project/pal/cvsroot/pal/pal.lisp	2007/07/13 13:21:04	1.9
+++ /project/pal/cvsroot/pal/pal.lisp	2007/07/13 21:30:59	1.10
@@ -1,10 +1,10 @@
-;; Urgent:
+;; Notes:
 ;; tags-resources-free?
 ;; circle/box/point overlap functions, fast v-dist
 ;; resources should check for void when freeing
-;; sdl window not always on top on windows?
 ;; do absolute paths for data-path work?
-;; draw-image aligns, draw-quad! abs.
+;; draw-image* aligns & scale, angle?
+;; draw-polygon*, draw-circle
 
 (declaim (optimize (speed 3)
                    (safety 3)))
@@ -416,21 +416,30 @@
     (pal-ffi::free-surface surface)
     image))
 
-(defun draw-image (image pos &key angle scale (valign :left) (halign :top))
+(defun draw-image (image pos &key angle scale valign halign)
   (declare (type image image) (type vec pos) (type (or boolean single-float) angle scale) (type symbol halign valign))
   (set-image image)
   (let ((width (image-width image))
         (height (image-height image))
         (tx2 (pal-ffi:image-tx2 image))
         (ty2 (pal-ffi:image-ty2 image)))
-    (if angle
+    (if (or angle scale valign halign)
         (with-transformation ()
           (translate pos)
-          (rotate angle)
+          (when angle
+            (rotate angle))
           (when scale
-            (scale scale scale))
-          (let ((x (- (/ (image-width image) 2f0)))
-                (y (- (/ (image-height image) 2f0))))
+            (scale scale scale)) ;; :-)
+          (let ((x (case halign
+                     (:right (coerce (- width) 'single-float))
+                     (:left 0f0)
+                     (:middle (coerce (- (/ width 2)) 'single-float))
+                     (otherwise 0f0)))
+                (y (case valign
+                     (:bottom (coerce (- height) 'single-float))
+                     (:top 0f0)
+                     (:middle (coerce (- (/ height 2)) 'single-float))
+                     (otherwise 0f0))))
             (with-gl pal-ffi:+gl-quads+
               (pal-ffi:gl-tex-coord2f 0f0 0f0)
               (pal-ffi:gl-vertex2f x y)
@@ -440,32 +449,21 @@
               (pal-ffi:gl-vertex2f (+ x width) (+ y height))
               (pal-ffi:gl-tex-coord2f 0f0 ty2)
               (pal-ffi:gl-vertex2f x (+ y height)))))
-        (with-gl pal-ffi:+gl-quads+
-          (pal-ffi:gl-tex-coord2f 0f0 0f0)
-          (pal-ffi:gl-vertex2f (vx pos) (vy pos))
-          (pal-ffi:gl-tex-coord2f tx2 0f0)
-          (pal-ffi:gl-vertex2f (+ (vx pos) width) (vy pos))
-          (pal-ffi:gl-tex-coord2f tx2 ty2)
-          (pal-ffi:gl-vertex2f (+ (vx pos) width) (+ (vy pos) height))
-          (pal-ffi:gl-tex-coord2f 0f0 ty2)
-          (pal-ffi:gl-vertex2f (vx pos) (+ (vy pos) height))))))
+        (let ((x (vx pos))
+              (y (vy pos)))
+          (with-gl pal-ffi:+gl-quads+
+            (pal-ffi:gl-tex-coord2f 0f0 0f0)
+            (pal-ffi:gl-vertex2f x y)
+            (pal-ffi:gl-tex-coord2f tx2 0f0)
+            (pal-ffi:gl-vertex2f (+ x width) y)
+            (pal-ffi:gl-tex-coord2f tx2 ty2)
+            (pal-ffi:gl-vertex2f (+ x width) (+ y height))
+            (pal-ffi:gl-tex-coord2f 0f0 ty2)
+            (pal-ffi:gl-vertex2f x (+ y height)))))))
 
-(defun draw-quad (image a b c d &key absolutep)
-  (declare (type image image) (type vec a b c d))
-  (set-image image)
-  (let ((tx2 (pal-ffi:image-tx2 image))
-        (ty2 (pal-ffi:image-ty2 image)))
-    (with-gl pal-ffi:+gl-quads+
-      (pal-ffi:gl-tex-coord2f 0f0 0f0)
-      (pal-ffi:gl-vertex2f (vx a) (vy a))
-      (pal-ffi:gl-tex-coord2f tx2 0f0)
-      (pal-ffi:gl-vertex2f (vx b) (vy b))
-      (pal-ffi:gl-tex-coord2f tx2 ty2)
-      (pal-ffi:gl-vertex2f (vx c) (vy c))
-      (pal-ffi:gl-tex-coord2f 0f0 ty2)
-      (pal-ffi:gl-vertex2f (vx d) (vy d)))))
 
-(defun draw-image-from (image from-pos to-pos width height)
+
+(defun draw-image* (image from-pos to-pos width height)
   (declare (type image image) (type vec from-pos to-pos) (type u11 width height))
   (set-image image)
   (let* ((vx (vx from-pos))
@@ -534,15 +532,21 @@
     (pal-ffi:gl-vertex2f (vx pos) (vy pos)))
   (pal-ffi:gl-pop-attrib))
 
-(defun draw-rectangle (pos width height r g b a &key (filledp t) (size 1f0))
-  (declare (type vec pos) (type float size) (type u11 width height) (type u8 r g b a) (type boolean filledp))
+(defun draw-rectangle (pos width height r g b a &key (fill t) (size 1f0) absolutep)
+  (declare (type vec pos) (type boolean absolutep) (type float size) (type u11 width height) (type u8 r g b a) (type (or image boolean) fill))
   (pal-ffi:gl-push-attrib (logior pal-ffi:+gl-color-buffer-bit+ pal-ffi:+gl-current-bit+ pal-ffi:+gl-line-bit+ pal-ffi:+gl-enable-bit+))
-  (pal-ffi:gl-disable pal-ffi:+gl-texture-2d+)
-  (set-blend-color r g b a)
   (cond
-    (filledp
-     (pal-ffi:gl-rectf (vx pos) (vy pos) (+ (vx pos) width) (+ (vy pos) height)))
-    (t
+    ((image-p fill)
+     (draw-polygon (list pos
+                         (v+ pos (v width 0))
+                         (v+ pos (v width height))
+                         (v+ pos (v 0 height)))
+                   0 0 0 0
+                   :fill fill
+                   :absolutep absolutep))
+    ((eq nil fill)
+     (pal-ffi:gl-disable pal-ffi:+gl-texture-2d+)
+     (set-blend-color r g b a)
      (pal-ffi:gl-enable pal-ffi:+gl-line-smooth+)
      (pal-ffi:gl-line-width size)
      (with-gl pal-ffi:+gl-line-loop+
@@ -552,10 +556,14 @@
        (pal-ffi:gl-vertex2f (+ (vx pos) width) (+ (vy pos) height))
        (pal-ffi:gl-vertex2f (+ (vx pos) width) (+ (vy pos) height))
        (pal-ffi:gl-vertex2f (vx pos) (+ (vy pos) height))
-       (pal-ffi:gl-vertex2f (vx pos) (+ (vy pos) height)))))
+       (pal-ffi:gl-vertex2f (vx pos) (+ (vy pos) height))))
+    (t
+     (pal-ffi:gl-disable pal-ffi:+gl-texture-2d+)
+     (set-blend-color r g b a)
+     (pal-ffi:gl-rectf (vx pos) (vy pos) (+ (vx pos) width) (+ (vy pos) height))))
   (pal-ffi:gl-pop-attrib))
 
-(defun draw-polygon (points r g b a &key fill absolutep (size 1f0))
+(defun draw-polygon (points r g b a &key (fill t) absolutep (size 1f0))
   (declare (type list points) (type u8 r g b a) (type (or image boolean) fill))
   (cond
     ((image-p fill)
@@ -648,8 +656,7 @@
 
 (defstruct glyph
   (char #\space :type character)
-  (x 0 :type u11)
-  (y 0 :type u11)
+  (pos (v 0 0) :type vec)
   (width 0 :type u11)
   (height 0 :type u11)
   (xoff 0 :type fixnum)
@@ -657,7 +664,7 @@
 
 
 (defun load-font (font)
-  (let ((glyphs (make-array 255 :initial-element (make-glyph :x 0 :y 0 :width 1 :height 1 :xoff 0 :dl 0) :element-type 'glyph))
+  (let ((glyphs (make-array 255 :initial-element (make-glyph :width 1 :height 1 :xoff 0 :dl 0) :element-type 'glyph))
         (lines (with-open-file (file (data-path (concatenate 'string font ".fnt")))
                  (loop repeat 4 do (read-line file))
                  (loop for i from 0 to 94 collecting
@@ -675,32 +682,29 @@
         (coords (read-from-string (concatenate 'string "(" (subseq line 2) ")"))))
     (make-glyph :char char
                 :dl 0
-                :x (first coords)
-                :y (second coords)
+                :pos (v (first coords)
+                        (second coords))
                 :width (third coords)
                 :height (fourth coords)
                 :xoff (sixth coords))))
 
-(defun draw-glyph (char font)
-  (declare (type font font) (type character char))
-  (let ((image (pal-ffi:font-image font))
-        (g (aref (pal-ffi:font-glyphs font) (char-code char))))
-    (draw-image-from image
-                     (v (glyph-x g)
-                        (glyph-y g))
-                     (v 0 0)
-                     (glyph-width g)
-                     (glyph-height g))
-    (pal-ffi:gl-translatef (coerce (+ (glyph-width g) (glyph-xoff g)) 'single-float) 0f0 0f0)))
-
 (defun draw-text (text pos &optional font)
   (declare (type vec pos) (type simple-string text) (type (or font boolean) font))
   (with-transformation (:pos pos)
-    (let ((font (if font
-                    font
-                    (tag 'default-font))))
-      (loop for c across text do
-           (draw-glyph c font)))))
+    (let* ((font (if font
+                     font
+                     (tag 'default-font)))
+           (origo (v 0 0))
+           (image (pal-ffi:font-image font)))
+      (declare (type image image) (type vec origo))
+      (loop for char across text do
+           (let ((g (aref (pal-ffi:font-glyphs font) (char-code char))))
+             (draw-image* image
+                          (glyph-pos g)
+                          origo
+                          (glyph-width g)
+                          (glyph-height g))
+             (pal-ffi:gl-translatef (coerce (+ (glyph-width g) (glyph-xoff g)) 'single-float) 0f0 0f0))))))
 
 (declaim (inline get-font-height))
 (defun get-font-height (&optional font)
--- /project/pal/cvsroot/pal/todo.txt	2007/07/13 13:21:04	1.5
+++ /project/pal/cvsroot/pal/todo.txt	2007/07/13 21:30:59	1.6
@@ -2,25 +2,40 @@
 
 - Add display list support.
 
-- Make font rendering use display lists.
+- Font rendering is too slow, maybe use display lists for that?
 
 - More drawing primitives.
 
 - image-from-array/image-to-array/screen-to-array etc.
 
-- Fix the FPS limiter.
+- Fix the FPS limiter, the results could be a lot smoother.
 
 - Check the sanity of vector.lisp and add some operations, esp. bounding-boxes
   etc.
 
 - Correct aspect ratio when fullscreen on widescreen displays.
 
-- CL native font resource builder.
+- I would really like to see it run on OS X.
 
-- Fix with-blend (r g b a).
+- Simple and transparent animation system for images.
 
-- Make it run on OS X.
+- Using fullscreen mode on Windows some times results in screen flickering
+  between desktop and PAL screen, usually fixed by alt-tabbing. Should be fixed.
 
-- TrueType font support.
+- The problems with Linux and some gfx drivers should be somehow fixed.
 
-- Simple animation system for images.
+- Documentation and tutorials.
+
+
+
+As separate projects on top of PAL:
+
+- Native CL font resource builder
+
+- TTF support
+
+- GUI
+
+- Some sort of sprite library?
+
+- Network code?




More information about the Pal-cvs mailing list