我在运行teapot example from cl-opengl package。我所做的唯一更改是加载所需的包。它在unix shell (sbcl --load "3.cl")中运行良好,但当我试图通过SLIME (C-c C-k)编译和加载它时,我得到了关于GLUT包未找到的错误。
奇怪的是,编译器在(defclass glut-teapot-window (glut:window)上卡住了。怎么回事?
Here's a screenshot of what happens
这是3.cl的代码。
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*-
;;; glut-teapot.lisp --- Simple usage of glut:solid-teapot.
(ql:quickload :cl-opengl)
(ql:quickload :cl-glu)
(ql:quickload :cl-glut)
;(setf *communication-style* :fd-handler)
(defclass glut-teapot-window (glut:window)
()
(:default-initargs :width 250 :height 250 :title "glut-teapot.lisp"
:mode '(:single :rgb :depth)))
(defmethod glut:display-window :before ((w glut-teapot-window))
(gl:clear-color 0 0 0 0)
(gl:cull-face :back)
(gl:depth-func :less)
(gl:disable :dither)
(gl:shade-model :smooth)
(gl:light-model :light-model-local-viewer 1)
(gl:color-material :front :ambient-and-diffuse)
(gl:enable :light0 :light1 :lighting :cull-face :depth-test))
(defmethod glut:display ((window glut-teapot-window))
(gl:load-identity)
(gl:translate 0 0 -5)
(gl:rotate 30 1 1 0)
(gl:light :light0 :position '(100 1000 1 0))
(gl:light :light0 :diffuse '(1.2 0.4 0.6 0))
(gl:light :light1 :position '(-100 1000 1 0))
(gl:clear :color-buffer :depth-buffer)
(gl:color 1 10 1)
(gl:front-face :cw)
(glut:solid-teapot 1.3)
;(glut:solid-torus 0.5 1.0 50 50)
;(glu:cylinder (glu:new-quadric) 0.5 0.5 0.5 20 20)
(gl:front-face :ccw)
(gl:flush))
(defmethod glut:reshape ((window glut-teapot-window) width height)
(gl:viewport 0 0 width height)
(gl:matrix-mode :projection)
(gl:load-identity)
(glu:perspective 50 (/ width height) 0.5 20)
(gl:matrix-mode :modelview)
(gl:load-identity))
(defmethod glut:keyboard ((window glut-teapot-window) key x y)
(declare (ignore x y))
(when (eql key #\Esc)
(glut:destroy-current-window)))
(defun glut-teapot ()
(glut:display-window (make-instance 'glut-teapot-window)))
(glut-teapot)发布于 2013-02-23 02:25:30
如果加载文件,Lisp系统将按表达式读取文件表达式,并在读取每个表达式后执行它们。
如果您在新的Lisp中编译该文件,那么它将读取表达式并编译它们。但它不会执行它们。因此,它看到了快速加载命令,编译了它,但不执行它。此OpenGL代码未加载,并且编译器不知道这些包。但这是有道理的:编译器通常应该编译文件,而不是执行它。Lisp将在加载编译后的fasl文件时执行表达式。
有两种简单的方法可以绕过它:
EVAL-WHEN语句中。(eval-when (:execute :load-toplevel :compile-toplevel) ... your code here ...).:compile-toplevel符号表示,当编译器将代码视为顶级表单时,代码将被执行。否则它是不会这么做的。因此,你可以在一个文件中编译代码,这会产生副作用--在这里加载其他代码。
https://stackoverflow.com/questions/15029420
复制相似问题