Archive for December, 2008

TGA import library

Monday, December 29th, 2008

Well sooner than I expected I got around to cleaning up the code I mentioned in my last post and publishing it under a BSD license. It’s all there in that article, enjoy!

More image fun – Targa import

Monday, December 29th, 2008

Another project I’m working on is adding some COLLADA import functionality to the library, which is going quite nicely. The end goal is that I can knock up some assets in blender and use them for some sample material. So far I’ve got triangle mesh import working, untextured materials and point lighting working. The next step was textured materials.

The first sample I came across however uses TGA’s as the texture. This is a pain as my library only supported PNG and JPEG. So being my usual lazy self off I went to search for a TGA import library that I could wrap around. Sadly I found things very lacking – but I did find the 2.0 specification document. Feeling brave I decided that actually I could roll my own importer pretty quickly. Turns out it was slightly more tricky than I anticipated but not much!

I will write an article about the choices I made and include a simple implementation of this shortly. My implementation covers the whole 2.0 specification, as best as I can tell, indexed (palletized), true colour and black and white images supporting run-length encoding. However I’ve found it difficult to get hold of a library of sample images so in the end have made my own. I’ll make those available too shortly, ideally (given time) I think I’ll clean the whole thing up a little and publish the library as a whole.

The only thing it doesn’t yet cover is I read something about Huffman compression but I guess that’s a later extension.

Image and thread fun

Monday, December 29th, 2008

So once I got all my cameras and matrices working as they should my target was to render a spinning earth textured with some images from Open Street Map. This worked great but what I really wanted was satellite imagery to make it look really cool. I find Google’s terms and conditions confusing and in a number of places I read that pulling down individual tiles is prohibited. Luckily I found the Open Aerial Map project that does seem to allow me to do whatever I like with the images.

My application is multi threaded. I have the main drawing thread, a thread than handles multiple downloads (wrapping the curl library) and then a couple of threads that take the images, decompress them and upload them to the graphics card memory. As I’m using OpenGL accessing the context from multiple threads was interesting and turned out to be different on my different target platforms (XP/Linux/OSX). Still I got all that working although I want to natively port my windows thread library rather than using a pthreads wrapper and I also want to use multiple opengl contexts on platforms that support it rather than the windows way of sharing the same context).

Anyway all this worked great with the PNG images from Open Street Map. What became a major headache however was when I started to pull down JPEG images. My image library wraps The Independant JPEG Group’s library which it turns out is not thread safe. I’ve had to run all JPEG decompression serially which I’m not so pleased with. As the IJG’s library was last updated in 1998 I’m thinking I either need to find an alternative library, write my own or perhaps make the IJG’s work thread safe. I’m thinking to make it thread safe the statics need protection – either by making them thread local storage, or preferably by stashing them all into a context that I pass around.

Here’s a quick screen shot of my globe:

A screenshot of my textured spinning earth application

Some of the blurriness is down to the way I compressed the PNG. You will see the nasty texture seams (ouch). Still I know what’s causing them and also how to fix it, but that’s a job for a little later, along with a whole load of optimization and a free camera to allow me to pan in, zoom around and such. Also I want to add a star field in the background, light the globe, ideally using the lighting to fade between a day and night image would be very cool but when zoomed in I’m not sure how we’d get the resolution, add an atmosphere and different material properties (water, ice, forest, sand etc). I’m sure I won’t get it all done but there’s plenty of things to play around with!

OSX Port and matrices

Monday, December 15th, 2008

Now I’ve got a working source control solution up and running it’s made it much easier to port my code base around to different operating systems as I can pull it down and play with it without having to copy the entire thing around.

So after having imported my sources on windows, I got everything running under 64 bit ubuntu (no problems there really, just hacked my makefiles to detect the os/host type rather than editing it by hand everytime). After that though the challenge I’d set myself was to port onto OSX. Now I’m not to familiar with OSX (yet) so this was probably more of a challenge than it should be.

I struggled with simple keyboard shortcuts not working as expected and the idea of the application menu bar always being at the top of the screen (wasn’t the Amiga OS like that though, I’m too old perhaps to remember). I also found it odd that I could close all the open windows of an application but it would remain be open.

My first problem was finding a nice text editing program for hacking around on text files. Under windows I use and would recommend notepad++ for this purpose. However it took me a while to find a suitable replacement for OSX. In the end I plumped for jEdit which Java based and so in theory I can actually use across all my environments if I want. Whilst jEdit worked fine I also wanted to be able to launch it from within the bash terminal shell, for example by typing jEdit ~/.bashrc and it launching the editor pointed at the correct place. This turned out not to be as easy as I’d have liked because of the way apps work. I’ve written an article about launching OSX apps from the command line if anyone is interested.

After getting all this working I played around with XCode and managed to import my code base and after a little struggling got it all to compile. As my library wraps SDL for it’s OpenGL, window management and input code it wasn’t even too hard to get my PlaneGame” up and running on OSX too. Next step is an iPhone port of the library!

In the meantime though I also have another little project I’m working on. This one requires full 3D rather than the 2D (built on top of 3D) approach that PlaneGame is currently using. In what should be a simple process of setting up a camera I ran into some matrix maths problems that I just couldn’t seem to figure out. I finally cracked it – I’m used to DirectX’s row major matrices whereas OpenGL uses column major matrices. However because GL’s vectors are column vectors and DirectX’s are row major the linear representation in memory is the same. Once I start multiplying those vectors together though all bets are off though as they result in transformations being applied in different orders. Now my matrix library is far more robust – I can request matrices and vectors to be row/column major and still have everything work as expected.

Setting up source control on Host Monster

Tuesday, December 2nd, 2008

I’m collaborating on a small project with a friend that means we’d like to share some source code around. As I have dynamic IP and don’t have a server at home always on the Internet I thought my web space on Host Monster (incidentally where this is hosted) seemed to be an ideal place to host this. My initial thought was to set up a CVS repository. CVS appears to be installed on my Host Monster account already – brilliant. However it seems that for anyone to access it they would have to have root ssh login to my account. Not that I don’t trust my friend but I don’t really want to start giving away root access to my web space.

So I thought about looking for other solutions – one that came to mind is svn so I looked into that and found this informative post on how to do what I wanted but with subversion, albeit on a different web host. I also found a helpful thread about how to install Subversion on Host Monster. Now I’m a newcomer to subversion although I know as a user it works in almost the same way as CVS.
Sadly it seems that there is no way to do this with CVS that I could find.  It may have been possible by tunnelling a pserver connection through ssh – however it seems the cvs install doesn’t allow even local pserver connections.  Finally I put all this together and thought I would share it with the world by writing a new article Adding a safe multi user subversion repository.