/ C++, EXAMPLES

Native client SDL example

I have been looking into chrome's native client (NaCl).

My goal is to be able to use it as an adaptation layer to run code on the browser, while keeping it as portable as possible.

I want to do some game development with it, so the fact that SDL was ported to it  (naclports) seemed extremely promising. SDL supports OpenGL and Audio context creation and input management.

Looks like that's just what I was looking for.

After going through the getting started tutorial and reading some of the examples, it was time to get SDL working.

I did have to make sure the nacl tools were working in my fresh 64 bit VM, since they are 32 bits binaries. I'm running ubuntu, so all I needed to do was install 32 bit libraries by running:

sudo apt-get install ia32-libs


Next I had to check-out and install naclports and compile the SDL port. This was relatively easy to do.

Now came the tricky part.

The naclports are a collection of patches to specific versions of the original projects. For SDL the port is for version 1.2.14.

I followed the documentation on the nacl site on how to port SDL games. I found this page to be a bit lacking in details, but I managed to fill in the blanks and get an example to compile.

The problem was ... the code wrote based on that page was compiling, but didn't actually produce anything visible on the browser apart from a blank NaCl element. No GL context, not nice graphics ;)

No problem I though, I'll just look at the patched SDL source and read the documentation for the new/adapter methods there. No luck here, there was no documentation specific to the port.

Ok, I though, there has to be something, somewhere. Just google it!. I found an example on github from a google developer that I saw in the svn log of the SDL port to naclports. Bingo! Thank you Evgeniy Stepanov (eugenis) for porting SDL, doing an example and uploading it to github!

The example was not compiling, it seemed to be for an old version of the nacl SDK.

Humm, according to the source code this is under a BSD license, and it is on github... here's my first chance to contribute something back to the NaCl comunity.

I forked the example in github and updated it to run on pepper_19 (the latest stable pepper release at the moment).

I changed the Makefile to compile both 64 and 32 bit nexes, based on the Makefiles in the nacl sdk examples. I didn't like how it turned out (the Makefile), but I'm still looking for a new build system to adopt. Make looks more than OK for a simple example.

You can find the fork here. And it works!

Just check out and run:

make
./httpd.py
google-chrome --enable-nacl http://localhost:5103/sdltest.html


(I'm assuming you are running linux)

You should see something like this:

nacl sdl example

 

Enjoy ;)

 

rui

Rui Pires

Working as a professional full time remote developer from the Azores since 2011.

Read More