Spare time projects: OpenGL and Lisp

2011-07-06 21:08:29 PST

Tags: , ,

So as you may know I’m trying to keep up with programming exploratory side projects in my spare time, somewhat spurred on by among many things, The Cult of Done. After learning a bit about HTML5 and Canvas and writing the The Game of Life for Canvas I wanted to move on to something more meaty. That’s about as far as I’d ever gone in graphics programming so I wanted to keep pushing on in that vein for a bit. So I figured why not check out 3D land. I briefly looked at WebGL but it’s not entirely ready just yet. Some of the tech demos look decent but for one thing, there’s almost no interactivity in the more complicated ones like flight sims, I assume because a good IO system isn’t in place, so I figured why not go for straight up OpenGL.

The defacto language for OpenGL programming is C/C++ however I’ve done my share of C programming and I’m enjoying higher level languages for many things these days. I have an ok relationship with Python but it doesn’t get me excited or anything, and I’m still working at getting better at Lisp which I am fond of so I thought why not use this as another excuess to work in Lisp? And so against some people’s advice I’ve been exploring OpenGL programmign in Lisp.

I Googled around and found that the basic package is cl-opengl and using Quicklisp got that installed and found a very basic tutorial for getting a window to show with a tutorial at from NeHe. It worked okish but not really. Then I found’s cl-opengl tutorials which were better. They used SDL instead of GLUT to make a window and the first one worked and I had a raindow triangle. Instead of going on, I started looking at the tutorial’s in C and tried translating them. I worked through the cube.c one, but it didn’t quite work, so after a bit I gave up.

I went back to the 3bb code and instead of continuing on with the tutorials, I just started working on it myself and googling for parts I needed and getting some help from a friend who’d done some heavier OpenGL programming in C. I made the color change over time (like I learned for the game of life). Then I made the triangle spin. Then I added a second back triangle and made them spin. Then I fleshed it out and made pyramid, then a diamond that spun. Then I finally made the spinning color changing diamond that also moved in a circle, refactoring the code a few times in the process.

Now I have a nice simple tech demo and some code and understandings of the basics of OpenGL and 3D programming. For about 8 days work in spare time I am very pleased. I have more plans to move on to from here, but I’ll probably start a new project for it. The code for all my demos is on github at The only one that really works is 3bb.lisp and you need cl-opengl and lispbuilder-SDL.

Something I discovered is that the linear algebra scene for Lisp is confusing and a mess (IMHO). There are a bunch of projects for it, all kind of a mess with no apparent blessed/defacto standard library. I looked at L-math, but the version in quicklisp seemed a bit broken :/. This whole Lisp philosophy of always using the latest dev code instead of stable releases seems… against better sense. And seemed to fail me here. I looked at Femlisp/matlisp but their own FAQ talked about how their linear algebra implementation was slow and that’s all I wanted it for. So in the end I just rolled my own. It was fun and I had to remember some basic math from a few years ago.

Here’s the final product:

View on YouTube

Drupal + Google Search Appliance + Multiple languages and collections

2011-07-06 20:29:10 PST

Tags: , , ,

So at work we use Drupal a lot. And one of our clients has a Google Search Appliance (mini google in a box installed in their datacenter for their personal use) and runs sites that operate in multiple languages. So we installed the Drupal GSA module, flicked it on, and had Google searches. Of course since we had multiple languages, we set up GSA collections, one collection for each language. Easy enough. But by default the Drupal GSA module only takes one collection in it’s admin page. So we did what we always do in this situation, we made the collection a multilingual variable, a kind of Drupal hack that enables that variable to have different values transparently depending on the site’s language. Then we input each GSA collection into each language/site’s GSA config. Done and good to go? Nope. All the searches were still in English for all the sites. So on the French site we cleared the cache and then the searches were in French! … for all the sites. The Drupal GSA module was deeply not designed to work with multiple languages/collections it turned out.

After about 2 hours debugging we figured it all out. When the module is initialized, it pulls out all the config data, puts it in a hash, and hands it off to Drupal in the menu hook. Drupal stores it forever, and hands it off to the search function whenever it is called and so what ever language is active when the module is initialized determines what colleciton is used forever for all languages. Not cunning. The fix however was straight forward and one line: in the search function, just disregard the passed in settings value for the collection and re-pull it.

For what it’s worth I filed a bug and patch (against 6.x-2.0-beta1, though it should work fine for all versions) with the module at but it seems it’s suffering from low maintainership.

Here it is as well, though it’s probably just as easy to copy/paste the line in directly.

Index: google_appliance.module
--- google_appliance.module	(revision 14982)
+++ google_appliance.module	(working copy)
@@ -1055,6 +1055,9 @@
  *   Themed search results.
 function google_appliance_search_view($search_base, $client, $collection, $keys = NULL, $title = NULL) {
+  $collection =  trim(variable_get('google_appliance_default_collection', 'default_collection'));
   $form = drupal_get_form('google_appliance_search_form', NULL, $search_base, $client, $collection, $keys);
   // When POSTing back to an existing search-results page, the original
   // URL is accessed (which re-runs that search) and then the redirect for

Now it works just fine and all our different language sites have searches and results in just their language. Splendid!

Twitter Updates for 2011-06-29

2011-06-29 10:00:00 PST

  • # uptime
    12:09:29 up 18 days, 21:27, 8 users, load average: 41.03, 24.61, 11.14 #

Note on Javascript (all?) closures and the difference between reference and value

2011-06-22 13:21:10 PST

Tags: , ,
for(var i=0; i< 10; i++) { var t = setTimeout( function () { alert(i);}, 200); }

This will results in 10 alerts all saying ’10’ and not as some might think 10 alerts of 1, 2, 3, …, 9, 10. This is because the function being called is a closure and contains a reference to i, not the value of i. When the first one is finally called, 200ms later, i contains the value of 10 since the loop is done executing when the function looks i up. I suspect this has caused some people some headaches.

You can easily test this in Chrome’s javascript console as I did first ;)

links for 2011-06-21

2011-06-21 00:01:17 PST

Game of Life in HTML/Canvas

2011-06-20 23:08:53 PST

Tags: , ,

I’ve been wanting to play with HTML5’s canvas for a bit now and I’ve always liked Conway’s game of life since it was introduced to me in first year CS so it seemed like a good match. In the spare time of a few days I was easily able to cobble it together, and even add some nice controls and one novel (to me) feature: the rainbow color age effect, which cycles the color of the cells and darkens them with age so you can quickly see the age of cells on the board and get a pretty show.

The code is on github and you can see it live on the demo I put up.

HTML5’s canvas is fun for simple things like this. I don’t know how it would a) hold up for more complicated and practical applications, and b) how much “fun” it would still be. Maybe I’ll find out, maybe not.

links for 2011-06-19

2011-06-19 00:00:53 PST

Twitter Updates for 2011-06-17

2011-06-17 10:00:00 PST

  • Big <3 to all the volunteers who have come out to clean. The city looks… better :/ #

Twitter Updates for 2011-06-16

2011-06-16 10:00:00 PST

  • So proud of the patience the VPD is showing! You guys rock! We're sorry #

Fedora 15 / Gnome Shell

2011-06-14 21:08:56 PST

Tags: , ,

So after a few failed attempts at installing Ubuntu 11.04 on my parents computer I thought I’d give Fedora 15 a try. It worked.

The install was pretty painless, and no weird unresponsive 10 to 20 minute pauses, so that was nice. Rebooted, logged into Gnome Shell.

It’s ok. It’s not bad. I like it better than Unity, but both of them suffer from the developer “my hands are always on the keyboard, why can’t I launch apps by search” syndrome. That’s cool for you, but sometimes if I have one hand on the mouse I just want to use the mouse to lauch apps and having to fling or click the top left of the screen, then move to the other side to click applications and the find my app in an unsorted list that over fills a screen is not optimal. At least Gnome Shell obviously offers the categories on the side to filter by. But at this point it is way way slower than the old Gnome menu was. Also, not offering an window list for me to easily toggle between apps? Either I again have to fling or click the top left and the select my window from a different display or Alt-Tab it. It’s like these new exciting GUIs are less friendly to traditional graphical interface tools like… a mouse. They are more friendly to keyboard combos.

Still, ranting aside, Gnome Shell was ok, and definatly better than Unity. And it and Fedora were more stable, why, this system has been runing for over an hour, and no random crashes. There are a few visual artifacts but I guess that’s just what I get for runing Linux on a new AMD Radeon 6500. Maybe in half a year there won’t be visual artifacts.

What really got me though was how much worse package management is on Fedora than it is on Ubuntu. It’s a colossal pain. Ubuntu / Debian have really spoiled me. Flash didn’t come with the system, so I followed online advice and downloaded the YUM and then it installed and nothing happened. But then flash was in the package manager, except it just sat there with a “Waiting in queue” message doing nothing for like 10 minuets with no way to fix. Awesome. And searching for apps? *Office also doesn’t come installed, and good luck trying to find it. I search Libre Office all kinds of ways. Among the truly large amount of not Libre Office results, the one that was closest that I usually got was “Libre Office development”… I eventually gave up and found a .doc file and tried to open it and Fedora then asked me if I wanted to install Libre Office Writer. Why yes I would. Then the installer went to work, it looked like it froze on the download, but with so little feed back it was hard to tell so I left it alone for a while and it sorted it self out. It’s just really not remotely helpful.

Finally, one of my mom’s favorite features on the computer is making a screen saver of all her family photos (they had several thousand photos and slides digitized recently) and it appears Gnome Shell has abolished the screen saver…. Really? Also, one of the other winning features of Gnome 2.0 for my Mom was I could place absurdly large icons of her few apps (Web Browser, Office, Picture folder) on her desktop. Not any longer.

All this new “usability” seems to make things more of a nuisance for me and simply remove key features my mom relied on. Critical regressions. I’m pretty sad.

Valid XHTML 1.0!
Valid CSS! is proudly powered by WordPress
Entries (RSS) and Comments (RSS).
19 queries. 0.382 seconds.