Lisp, Windows and OpenGL

Discussion of Common Lisp
Post Reply
Akira
Posts: 5
Joined: Wed Aug 20, 2008 5:21 am

Lisp, Windows and OpenGL

Post by Akira » Wed Aug 20, 2008 5:43 am

I'm thinking of giving Lisp (common Lisp - CLISP) a try. Paul Graham sounds like a fanboy, but at least has let me wondering. I'm reading a lot of things in the Net, but a part from one pdf that I downloaded (a comparison between programs written in Java, C and Lisp), there is nothing that sways me either to go for it or not, so a bit of practice and first hand experience is needed, I think.

Now, what I'm really interested in are two things:
Can I code programs for Windows? (as in creating a window with its toolbars and what-not). Of course it will be nice to know as well if it can be done for Linux (either KDE or Gnome) and MacOsX, but the preference for the time been is Windows XP.

How can I use OpenGL? There seem to be bindings for it, but nothing that I have read lets me completely convinced. Maybe a better explanation of any of them would be required. I don't want just to use opengl, but use it with really good speed.

Thank you,
Akira

Harnon
Posts: 78
Joined: Wed Jul 30, 2008 9:59 am

Re: Lisp, Windows and OpenGL

Post by Harnon » Wed Aug 20, 2008 6:21 am

Well, cl-opengl is a good binding. Basically, you use it the same way you would use it in c. What i would be asking though
is how to incorporate Opengl into a windows window which has buttons, menu items, etc (i'm sure theres a way, but i don't
know how). Also, warning, i *think* the glut:keyboard thing is screwed up. It passes a character code (integer) instead of the actual character. This is easily fixed, though, by defining a :before method on glut:keyboard and using
(code-char num). Here's the main website
http://common-lisp.net/project/cl-opengl/
You have to use darcs get to retrieve it, download darcs from internet if you don't have it.
Here's an example from its example files:

Code: Select all

(defpackage :example (:use :cl :gl :glu :glut)) ;;i added this
(in-package :example) ;;i added this
;;rest is from line.lisp example
(defun draw-one-line (x1 y1 x2 y2)
  (gl:with-primitives :lines
    (gl:vertex x1 y1)
    (gl:vertex x2 y2)))

(defclass lines-window (glut:window)
  ()
  (:default-initargs
   :width 400 :height 150 :pos-x 100 :pos-y 100
   :mode '(:single :rgb) :title "lines.lisp"))

(defmethod glut:display-window :before ((w lines-window))
  (gl:clear-color 0 0 0 0)
  (gl:shade-model :flat))

(defmethod glut:display ((w lines-window))
  (gl:clear :color-buffer-bit)
  ;; Select white for all lines.
  (gl:color 1 1 1)
  ;; In 1st row, 3 lines, each with a different stipple.
  (gl:enable :line-stipple)
  (gl:line-stipple 1 #b0000000100000001) ; dotted
  (draw-one-line 50 125 150 125)
  (gl:line-stipple 1 #b0000000011111111) ; dashed
  (draw-one-line 150 125 250 125)
  (gl:line-stipple 1 #b0001110001000111) ; dash/dot/dash
  (draw-one-line 250 125 350 125)
  ;; In 2nd row, 3 wide lines, each with different stipple.
  (gl:line-width 5)
  (gl:line-stipple 1 #b0000000100000001) ; dotted
  (draw-one-line 50 100 150 100)
  (gl:line-stipple 1 #b0000000011111111) ; dashed
  (draw-one-line 150 100 250 100)
  (gl:line-stipple 1 #b0001110001000111) ; dash/dot/dash
  (draw-one-line 250 100 350 100)
  (gl:line-width 1)
  ;; In 3rd row, 6 lines, with dash/dot/dash stipple as part
  ;; of a single connected line strip.
  (gl:line-stipple 1 #b0001110001000111) ; dash/dot/dash
  (gl:with-primitives :line-strip
    (dotimes (i 7)
      (gl:vertex (+ 50 (* i 50)) 75)))
  ;; In 4th row, 6 independent lines with same stipple.
  (dotimes (i 6)
    (draw-one-line (+ 50 (* i 50)) 50
                   (+ 50 (* (1+ i) 50)) 50))
  ;; In 5th row, 1 line, with dash/dot/dash stipple and
  ;; a stipple repeat factor of 5.
  (gl:line-stipple 5 #b0001110001000111) ; dash/dot/dash
  (draw-one-line 50 25 350 25)
  ;; Finally,
  (gl:disable :line-stipple)
  (gl:flush))

(defmethod glut:reshape ((w lines-window) width height)
  (gl:viewport 0 0 width height)
  (gl:matrix-mode :projection)
  (gl:load-identity)
  (glu:ortho-2d 0 width 0 height))

(defmethod glut:keyboard ((w lines-window) key x y)
  (declare (ignore x y))
  (when (eql key #\Esc)
    (glut:destroy-current-window)))

(defun rb-lines ()
  (glut:display-window (make-instance 'lines-window)))

Akira
Posts: 5
Joined: Wed Aug 20, 2008 5:21 am

Re: Lisp, Windows and OpenGL

Post by Akira » Wed Aug 20, 2008 8:07 am

Thanks for the answer.

I'm not worried about mixing opengl and Windows windows. The OpenGl windows that I will create for the time being will be full screen, with no toolbars or anything.

From what I can read to be able to create windows and such I will have somehow to use cffi to call the WinAPI?

Wodin
Posts: 56
Joined: Sun Jun 29, 2008 8:16 am

Re: Lisp, Windows and OpenGL

Post by Wodin » Wed Aug 20, 2008 1:47 pm

Akira wrote:From what I can read to be able to create windows and such I will have somehow to use cffi to call the WinAPI?
Have a look at Graphic-Forms. I haven't used it, but it seems to be what you're looking for.

Of course, the web site also says:
Graphic-Forms is in the alpha stage of development, meaning new features are still being added and existing features require considerable testing. Be advised that significant API and behavior changes are likely for at least several more releases.

qbg
Posts: 64
Joined: Mon Jun 30, 2008 1:05 pm
Location: Minnesota

Re: Lisp, Windows and OpenGL

Post by qbg » Wed Aug 20, 2008 2:40 pm

For making GUIs, there are a number of binding to GTK (see this Cliki page; I think some of them should work on Windows).

There are other toolkits (Ltk uses Tk; I'd guess it would work on windows)

LispWorks (commercial implementation) provides CAPI which is cross-platform.

Akira
Posts: 5
Joined: Wed Aug 20, 2008 5:21 am

Re: Lisp, Windows and OpenGL

Post by Akira » Wed Aug 20, 2008 11:10 pm

Thanks again. I will try them ... once I manage to have an idea of what I'm doing.

Flatlander
Posts: 8
Joined: Sat Jun 28, 2008 12:06 pm
Location: Finland

Re: Lisp, Windows and OpenGL

Post by Flatlander » Thu Aug 21, 2008 9:20 am

Maybe PAL (http://common-lisp.net/project/pal/ ) would work for you? It uses OpenGL and should work with CLisp. There is a simple windows demo build with SBCL at http://www.yellow-hut.com/blog/wp-conte ... ermuda.zip to see how it works in practice (the Bermuda demo is not yet included with PAL but there are other simple examples that should get you going).

stefano
Posts: 3
Joined: Sun Aug 17, 2008 6:55 am

Re: Lisp, Windows and OpenGL

Post by stefano » Thu Aug 28, 2008 4:03 am

A really good library for GUI applications is cells-gtk: http://common-lisp.net/project/cells-gtk/
You probably want the cvs version (the tarball linked from the home page is quite out of date) because it has support for integrating an OpenGL widget. It doesn't have much documentation, but you should be able to use it by reading the many examples included. It is really easy to use.

Jasper
Posts: 209
Joined: Fri Oct 10, 2008 8:22 am
Location: Eindhoven, The Netherlands
Contact:

Re: Lisp, Windows and OpenGL

Post by Jasper » Fri Oct 10, 2008 9:13 am

I use cl-sdl and cl-opengl together, that works, on ubuntu at least. That doesn't give you anything to make UI widgets with, though.

GLUTs keyboard and mouse input is just plain limited, afaik. I remember using it in c(++?) and just hitting walls, but forgot what the limitations were. I wouldn't use it except for examples and practice.

Post Reply