Saturday, January 15, 2011

Sony Handycam easy on Ubuntu Linux

When I was lucky enough to have my Father-in-law buy me a Sony Handycam, the guy at the shop told us

"Ah, you'll need a Japanese version of Windows on your computer if you want to turn your videos into DVDs"

Having previously owned a Sony mp3 walkman, I'm well aware of Sony's tendency to release propriety software with their gadgets, but being an Ubuntu fan, I also found a nice little java program that bypasses that necessity (called symphonic), and so I figured that the Japanese Handycam's requirement for a Japanese OS could also be bypassed fairly easily.

... In any case, there is always my wife's Japanese VAIO...

As expected, it was fairly straightforward. Indeed, I didn't even need any dedicated software to get everything working. I just used VLC to view the videos (although they run mighty choppy on my poor ickle netbook) and Kino video editor.

In fact, I get the feeling that it would have been more difficult to get the camera going in Windows.

Thursday, January 6, 2011

Making the world in 7 days?: An experience with JOGL

Last year I started learning Java, and had a lot of fun using its 2D graphics to procedurally generate a cartoon seal. Eventually I came across JOGL, a wrapper for OpenGL in Java. Its been a while since I did any serious 3D graphics programming, so I thought I'd see how easy it would be to program a 3D game in Java, and how well java would cope.

I started out making a grid comprised of regions, each subdivided into areas, further subdivided into terrain squares. I then made (a very inefficient) world generation class to iterate through all these terrain squares and assign them a different height (basically, I shove a load of sine waves onto the landscape with varying amplitudes, it looks very silly until the sine waves start overlapping, then the interactions between the sine waves start to produce something approaching believable.

Next came lighting, and I remembered (horror of horrors) that you need to specify normals at each vertex of the terrain, which is done by averaging the surface normals of all the quads surrounding a terrain vertex. Nonetheless, by the end of day one, I had a lit, hilly landscape. Albeit a blue one.

Most of day 2 was spent trying to find a simple way of adding terrain textures, it turns out that there is a very simple way, and I'm glad I took the time out to find it:

Texture tex ;
tex = TextureIO.newTexture(new File("Ground.png"), true);

Of course, I'm going to have to move this out of the init() function when I want to use more than one texture... But in any case it works. Finally, I added culling so any regions outside of the viewport aren't drawn, cutting down on rendering times. By the end of the second day, then, it was looking like this:

Remember I'm using a subdivided system of regions, areas and the rendered terrain squares. To further optimise, I added an algorithm to give the corner of each area its own vertex, and I moved the height of these vertices to match the height of the nearest terrain vertex. In effect I had created a low detail version of the rendered terrain. Then all that was required was to render the more detailed terrain closer to the camera, and render the less detailed areas further from the camera, reducing the number of triangles rendered overall. This effectively allowed me to greatly expand the size of the terrain, and still have it render at reasonable speed. Finally I added fog, which didn't take me too long at all, to get something looking a little more atmospheric:

Well... When I say atmospheric, perhaps depressing is a better word... To inject some new life into the world, I spent the 4th day adding the skybox (actually I spent most of the day adding model support). This is basically a textured sphere that I flattened into a pancake (not the most efficient method, but very quick), this way the fog doesn't obscure the sky above, but fades seamlessly into the sky. I also added a blue tint to the fog so it looks more like haze on a cloudless day than miserable English fog..

You might notice the sky has pixelation on a geographic scale, this is due to the fact I still haven't actually added support for multiple textures.. Yes, that's right, its the ground texture coloured blue!

So... 4 days into the creation, and just about everything is in place. Now I've hacked out the majority of the model loading code, vibrant tree'd (even inhabited) landscapes can't be far away...

To conclude... I've basically done this before in DirectX many years ago, but I'm quite impressed with how JOGL handles everything. Its a little more difficult for me to get my head around managing resources like models and images (something that DirectX manages quite well on its own), but performance wise its working like a charm, and creating it on my netbook has been very pleasing. Its the added portability of Java is the icing on the cake for me though, and I had my fledgling program running on linux with no troubles at all.