June 2, 2011

Playing with WebGL

OpenGL is one of those things I like to play with from time to time. So naturally I wanted to check out WebGL now that Chrome and Firefox support it.

It's fun being able to use javascript and web technology in conjunction with OpenGL. Building GUIs using raw SDL/OpenGL was always rather a pain for me. I don't even like how standard toolkits work (GTK+, Qt etc). So being able to use HTML widgets and jQuery on top of my 3D scene is really awesome.


Unfortunately it's noticeably slower than an equivalent program running natively. When profiling, the GL calls seemed to be the bottleneck. A bit less so on Windows than Linux, although that may have been due to better driver support on the former.

So like usual, optimizing comes down to reducing the number of GL calls you make per frame.

The javascript logic and matrix transformations ran very fast. This was the case for both Firefox and Chrome and was a very pleasant surprise.

You can try out what I made at http://arcticpaint.com/planes/, play with the source or what ever. It's all under public domain (with the exception of the glmatrix library which has a BSD license).

I had also started toying with the idea of a turn-based game http://arcticpaint.com/islands/ (very, very far from completion)

If you want to check out more webgl stuff http://learningwebgl.com is a great resource. They also have some decent tutorials that are easy to follow along if you're new to OpenGL.