Hi,
I'm currently learning OpenGL, using to that end cl-opengl. It comes without saying that one of the main advantages of using Lisp here is the ability to experiment interactively at the REPL. The examples i've seen so far, though, use a blocking call to GLUT:DISPLAY-WINDOW to run (which is OK for such examples, i don't complain), and i was wondering about what would be the best way to have an OpenGL/GLUT window open and manipulate it from a (non-blocked) REPL, maybe even while the GLUT main loop is running. Threads come to mind (i'm using SBCL on Linux), but probably more experienced readers of this list will have some other (or more concrete) advice/code snippets/configurations/whatever to share? Needless to say, pointers to documentation or examples in any form would also be very welcome.
Thanks a lot for your time!
Cheers, jao
On Sat, Jul 12, 2008 at 10:49 PM, Jose A. Ortega Ruiz jao@gnu.org wrote:
what would be the best way to have an OpenGL/GLUT window open and manipulate it from a (non-blocked) REPL, maybe even while the GLUT main loop is running.
If you are using a multi-threaded Lisp, you can redefine e.g. your glut:display method and GLUT's main loop will pick it up. Otherwise, you'll have to interrupt the loop, redefine things, then resume it.
If you want to try GL commands at the REPL and watch their effect interactively then try something like this:
CL-USER> (let ((glut:*run-main-loop-after-display* nil)) (glut:display-window (make-instance 'glut:window))) NIL CL-USER> (progn (gl:clear-color 1 0 0 0) (gl:clear :color-buffer) (gl:flush))
Running glut:main-loop in a separate thread seems to confuse GLUT, so when you need GLUT's help to handle some window event, you can call glut:main-loop-event which only handles at most one event per call, IIUC.
HTH
"Luís Oliveira" luismbo@gmail.com writes:
On Sat, Jul 12, 2008 at 10:49 PM, Jose A. Ortega Ruiz jao@gnu.org wrote:
what would be the best way to have an OpenGL/GLUT window open and manipulate it from a (non-blocked) REPL, maybe even while the GLUT main loop is running.
If you are using a multi-threaded Lisp, you can redefine e.g. your glut:display method and GLUT's main loop will pick it up. Otherwise, you'll have to interrupt the loop, redefine things, then resume it.
Yes, i'm using SBCL/Slime on Linux, and that seems to work so far. I guess that the best way to interrupt the loop (as i've been suggested in a private response) is to use restarts (one more thing for me to learn properly): maybe providing some predefined restarts in cl-opengl itself would be a good idea? (i could even try to send some patches, although i've done very little serious CL programming so far).
If you want to try GL commands at the REPL and watch their effect interactively then try something like this:
CL-USER> (let ((glut:*run-main-loop-after-display* nil)) (glut:display-window (make-instance 'glut:window))) NIL CL-USER> (progn (gl:clear-color 1 0 0 0) (gl:clear :color-buffer) (gl:flush))
Hmm, maybe i'm missing something basic here, but that doesn't work. The new window pops up, totally transparent, but the subsequent PROGN has no effect: the window remains transparent.
Running glut:main-loop in a separate thread seems to confuse GLUT, so when you need GLUT's help to handle some window event, you can call glut:main-loop-event which only handles at most one event per call, IIUC.
Yes, that seems to be the case. For instance, using a window instance with dimensions other than the defaults needs a call to glut:main-loop-event for the resizing to take effect. But then, as i mentioned before, no drawing takes place.
Cheers, jao
On Sun, Jul 13, 2008 at 1:30 PM, Jose A. Ortega Ruiz jao@gnu.org wrote:
Hmm, maybe i'm missing something basic here, but that doesn't work. The new window pops up, totally transparent, but the subsequent PROGN has no effect: the window remains transparent.
Is the window visible while you're evaluating the GL calls? That seems to be necessary in my case, but I guess this behaviour might depend on your window manager, drivers, etc.
"Luís Oliveira" luismbo@gmail.com writes:
On Sun, Jul 13, 2008 at 1:30 PM, Jose A. Ortega Ruiz jao@gnu.org wrote:
Hmm, maybe i'm missing something basic here, but that doesn't work. The new window pops up, totally transparent, but the subsequent PROGN has no effect: the window remains transparent.
Is the window visible while you're evaluating the GL calls? That seems to be necessary in my case, but I guess this behaviour might depend on your window manager, drivers, etc.
Ah, excellent: that made the trick! Thanks!
Cheers, jao
cl-opengl-devel@common-lisp.net