This video from Benedek93 is a little slow to get going, but it’s well worth watching all the way through for a really tight demonstration of what you can achieve with OpenGL ES on the Pi.
Recently I’ve started going through a tutorial for modern OpenGL programming again (I can recommend it:http://arcsynthesis.org/gltut/ ), and on the way I decided to re-do that function plotter program I have showed off in one of my videos (“OpenGL Shaders and Shadow Maps”).
First I wrote it using the old, fixed-pipeline OpenGL specification so that I could run it on my laptop which didn’t support the newer versions. You can download it here and play with it on a PC: https://bitbucket.org/benedek/simple-…
At the same time I was also messing around with OpenGL on the Raspberry Pi and I was impressed seeing how smoothly you could make it draw simple but pretty 3D graphics. So I started porting that program to the RPi, adding the boilerplate code necessary to set up a GL context on it and changing the graphics code to use modern OpenGL ES.
In the end, the results were just as pretty as in my old shadow-mapping plotter program (except for the shadows), and the RPi was able to draw models smoothly at the same triangle counts as my laptop.
Liz: if you haven’t entered our contest to win a pre-production camera board, have a look at the post explaining what you’ll need to do. And if you’re looking for inspiration, here’s a guest post from Gordon, our Head of Software, about a mini-HD camera project he worked on at home using the prototype boards we showed the BBC back in 2011.
I may have mentioned that Gordon does a lot of cycling. He bodged up a 3D helmet cam a couple of years ago: here’s how he did it. (He has also made me include some 2D video because he likes showing off.)
Careful with the last video, which is in 3D – if you’re using bi-coloured 3D glasses to view it, as I did, you are liable to feel VERY motion sick if you’re susceptible to that sort of thing. Over to Gordon!
A few years ago I really wanted to play around with a helmet-mounted camera for my mountain biking. There were quite a few out in the market, but they were quite expensive, and it’s always difficult getting toys past my wife! Because I was working at Broadcom, I was able to get my hands on what we called the MicroDB (the thing David and Eben first showed to the BBC as the Raspberry Pi), and since I had all the software and a bit of competence, I decided to try doing a bit of HD helmet recording.
The hardware I used was based on the same BCM2835 chip that we all know and love. The hardware also had a PMU chip (power supply), which meant you could power it directly from a lithium ion battery and record 720p HD video for about an hour.
So I rigged up some properly engineered mounting. I used a rubber from my daughter’s pencil case (Americans, breathe easy – this is the UK word for what you call an eraser), a couple of cable ties, and a USB socket! I set out on a voyage of discovery…apologies in advance for the lycra clad arses, but It’s something you’ll just have to put up with!
Liz interjects: that’s not the half of it. Eben and Gordon have a regular date on Wednesdays where they take an hour and a half over lunch to go cycling and have a software meeting at the same time. This means a certain amount of strutting sweatily around the office dressed in lycra at the end of the ride. This week, Jack turned up, tutted and said: “You two do realise there are showers downstairs, don’t you.” The rest of us cheered.
This is an example of the helmet cam being used in a chain gang, which is a fast-moving (we’re doing around 26mph average for the whole of the clip) club ride, where you continuously rotate who’s cycling at the front, making it a very efficient way of travelling at speed!
This is another clip from the helmet cam, at the start of a mountain bike race held by a good friend of mine who’s an elite rider.
When I took these videos, I expected to experience the same feeling of speed as when you’re riding for real, but it doesn’t quite make it. The main issue is that the feeling of speed you get is a product of the full 3D stereoscopic experience that the 2D camera throws away. It’s there and it’s fun, but it doesn’t actually feel real; you don’t quite get the full-force feeling of what it’s like to tear down that trail!
I was missing a dimension, so I had to go find it again! OK, now you ask, surely it’s going to cost me a lot of money to buy a proper 3D camera, and you’d be right if you didn’t have a whole bunch of little camera boards kicking around in the office. I realised that all I needed was two of them, and a spot of work to synchronise the pictures: then Bob’s your uncle!
I took two MicroDB’s and connected them together (actually I used a USB -> USB connector which I then cable-tied to my bike helmet with a rubber/eraser to give it something soft to sink into). So what you get out is two videos (each 720p30). To get the images working together, you need to do some processing, which presents a number of problems:
1) The two cameras are not aligned and therefore you have to rotate and translate the images.
2) You also need to invert one of the images.
3) You need to hand-synchronise the two videos (and keep them synchronised during the video).
So I wrote a bit of software based on FFMPEG and SDL, and lots of handcrafted fun code to take the two videos and output them as one in a number of formats, including interleaved line (odd lines are left image, even lines right), horizontal half-resolution and vertical half-resolution (because we had a number of different 3D televisions to play with!) Application of Bresenham’s algorithm is so much fun!
I then went and did a 24-hour mountain bike race in a team of five (we came third that year) and recorded the first half of one of the laps in glorious 3D. You are going to either need a proper 3D television to watch this or use some red/green (actually cyan is closer) glasses (the kind you get in breakfast cereals!) – otherwise you can just hold two bits of suitably coloured filters against your face.
Liz again: editing this post, I have realised that the next video gives me motion sickness even without Gordon’s 3D glasses. Proceed with caution. Gordon, I can’t believe you kept this stuff up without sleeping for 24 hours.
Why am I showing you this? Well mostly because I had so much fun doing it, and it really shows how the real 3D helmet cameras can make the experience of home video just so much better if you’re doing something fast and aggressive. I hope you agree!
Finally, of course, the Raspberry Pi camera (now in production and being released next month) is very closely related to this one – although it’s actually higher quality; the images we’ve been seeing in test are looking fantastic. This project gives you an impression of the kind of thing you’ll be able to do with it with a bit of extra coding – and of the sort of extra legwork we’re looking for from people entering the competition to win a pre-production camera board.
I’ve been looking for where I put the video manipulation code; if I can find it, I’ll put it into GitHub somewhere so you can have a play yourself (if anyone is remotely interested)!
Finally – really finally – you have to think about the fact that the Raspberry Pi has two CSI interfaces, meaning there’s a potential to add two camera boards. Does that mean it would be possible to do all this completely on a single Raspberry Pi? We haven’t experimented with the idea yet – only the future can tell…
As well as an ARM processor, the Raspberry Pi’s system on a chip (SoC) also contains 48 extra processors optimised for the calculations involved in 3d graphics.
As an example of how to use these processors on the Raspberry Pi, Peter de Rivaz (an old and revoltingly clever friend of ours, who has been doing Raspberry Pi development work in his spare time) has written a charityware 3d physics puzzler, using them to draw dynamic clouds, shadows, water reflections, and lots and lots of penguins.
Visit penguinspuzzle.appspot.com for instructions on installing this game on the Raspian “wheezy” OS, or to play a WebGL version in your browser if you haven’t got a Pi yet.
The source code is freely available on github if you want to have a go at writing your own 3d game. If you do, let us know about it – we’d love to see what you come up with!
Liz: Some news from Tim Skillman – which is going to be particularly interesting for those of you who wanted to use the accelerated 3D potential of the Raspberry Pi, but who didn’t fancy getting down and dirty with OpenGL ES. Pi3D is still a work in progress, but there’s already plenty you can already it do with it if you’re interesting in playing with 3D models on your Raspberry Pi. Tim includes download links for the module and for some examples. Over to Tim!
Pi3D is a Python module designed to open up the 3D abilities of the Raspberry Pi BUT with a difference: it will provide simple yet powerful functions for kids (and adults) to create 3D with very little knowledge of programming. The main aim of Pi3D is to instil some fun and excitement and get kids (and adults) coding!
Eventually, Pi3D will import and render several 3D & 2D file formats, create 3D objects, fractal landscapes, compile scenes into vertex arrays and render shaders. Pi3D is in its early stages although you can already experiment with both 3D models and 2D sprites (similar to pygame – but much faster and more capable!) Pi3D also uses the Python Imaging Library, so this will need to be installed first (instructions with the code).