[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sample GWorld Code?

Here's a simple example use of GWorlds to generate offscreen pixmaps.
If this crashes, you probably need to install the patch that Alan

;;; Body should consist of low-level Quickdraw calls, which will be
;;; done on the pixmap.
;;; Bugs:  doesn't deallocate gworld.
(defmacro make-pixmap ((w h) &body body)
  `(rlet ((cgrafptr :pointer) (gdhandle :pointer))
     (#_GetGWorld cgrafptr gdhandle)
     (let* ((gworld (make-gworld ,w ,h))
            (pixmap (#_GetGWorldPixMap gworld)))
           (#_SetGworld gworld (ccl:%null-ptr))
           (#_LockPixels pixmap)
           (#_EraseRect (ccl:rref gworld cgrafport.portrect))
       (#_UnLockPixels pixmap)
       (#_SetGWorld (ccl:%get-ptr cgrafptr) (ccl:%get-ptr gdhandle))

(defun make-gworld (w h)
  (rlet ((bounds-rect :rect :top 0 :left 0 :right w :bottom h)
         (gworldp :pointer))
     (unless (zerop (#_NewGWorld gworldp 0 bounds-rect (ccl:%null-ptr) (ccl:%null-ptr) 0))
       (error "Failed to make gworld"))
     (ccl:%get-ptr gworldp)))