-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathopengl-view.lisp
39 lines (33 loc) · 1.31 KB
/
opengl-view.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(in-package :cl-nextstep)
(defclass opengl-view (base-view)
((core-profile :initarg :core-profile
:initform nil
:reader core-profile)
(animate :initarg :animate
:initform nil
:reader animate)
(retina :initarg :retina
:initform nil
:reader retina)))
(defmethod reshape ((self opengl-view))
())
(defmethod initialize-instance :after ((self opengl-view) &key (x 0) (y 0) (w 400) (h 200))
(let* ((pixel-format (cgl:make-pixel-format (cgl:list-attributes
:core-profile (core-profile self)))))
(unwind-protect (let* ((gl-view (ns:objc
(ns:objc "LispOpenGLView" "alloc" :pointer)
"initWithID:frame:pixelFormat:isAnimate:drawFn:eventFn:"
:int (id self)
(:struct ns:rect) (ns:rect x y w h)
:pointer pixel-format
:unsigned-char (if (animate self) 1 0)
:pointer (cffi:callback view-draw-callback)
:pointer (cffi:callback view-event-callback)
:pointer)))
(set-gl-best-resolution gl-view (retina self))
(setf (cocoa-ref self) gl-view))
(cgl:destroy-pixel-format pixel-format))))
(defun set-gl-best-resolution (opengl-view setup)
(ns:objc (cocoa-ref opengl-view) "setWantsBestResolutionOpenGLSurface:" :bool setup))
(defun display-link (opengl-view)
(objc opengl-view "link" :pointer))