我試圖代碼this現代的OpenGL教程轉換成CL,但如果我啓動我的程序,沒有什麼事情一個新窗口打開,我必須重新啓動整個窗口管理器,所以很難調試。使用CL-的OpenGL着色器
我的代碼(使用SDL2,而不是過剩):
(defun to-gl-array (seq type
&aux
(length (length seq))
(array (gl:alloc-gl-array type length)))
(dotimes (i length)
(setf (gl:glaref array i) (aref seq i))))
(defvar *vs* (gl:create-shader :vertex-shader))
(defvar *vs-source*
"#version 330
attribute vec2 c2d;
void main(void) {
gl_Position = vec4(c2d, 0.0, 1.0);
}
")
(defvar *fs* (gl:create-shader :fragment-shader))
(defvar *fs-source*
"#version 330
void main(void) {
gl_FragColor[0] = 0.0;
gl_FragColor[1] = 0.0;
gl_FragColor[2] = 1.0;
}
")
(defvar *c2d*)
(defvar *program* (gl:create-program))
(defun init()
(gl:shader-source *vs* *vs-source*)
(gl:compile-shader *vs*)
(gl:shader-source *fs* *fs-source*)
(gl:compile-shader *fs*)
(gl:attach-shader *program* *vs*)
(gl:attach-shader *program* *fs*)
(gl:link-program *program*)
(setq *c2d* (gl:get-attrib-location *program* "c2d")))
(defun run (&aux triangle)
(gl:use-program *program*)
(gl:enable-vertex-attrib-array *c2d*)
(setq triangle (to-gl-array #(0.0 768.0
1280.0 768.0
640.0 0.0) :float))
(gl:vertex-attrib-pointer *c2d* 2 :float nil 0 triangle)
(gl:free-gl-array triangle)
(gl:draw-arrays :triangles 0 3)
(gl:disable-vertex-attrib-array *c2d*))
(defun free()
(gl:delete-program *program*))
(defun start()
(init)
(sdl2:with-init (:everything)
(sdl2:with-window (win :w 1280 :h 768 :flags '(:shown :opengl :resizable))
(sdl2:with-gl-context (gl-context win)
(gl:ortho 0 1280 768 0 -1 1)
(gl:clear-color 0 0 0 1)
(sdl2:with-event-loop (:method :poll)
(:quit() t)
(:windowevent (:data1 w :data2 h)
(sdl2:set-window-size win w h))
(:keydown (:keysym key)
(and (sdl2:scancode= (sdl2:scancode-value key) :scancode-escape)
(sdl2:push-event :quit)))
(:idle()
(gl:clear :color-buffer)
(gl:color 0 0 1)
(run)
(gl:flush)
(sdl2:gl-swap-window win))
(finish-output)))))
(free))
什麼是讓(現代)的OpenGL與CL工作的最佳方式? 我應該使用另一個教程(也許用於常見的lisp?我沒有找到一個)或其他庫(例如lispy glsl或不sdl2)?
它沒有工作。 – 2015-03-31 09:23:22