【问题标题】:Is there a smarter way of using the code located in another namespace有没有更聪明的方法来使用位于另一个命名空间中的代码
【发布时间】:2017-03-25 23:00:58
【问题描述】:

我的核心页面上有这个。创建窗口但不绘制任何东西

(deftype Program []
   GLEventListener
     (display [this drawable] (in-ns 'game-c.drawtriangle))
     (init [this drawable] "init")
     (dispose [this drawable] "dispose")
     (reshape [this drawable x y width height] "reshape")
   )

;set up and start window methods/functions
 (def glp (GLProfile/getDefault))
 (def caps (GLCapabilities. glp))
 (def window (GLWindow/create caps))

 (def ani (FPSAnimator. window 60 true))

 (doto window
  (.addGLEventListener (Program.))
  (.setSize 600 600)
  (.setTitle "CloGame")
  (.setVisible true)
  (.start ani)
 )

这是在窗口上绘制三角形的部分。但它不会那样做。我刚启动repl,它显示空白窗口、函数返回值和错误消息(详情如下)

(ns game-c.drawtriangle)

(def gl (.getGL4 (.getGL window)))
(def tri [ [0.0 0.0] [0.5 0.0] [0.5 0.5] ])
(doto gl
  (.glCreateVertexArrays 1 tri)
)

这是repl输出

#object[clojure.lang.Namespace 0x49db0a8e "game-c.core"]

CompilerException java.lang.RuntimeException: 
com.jogamp.opengl.GLException: Caught IllegalStateException: Can't 
change/establish root binding of: *ns* with set on thread nREPL-worker-
1-Display-.x11_:0-1-EDT-1, compiling:(game-c/core.clj:33:2)

我认为可能有另一种方法可以使用位于 drawtriangle 中的代码,但我不确定你会如何做到这一点

【问题讨论】:

  • 是的,我看过其他类似的问题,但它们似乎是特定的

标签: opengl clojure jogl


【解决方案1】:

试试这个:

(ns game-c.core
  (:require [game-c.drawtriangle :as tri] ))
...
 (display [this drawable] (tri/drawtriangle))
...

(ns game-c.drawtriangle
  (:require [game-c.core :as core] ))
(def gl (.getGL4 (.getGL core/window)))
...

【讨论】:

  • 该排序工作但现在 (def gl...) 无法找到“窗口”变量
猜你喜欢
  • 2010-11-25
  • 2023-03-21
  • 2020-08-28
  • 1970-01-01
  • 2015-04-07
  • 2016-03-28
  • 2010-12-28
  • 1970-01-01
  • 2016-09-10
相关资源
最近更新 更多