diff -rN -u old-cl-opengl/glut/callbacks.lisp new-cl-opengl/glut/callbacks.lisp
--- old-cl-opengl/glut/callbacks.lisp	2009-06-02 20:49:42.000000000 -0400
+++ new-cl-opengl/glut/callbacks.lisp	2009-06-02 20:49:42.000000000 -0400
@@ -137,11 +137,13 @@
   (poll-interval :int))
 
 ;; freeglut ext
+#-darwin
 (defcfun ("glutMouseWheelFunc" mouse-wheel-func) :void
   ;; void (*func)(int button, int pressed, int x, int y)
   (callback-pointer :pointer))
 
 ;; freeglut ext
+#-darwin
 (defcfun ("glutCloseFunc" close-func) :void
   ;; void (*func)(void)
   (callback-pointer :pointer))
@@ -152,6 +154,7 @@
   (callback-pointer :pointer))
 
 ;; freeglut ext
+#-darwin
 (defcfun ("glutMenuDestroyFunc" menu-destroy-func) :void
   ;; void (*func)(void)
   (callback-pointer :pointer))
diff -rN -u old-cl-opengl/glut/fonts.lisp new-cl-opengl/glut/fonts.lisp
--- old-cl-opengl/glut/fonts.lisp	2009-06-02 20:49:42.000000000 -0400
+++ new-cl-opengl/glut/fonts.lisp	2009-06-02 20:49:42.000000000 -0400
@@ -107,19 +107,21 @@
   (string :string))
 
 ;; freeglut ext
+#-darwin 
 (defcfun ("glutBitmapHeight" bitmap-height) :int
   (font :pointer))
 
 ;; freeglut ext
+#-darwin
 (defcfun ("glutStrokeHeight" stroke-height) %gl:float
   (font :pointer))
 
 ;; freeglut ext
-(defcfun ("glutBitmapString" bitmap-string) :void
+#-darwin (defcfun ("glutBitmapString" bitmap-string) :void
   (font :pointer)
   (string :string))
 
 ;; freeglut ext
-(defcfun ("glutStrokeString" stroke-string) :void
+#-darwin (defcfun ("glutStrokeString" stroke-string) :void
   (font :pointer)
   (string :string))
\ No newline at end of file
diff -rN -u old-cl-opengl/glut/geometry.lisp new-cl-opengl/glut/geometry.lisp
--- old-cl-opengl/glut/geometry.lisp	2009-06-02 20:49:42.000000000 -0400
+++ new-cl-opengl/glut/geometry.lisp	2009-06-02 20:49:42.000000000 -0400
@@ -92,34 +92,34 @@
 
 ;;; The following are freeglut extensions:
 
-(defcfun ("glutWireRhombicDodecahedron" wire-rhombic-dodecahedron) :void)
-(defcfun ("glutSolidRhombicDodecahedron" solid-rhombic-dodecahedron) :void)
+#-darwin (defcfun ("glutWireRhombicDodecahedron" wire-rhombic-dodecahedron) :void)
+#-darwin (defcfun ("glutSolidRhombicDodecahedron" solid-rhombic-dodecahedron) :void)
 
-(defcfun ("glutWireSierpinskiSponge" %glutWireSierpinskiSponge) :void
+#-darwin (defcfun ("glutWireSierpinskiSponge" %glutWireSierpinskiSponge) :void
   (num-levels :int)
   (offset-seq :pointer) ; GLdouble offset[3]
   (scale %gl:double))
 
-(defun wire-sierpinski-sponge (num-levels offset-seq scale)
+#-darwin (defun wire-sierpinski-sponge (num-levels offset-seq scale)
   (gl::with-opengl-sequence (offset '%gl:double offset-seq)
     (%glutWireSierpinskiSponge num-levels offset scale)))
 
-(defcfun ("glutSolidSierpinskiSponge" %glutSolidSierpinskiSponge) :void
+#-darwin (defcfun ("glutSolidSierpinskiSponge" %glutSolidSierpinskiSponge) :void
   (num-levels :int)
   (offset-seq :pointer) ; GLdouble offset[3]
   (scale %gl:double))
 
-(defun solid-sierpinski-sponge (num-levels offset-seq scale)
+#-darwin (defun solid-sierpinski-sponge (num-levels offset-seq scale)
   (gl::with-opengl-sequence (offset '%gl:double offset-seq)
     (%glutSolidSierpinskiSponge num-levels offset scale)))
 
-(defcfun ("glutWireCylinder" wire-cylinder) :void
+#-darwin (defcfun ("glutWireCylinder" wire-cylinder) :void
   (radius %gl:double)
   (height %gl:double)
   (slices %gl:int)
   (stacks %gl:int))
 
-(defcfun ("glutSolidCylinder" solid-cylinder) :void
+#-darwin (defcfun ("glutSolidCylinder" solid-cylinder) :void
   (radius %gl:double)
   (height %gl:double)
   (slices %gl:int)
diff -rN -u old-cl-opengl/glut/init.lisp new-cl-opengl/glut/init.lisp
--- old-cl-opengl/glut/init.lisp	2009-06-02 20:49:42.000000000 -0400
+++ new-cl-opengl/glut/init.lisp	2009-06-02 20:49:42.000000000 -0400
@@ -43,16 +43,23 @@
   #-(and sbcl (or x86 x86-64))
   `(progn ,@body))
 
+(defparameter *glut-initlialized-p* nil)
+
+(defun glut-initialized ()
+  #-darwin (getp :init-state)
+  #+darwin *glut-initlialized-p*)
+
 (defun init (&optional (program-name (lisp-implementation-type)))
   (without-fp-traps
     ;; freeglut will exit() if we try to call initGlut() when
     ;; things are already initialized.
-    (unless (getp :init-state)
+    (unless (glut-initialized)
       (with-foreign-objects ((argcp :int) (argv :pointer))
         (setf (mem-ref argcp :int) 1)
         (with-foreign-string (str program-name)
           (setf (mem-ref argv :pointer) str)
-          (%glutInit argcp argv)))
+          (%glutInit argcp argv)
+          (setf *glut-initlialized-p* t)))
       ;; By default, we choose the saner option to return from the event
       ;; loop on window close instead of exit()ing.
       (set-action-on-window-close :action-continue-execution)
diff -rN -u old-cl-opengl/glut/interface.lisp new-cl-opengl/glut/interface.lisp
--- old-cl-opengl/glut/interface.lisp	2009-06-02 20:49:42.000000000 -0400
+++ new-cl-opengl/glut/interface.lisp	2009-06-02 20:49:42.000000000 -0400
@@ -188,8 +188,8 @@
   ;;                           (z :int)))
   (mouse-wheel      (window (button mouse-button) (pressed mouse-button-state)
                             (x :int) (y :int)))
-  (close            (window))
-  ;; (wm-close         (window)) ; synonym for CLOSE
+  #-darwin (close            (window))
+  #+darwin ( wm-close         (window)) ; synonym for CLOSE
   (menu-destroy     (window)))
 
 ;;; These two functions should not be called directly and are called
diff -rN -u old-cl-opengl/glut/library.lisp new-cl-opengl/glut/library.lisp
--- old-cl-opengl/glut/library.lisp	2009-06-02 20:49:42.000000000 -0400
+++ new-cl-opengl/glut/library.lisp	2009-06-02 20:49:42.000000000 -0400
@@ -32,9 +32,23 @@
 
 (in-package :cl-glut)
 
+;; In darwin, if we don't load cocoa first,
+;; it crashes with the following message:
+;;  "GLUT Fatal Error: internal error: NSInternalInconsistencyException, 
+;;   reason: Error (1002) creating CGSWindow"
+#+darwin 
+(define-foreign-library cocoa
+  ((:and :darwin :x86) (:framework "Cocoa")))
+
 (define-foreign-library glut
-  (:darwin (:or "libglut.dylib" "libglut.3.dylib"))
+  ;(:darwin (:or "libglut.dylib" "libglut.3.dylib"))
+  (:darwin (:framework "GLUT"))
+  ;(:darwin (:or "libopenglut.dylib" "libopenglut.3.dylib"))
   (:windows "freeglut.dll")
   (:unix (:or "libglut.so" "libglut.so.3")))
 
-(use-foreign-library glut)
\ No newline at end of file
+(use-foreign-library cocoa)
+(use-foreign-library glut)
+
+(cffi:defcfun ("NSApplicationLoad" nsapplicationload) :int)
+;(nsapplicationload)
diff -rN -u old-cl-opengl/glut/main.lisp new-cl-opengl/glut/main.lisp
--- old-cl-opengl/glut/main.lisp	2009-06-02 20:49:42.000000000 -0400
+++ new-cl-opengl/glut/main.lisp	2009-06-02 20:49:42.000000000 -0400
@@ -33,12 +33,33 @@
 (in-package #:cl-glut)
 
 (defcfun ("glutMainLoop" %glutMainLoop) :void)
+#+darwin (defcfun ("glutCheckLoop" check-loop) :void)
 
+;; setting this variable to false will
+;; stop opengl
+#+darwin (let ((darwin-run-main-loop t))
+           (defun darwin-main-loop ()
+             (unwind-protect
+                  (progn
+                    (format t "check-loop~%")
+                    (loop while darwin-run-main-loop do (check-loop))
+                    (format t "check-loop end~%"))
+               (init)
+               (setf darwin-run-main-loop t)))
+           
+           (defun leave-main-loop ()
+             (setf darwin-run-main-loop nil)))
+             
+#-darwin (defun normal-main-loop ()
+           (without-fp-traps
+             (%glutMainLoop))
+           (init))
+               
 (defun main-loop ()
-  (without-fp-traps
-    (%glutMainLoop))
-  (init))
+  #-darwin (normal-main-loop)
+  #+darwin (darwin-main-loop))
+  
 
-(defcfun ("glutMainLoopEvent" main-loop-event) :void)
+#-darwin (defcfun ("glutMainLoopEvent" main-loop-event) :void)
 
-(defcfun ("glutLeaveMainLoop" leave-main-loop) :void)
\ No newline at end of file
+#-darwin (defcfun ("glutLeaveMainLoop" leave-main-loop) :void)
\ No newline at end of file
diff -rN -u old-cl-opengl/glut/misc.lisp new-cl-opengl/glut/misc.lisp
--- old-cl-opengl/glut/misc.lisp	2009-06-02 20:49:42.000000000 -0400
+++ new-cl-opengl/glut/misc.lisp	2009-06-02 20:49:42.000000000 -0400
@@ -73,9 +73,11 @@
 (defcfun ("glutGameModeString" game-mode-string) :void
   (string :string))
 
-(defcfun ("glutEnterGameMode" enter-game-mode) :int)
+#-darwin (defcfun ("glutEnterGameMode" enter-game-mode) :int)
+#+darwin (defcfun ("glutEnterGameMode" enter-game-mode) :void)
 (defcfun ("glutLeaveGameMode" leave-game-mode) :void)
 
+
 (defcenum (game-mode-param %gl:enum)
   :game-mode-active
   :game-mode-possible
diff -rN -u old-cl-opengl/glut/state.lisp new-cl-opengl/glut/state.lisp
--- old-cl-opengl/glut/state.lisp	2009-06-02 20:49:42.000000000 -0400
+++ new-cl-opengl/glut/state.lisp	2009-06-02 20:49:42.000000000 -0400
@@ -54,9 +54,11 @@
   (:window-cursor #x007A))
 
 ;;; freeglut ext
-(defcfun ("glutSetOption" set-option) :void
+#-darwin (defcfun ("glutSetOption" set-option) :void
   (option options)
   (value :int))
+#+darwin (defun set-option (val1 val2)
+           (declare (ignore val1 val2)))
 
 ;;; Also provide some utility functions around glutSetOption().
 
@@ -156,7 +158,7 @@
   :window-border-width                  ; freeglut ext
   :window-header-height                 ; freeglut ext
   :version                              ; freeglut ext
-  :rendering-context                    ; freeglut ext
+  #-darwin :rendering-context                    ; freeglut ext
   :direct-rendering)
 
 (defcfun ("glutGet" get) :int

