LoginSignup
0
2

More than 5 years have passed since last update.

cl-openglでグラフィックス(文字列描画編:GLisph)

Posted at

Common Lisp+OpenGLで文字列を描画したい

以前書いた記事からいろいろとグラフィックス関連を触ってて、
文字列を描画したくなったので方法を探ってみた結果、
良さそうなものがあったのでありがたく利用させていただいてサンプルを作ってみた。

開発環境

  • Windows 10 x64
  • Steel Bank Common Lisp 1.3.12
  • QuickLisp

使用技術

cl-opengl

先述の記事でも利用したCommon LispからOpenGLを利用するためのライブラリ。
これがないとなにもはじまりません。

GLisph

今回文字列の描画で利用させていただいたライブラリ。
(ql:quickload :glisph)
でインストールできる、便利。

成果物

GLisphのGitHubにあるサンプルをみながらごにょごにょしたサンプルコードをGitHubで公開しています。

動かし方

cd ~/quicklisp/local-project
git clone https://github.com/singy15/cl-opengl-text-sample.git
cd cl-opengl-text-sample
sbcl
(ql:quickload :cl-opengl-text-sample)
(cl-opengl-text-sample:main)

こんなかんじのコードで文字列を描画できる(一部抜粋)。

cl-opengl-text-sample.lisp
;; Variables for GLisph.
(defparameter *font-en* nil)
(defparameter *glyph-table-en* nil)
(defparameter *text-en* #("text drawing sample"))

;; 初期化処理
(defmethod glut:display-window :before ((window main-window))
  ;; Initialize GLisph.
  (gli:init *width* *height*)
  (setf *font-en* (gli:open-font-loader #p"./font/Ubuntu-R.ttf"))
  (setf *glyph-table-en* (gli:make-glyph-table *font-en*))
  (loop for text across *text-en*
        do (gli:regist-glyphs *glyph-table-en* text))
  (setf *text-en*
        (gli:draw *glyph-table-en*
                  '(:size 20 :x 0 :y 0 :text (aref *text-en* 0)))))

;; 描画処理
(defmethod glut:display ((window main-window))
   ; ...
   ;; Draw text
  (gl:clear-stencil 0)
  (gl:clear :color-buffer-bit :stencil-buffer-bit)
  (gli:gcolor 1.0 1.0 1.0 1.0)
  (gli:render *text-en*)
  ; ...
)

こんなかんじの画面がでます。

cl-opengl-text-sample.png

疑問点など

  • OpenGLの描画モード??にstencilとmultisampleを指定している意味がよくわかってない。
  • draw-stringという関数が使えるらしいんだけど、使い方がよくわからなかった。シンボルがエクスポートされてないっていわれる。

参考にしたサイトなど

Common LispでGPUベクトルベースフォントレンダリング
GitHub - GLisph

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2