"Codecolors" sources released

Codecolors

As they always say, good things always come in threes (or in Spanish: ¡No hay dos sin tres!). So here's the third batch of demo sources! This time it's the turn for PPG05: Codecolors. The only demo that will fully test your monitor's ability to display the full gamut of colors, by showing them all at the same time!

Best of all, it's even captured to HD video so that you can watch it in glorious High Definition. It can't get any better. Or maybe you can — if you do anything with the code, as always, let me know!

I have also changed a bit the way the builds are done and tidied the root folder up. Now both the Mac and Linux versions of BASS dynamic library are in the src/bass folder, and get copied to the right destination only if needed. There's also support for building the Mac bundles right from the command line, thanks to an awesome bundle.sh script which the guys from glfw did and that I modified in order to include an icon too. So you don't need to mess with XCode and its awkward project settings for compiling, and everything can be done from the Makefile. Hooray!

I still have to update the Makefile for PPG01 so that it generates Mac builds and also follows the same location for BASS that these latest builds use, but I'll probably do it tomorrow. My eyelids won't allow me to do it now, I'm afraid!

Keeping .DS_Store files at bay

.DS_Store files are to Mac what Thumbs.db are to Windows: annoying, meaningless and worst of all, ubiquitous. Whenever you browse to a folder which contains certain magic files or you do something like moving an icon to a certain position, they system will create those files in the folder. Then you happily type in git status, or svn status, when lo and behold! those defiant .DS_Store files are there, waiting to be added to your repository.

So you type this in, frantically:

find . -name ".DS_Store" -delete

and then before it happens again, you edit your .gitignore file (which as the user's manual helpfully points out, should be in the top level of your working directory) and make sure it contains the following lines:

# Ignore useless stuff
.DS_Store

Or if you're using subversion, you can set the svn:ignore property:

svn propset svn:ignore .DS_Store .

You may want to make sure there isn't a previous value for svn:ignore with

svn propget svn:ignore .

and if that's the case, probably "merge" them so that you don't lose those values.

While we are on it we could also add Thumbs.db to the list, but since I haven't used a Windows system for developing in a long time, I don't need to do that (lucky me!)

"Killotrona" sources released

Killotrona

Yesterday, I wanted to spend some time in the park but our glorious variable weather decided it would pour a few water drops instead. So I went back home and began working on porting this demo to Linux. To be honest, this one has been faster because it was almost finished, since I had spent some time working on a mac port a couple of years ago, but neved finished it due to some problems with fmod, I think (although I don't know exactly which type of problems, I can't quite recall at this time).

I have taken the opportunity to fix a couple of things that annoyed me, like the laser which didn't finish properly, and increased a little bit the resolution of the plasma. Not too much, so as not to lose the original demo feeling. This is a port, not a remix!

Here's the "making of" and the github commit.

Enjoy!

"Scene Of The Girls" sources released

Scene of the girls

We released this demo approximately 6 years ago. Then I was using windows and I didn't worry about other platforms actually. Nowadays I'm using linux and get horrified with the mere thought of having to use windows again, but my demos didn't work too well with wine. Since I still hadn't lost the code, what about doing a portable version which works in my computer? So that's what I have done with Scene Of The Girls.

Things that I have learnt

I expect most of you to feel skeptical about the idea of taking sources 6 years old and trying to make them work in a completely different system. But it has been an interesting experience and I have learnt a lot meanwhile.

BASS is way better than fmod

This is kind of ironic. At the beginning, I used BASS. Then when I began coding for Mac I had to use fmod, because it was the only available multiplatform library. I wasn't too happy with the sound quality (specially for modules) but that was all that we had. I then found out that BASS was available for MacOS, so I switched back to BASS. But then I wanted to code for linux and BASS wasn't available, so I switched again to fmod. I tried with fmod3.75 and then I noticed that I couldn't capture the demo with it, so I moved to the newer fmodex, which did allow me to capture the demo, with audio.

And there was a big "but": the latency. There was a considerable amount of time between the "BOOM" in the music and the images reacting. Funnily it wasn't that the images were happening with delay; it was that the music happened to sound too late for what was being shown in the screen. You saw torus shaking, and a quarter of a second later, there was a bassdrum kick. Something was decidedly wrong. I copied the code to a usb pen stick, and compiled everything on my powerbook with MacOSX, just to dismiss any possible ALSA+Pulseaudio+whatever latency issue. After all, supposedly MacOSX sound drivers have a very good latency. But the problem was still there. I tried on mrdoob's laptop (a Macbook running Linux) and the latency was still there. Luckily before I began to code my own sound/module playing library I thought of having a look at the BASS site again, just in case they happened to have released a linux version and oh joy! there it was!

I then proceeded to change once again my Music.h/cpp wrapper. I congratulate myself each time I have to change the wrapper, because thanks to having the wrapper I don't have to change every other call in the code. Then I ran the demo again, in linux, and the latency had gone away! YEAH! Even more, the song sounds WAY BETTER, because BASS interprets properly the resonant filters the song uses. That was a supercool moment!

So unfortunately for the fmod guys, sorry, but there's something wrong in your library. Although to be honest, the fmod API is nicer and doesn't make you think of bytes when what you want to know is how many seconds have elapsed, but is the price you have to pay for no delays.

GLC: a .kkapture alternative for linux

Normally one would capture a demo with .kkapture… if he happened to be using windows. Us linux-ers are left out without any alternative… or not! Because I found glc. It can capture opengl windows along with its associated audio and it works very well actually. I used it for capturing the demo and publishing it in youtube, after encoding it to mp4 with this script.

getopt_long is confusing, but very rewarding

To date I had only used a very basic style of argument parsing. I decided I would have something better, and I used getopt_long for it. This allowed me to add a lot of configuration options which before had been hardcoded in the demo and forced me to recompile each time I wanted to test a different parameter. You can see how I used it in the parse_arguments function in main.cpp.

PyGTK is very cool

This also set the path clear for the next thing I wanted: a nice launcher for people who do not want to type in a series of config options to launch the demo. I made the launcher with pygtk, and verified it works on any vanilla ubuntu (as I suspected, pygtk comes by default with the system because several basic applications depend on it).

So I just open that GTK window with some checkboxes and pulldown lists and let the user choose what he wants, and it builds up the config settings for the executable, and calls it. And when developing, one just had to press the up arrow to get the last typed in command and relaunch the demo using those very same parameters, instead of having to select them manually in the launcher dialogue. Simple linux style, I like it!

VBlank is off by default, whatever they say

I had lots of tearing in my app, even in window mode. I checked the SDL docs and they mentioned an GL attribute (SDL_GL_SWAP_CONTROL) that could be activated but was deprecated, and activated by default. I tried it anyway, explicitly setting it to true and surprise! the tearing and flickering went away!

And now…

I guess I'll continue releasing the remaining sources, once I get them to work here and wipe up extremely confusing stuff. The main goal is to let someone else learn from the code just as I did when looking at the code of other demos and specially sites like NeHe. There aren't superclever tricks in this demo, it is all fairly basic and if you want to code an opengl demo, it should be a good basis, at least for experimenting and changing things here and there. So come on, play with the code, experiment with it and make something better. And let me know afterwards!

Terminator 4, from the point of view of a programmer

WARNING!

Needless to say, this post contains tons of SPOILERS, so if you plan on watching the film, stop reading now!

———- Spoilers below ———-

We had been strolling up and down the streets of Bristol for several hours and our legs were tired. Nice city, although very hilly! That didn't show up in Google StreetView. And so we thought, let's find a cinema! We finally ended up in the new Showcase deluxe multiplex cinemas (much nicer than the shabby Odeon) and chose Terminator 4. There wasn't much more to choose from; after having watched Transformers, I would require to be paid to watch Transformers 2.

After the movie ended, we felt a bit analytical and began enumerating the little flaws in the script. It's not bad for an action movie, I argued, … but after having read a good amount of sci-fi books and, specially, since I'm a programmer and have seen how things truly work, the script is overly optimistic.

Optimistic?, you'll ask. How come, if it predicts a dark, near future where humanity is in a continuous war against the machines. Well, I say so because there's no way humanity can build such intelligent and advanced systems. Just look around you: air planes which fail and explode in the middle of the ocean, or maybe even just minutes after taking off, trains which collide with each other because the system didn't take them into account, and etcetera. On a minor scale, look at the operating system you use daily. For sure it has flaws — human flaws.

The only way humanity could build something like the machines in the movie would be as a result of an accident. That is, without acting on purpose or knowing beforehand what they were doing and what did they want to achieve. By pure chance.

Even though, the probability of that happening is so remote that I believe we would have auto-exterminated ourselves centuries before. There's no biggest enemy for humanity than humanity itself. Simple proof: how many lives have been lost in wars, versus how many lives have been lost in natural disasters? And when I say natural disasters, I take it with a good pinch of salt. Some of the recent disasters, such as rain flooding in the south of England, seem to be a direct consequence of building just too much over places that shouldn't be urbanised, preventing the rain from being naturally absorbed by the soil, and therefore it's just an easy recipe for catastrophes.

So that being clarified, here are some other things that didn't seem very appropriate in the movie:

  • USB connectors. So the machines and the humanity are in a war, but they still agree on using USB connectors. Does that mean that fireware is deprecated, then?
  • Displays. Why do machines need a display on their equipment? Won't it be easier for them to send a wireless signal? The Override display on the motorbike that John Connor picks up is useful only for humans.
  • The radio is already tuned on the proper frequency. Or is it that they emit the same signal in every frequency, just in case?
  • Sony VAIO. The resistance not only uses an amazing array of technology; it's even VAIO branded. Where is the factory for building them?
  • The machines get totally switched off when exposed to a certain frequency. WHAT???? Edit: As luchyx points out, there is something like this already, but it is highly classified: the electromagnetic bomb
  • How come that when Marcus connects to the main computer, he actually seems to know what he's doing, and yet the evil Skynet doesn't use that opportunity to completely erase any human behaviour from his brain just in case it decides to help its human friends?
  • Furthermore: why do they leave him with a human heart when they reconstruct him (or whatever they call the process), when it's one of the weakest points of failure in humans? Answer: so that we can have a happy ending and John Connor doesn't die?

I think there were more things like these, but I can't quite remember now. It's that kind of flaws you need to ignore and forget if you want to enjoy the movie; as soon as you try to take it seriously, the script falls apart.