Fork me on GitHub

SFML Game Development

Recently I was sent a review copy of SFML Game Development by Packt Publishing. SFML stands for the “Simple and Fast Multimedia Library”, and is one of two major libraries used in 3D OpenGL graphics programming. The competitor to SFML is SDL, which is a C library. Comparatively, SFML is written in C++. I’ll cover an overview of the book’s contents and a quick review.

SFML is quite complex, and so is C++. This book assumes a fairly competent programmer who is already familiar with most of the language constructs of C++. It’s recommended the reader understand variables, data types, functions, classes, polymorphism, pointers and templates. If you don’t, I wouldn’t recommend trying to learn C++ in parallel with SFML. It would be quite a challenge. If you don’t know C++ very well, I’d recommend Absolute C++. On to the book!

SFML Game Development starts off with a strong first chapter, covering a basic graphical “Hello world”. It covers user input using the more modern events API, as opposed to the old polling API. It also covers in depth frame independent movement and fixed time steps.

After explaining some of the basics of getting an SFML project up and running, it jumps right into building a modern clone of 1942. It covers building an asset pipeline, rendering scenes, getting player input, playing music, multiplayer code, gameplay logic, and transitioning between states such as the main menu, gameplay, and boss screens. It even finds some time to cover a basic bloom shader in GLSL.

At 280 pages long, this book is short but sweet. It walks you through a complete project from start to finish, and gets you up and running with SFML. You’ll be writing your own real time graphics in no time. When I was learning SFML 1.5, there weren’t resources like this available. It was a much slower, more painful process than it is now. If you’re interested in high performance real time graphics programming, this would be a great book to start out with. Once you’ve finished this book, you’ll have a good foundation for learning OpenGL itself if you’re so inclined.

For an easier start, I created a Github project with an empty SFML project already set up. It’s called sfml-template, and it uses CMake for its build system. It isn’t currently set up to build on Windows, but it will build on either Linux or Mac OS X. The linking of OpenGL on these two platforms is quite different, which is why CMake is required for handling building on either.

Alright, that’s it. Go build something awesome!

Automating Rtorrent - A Seedbox Guide

A seedbox is a nice step up from a normal torrent client if you’ve decided you want to get more serious about contributing back to your swarms. I personally run an rtorrent instance on my home Debian server which I’ve automated to a fair degree, which lets me seed files 24/7. I use this mostly for linux distributions, such as the ArchLinux ISO, so that I can help contribute to the health of these open source projects.

I see a lot of people set up home services like this in a rather haphazard fashion, running a daemonized process as their administrative user and giving it free reign over their home directory. Isolating processes to their own user is a good security practice, it can help you keep a tidier box and lower your cognitive strain when working with a specific service. Personally, I also find it easier to keep track of everything in one location.

I’m assuming you’re running some variant of Debian on your server. The general setup principles are the same no matter the flavor of linux, so adjust as necessary based on your favorite package manager. To start out, we’ll install some software and add a new user:

sudo aptitude install rtorrent screen
sudo useradd -m rtorrent

This creates a new user named rtorrent, with a default home directory. Note that I didn’t pass the -p flag, leaving this account without a password. This was intentional, because this account shouldn’t ever be logged in to like a normal user. Having no password ensures that the rtorrent user can’t be logged in directly from a TTY. We’ll be setting things up initially with su, but we can add an ssh key for easy maintenance and monitoring.

Switch to the new user with:

sudo su rtorrent

This is a bit of a workaround but it’ll do for the initial configuration. Change to this user’s home directory with cd, open the file .rtorrent.rc in your favorite editor, and add the following:

download_rate = 0
upload_rate = 0

directory = /home/rtorrent/downloads
session = /home/rtorrent/.rtorrent/session

port_range = 49152-65535
port_random = yes

schedule =
schedule = untied_directory,5,5,stop_untied=
schedule = tied_directory,5,5,start_tied=

system.method.set_key =,link_complete,"execute=cp,-r,$d.get_base_path=,/home/rtorrent/finished"

The first 6 configuration options are rather self explanatory. The schedule lines respectively set up where rtorrent should watch for files, that it should start those torrents when they are created, and stop them when they are deleted. Your session folder is where rtorrent stores its internal database that allows it to keep track of torrents persistently. The very last line sets up rtorrent to copy the finished files to a different directory. This specific option lets me know when torrents have finished and lets me copy them to archival media before clearing the temporary folder.

So, now we need to create the necessary folders in the home directory. We can do that with:

mkdir -p downloads torrents finished .rtorrent/session

We also need to tweak a few settings so that rtorrent will work from the normal user account you logged in with. Set the finished and torrents folders group sticky with:

chmod g+s finished torrents

Set open group permissions with:

chmod g+rwx finished torrents

This sets both folders as group writable, and the sticky permission ensures that files created within this folder inherit the same group.

Having rtorrent start as the proper user on boot would be really nice, so we’ll create a new file called Add the following:

screen -d -m rtorrent

Add executable permissions:

chmod +x

This script starts screen, executes the command rtorrent and immediately detaches from the session. We still need to add this script to our crontab. To ensure our newly created script is called on system boot, edit rtorrent’s crontab with crontab -e and add:

@reboot /home/rtorrent/

Next, edit the .bashrc file and add umask 0002. This overrides the rtorrent user’s default umask of 0022, which means new files created by the rtorrent user will have the permissions 775, or rwxrwxr-x. We’re all done, take the opportunity (optionally) add your public key to ~/.ssh/authorized_keys and exit the session. Then, just make sure your normal user is in the rtorrent group with:

sudo usermod -Ga rtorrent username

Now, just create symlinks pointing to ~rtorrent/torrents and ~rtorrent/finished wherever you’d like in your home directory. Drop your torrents in the torrents folder, and wait for the finished download to appear in finished. You can safely delete these downloads and they’ll still be seeding, living in ~rtorrent/downloads. Personally, I access this server over NFS on my home LAN, but you could easily scp torrents or use any other mechanism you’d prefer to get them on the machine.

A Primer on Surveillance Systems

A few months ago I had the misfortune of experiencing an invasive burglary. I was very lucky that I only lost a 2008 era iPod and $100. It was immediately pretty clear that they were specifically targeting very light items, as they passed over a Macbook Pro and a collection of camera lenses. In actuality, the most distressing part of the experience was coming home to the contents of my cigar humidor upended in the middle of the floor.

Unfortunately, this hasn’t been the first time this house has been burgled, but it has been the first time it’s happened since I moved in. From what I’ve heard from my roommates, after every incident the external security of the house has been improved, but they keep managing to find the next weak spots. They’re annoyingly persistent. Mulling over this problem, I started to think about access elevation, and treating my home security in the same way I would digital security - in layers.

I started by prioritizing the rooms of my house based on their security requirements. My bedroom contains my workstation and home electronics lab, and my two roommates keep their valuables in their room as well. These rooms need to be the most secure. The rest of the house is furnished, but doesn’t hold many expensive items. Thus, the central hallway connecting our rooms makes for a great buffer between the ‘high’ and ‘low’ security sections of the house. If burglars are going to get in, I’d at least like to see who it is, so I decided to put up some security cameras. Before I talk about the specifics of my security system, lets talk a little bit about how CCTV works in general.

The term CCTV is actually a bit confusing. It traditionally stands for Closed Circuit Television, and that’s how a large number of security setups operate. It’s the classic CCTV configuration. A video signal is sent along a coaxial BNC terminated cable to a central system which interprets the video signals, digitizes and stores it. There are a couple different configurations available to consumers, from all in one DVR devices to add-on cards for standard PCs. You’re limited by the number of inputs on this input unit, with a common number being four or eight. A four camera setup with a DVR set top box will set you back a little over $500. This is a centralized security system.

These systems can be quite involved physically to get up and running, as you need to run both power and coaxial lines to every camera you want to install. They can also be more expensive and have a single point of failure. However, these systems are still relatively popular and you can purchase one from any number of retailers.

With the proliferation of wireless devices around the home, a new type of security camera has emerged - the wireless IP camera. If you have a spare computer to use as a DVR, these devices are much cheaper in terms of initial investment and offer some cool perks.

ISC West 2010 9

An IP Camera based system is considered a decentralized security system. These units are smart little devices, and $80 should get you a Wifi enabled model with up to 300 degrees of panning range. They do their own digitizing, and many of them export their footage to a moving JPEG (MJPEG) served over HTTP. After configuring your IP camera to connect to your wireless network, you only need to run power to them.

You can log in directly to the camera at its local network address to change its internal settings or pan and tilt it around. This distributes responsibility off of the central server, leaving it to focus on just motion detection and storage. Given the networked nature of the cameras, you can run as many as your server can handle processing. Also, in the case of a server outage, you can still view individual camera feeds, something that isn’t possible with a coaxial system.

The downside to an IP camera system is that there’s a lot more networking involved. That isn’t to say coaxial systems are simpler, because they bring their own complexities, but IP cameras may not be the best choice if you just want to purchase a full solution you can physically mount, plug in and flip on.

As for my specific setup, I put a good amount of thought into what would be easiest to incorporate into my existing home network. I already run a Debian server at home, which puts Linux support high on my list of requirements - I need this same computer to monitor and record from my new cameras. I found ZoneMinder, which is a great open source project for running a CCTV system and was pretty easy to install. I looked through their hardware compatibility list and found Foscam makes an affordable wireless pan/tilt security camera, the Foscam FI8918W. I purchased two of them from Amazon and got to work mounting them on the ceiling. Strategically placed, the combined coverage of both their infrared LEDs completely light up the hallway on the feeds.


After connecting the cameras to my wireless I issued two static DHCP leases using their MAC addresses. I use DD-WRT on my router at home, which made it pretty easy. Zoneminder needs an install of PHP and MySQL because it’s a full fledged web application, but they have pretty good instructions over at the wiki.

Configuring Zoneminder takes a few more steps. First is adding the cameras by the static IPs I leased in the router, and setting up the storage path. After that, there are a couple ways Zoneminder can record. If you need 24/7 recording, you can select “record” for each device. I wanted to record when movement is detected, which is the “modect” option. There are a lot of ways Zoneminder can work, and if you’re curious you should read the tutorial. This configuration has given me a very hands off system. It automatically logs events based on movement, and I can log in and review them on a timeline.

Of course, a CCTV setup definitely isn’t a silver bullet, and this is only one piece of the puzzle when talking about a more secure home. However, a system like this is a good way to start down the path of home surveillance and possibly home automation. It’s definitely given me some peace of mind. I’ve purposefully written this post as an overview, because there’s really great documentation over at the Zoneminder site if you want to get something similar up and running.