Hi All,

Just managed to get a little time free and picked up on the 3D buzz that is here now, something I need/want to get into.

Some of you may be old geeks (like me) who played on various games in the past. One of these, for me, was a serious drain on my personal time. I’m talking about Elite!

Elite was written by David Braben, I think in machine code, for the BBC Micro - then later for the Archimedes (in Arm code). It later appeared on the Amiga, Atari ST, PC and others as Frontier and drew many followers.

After achieving Elite status (I’ve got the badge) I wandered off in pursuit of my second devotion (Lara Croft) on the PC and Elite drifted into obscurity (or so I thought).

Why am I telling you this - easy, wanting to learn about 3D, meshes and shaders I thought I needed an objective. So I decided to try to generate 3D ships from Elite. I remember the Cobra MKI and MKIII well. Some Elite pics below.


Galaxy Map

Space Station

I searched the net for models and found them, they have been built into 3D models for Direct X .X format. But I found these unusable, does anyone know how to convert them to OpenGL format? So I struggled, until I found an unusual tool to help - paper models!!!

Armed with these, a ruler and a little imagination I managed to determine the vertices and the associated triangles for 3D design.

After digging through the Codea archives, looking for all things 3D, I found code submitted by dave1707 which finally lit the bulb. With a few trials and a lot of patience I eventually built my Cobra MKIII, video provided.

My Crude Vid Starter

Still relatively crude!!!

I’m now going to work through the models, Krait is in hand and Feu-de-Lance will follow. Data and code will be posted as I progress. Eventually I’ll include shaders and tidy the code up so it looks more like an App.

I’m now beginning to understand more about 3D. This has been well worth the effort. However there are some problems you may be able to help me with - the Cobra model is missing a viewing panel on the front and the engine panels on the back. I tried to superimpose them on the existing triangles but it’s messy. Offsetting doesn’t work either. The other thing is that I’d like to superimpose the model on a background, but the background covers the model - as do the stars from Reefwings Twinkle starfield class and any sprites printed to screen. Any ideas on prioritising the model to be on top??

As an aside, Elite/Frontier live on as Oolite and Pioneer. Both gone beyond Elite, especially Oolite. Well worth the visit.

But more importantly, and you probably all know about this, Braben has been busy and is developing Elite Dangerous, release 2014. This looks like a serious time magnet, definitely take a peek at this.


For those wanting to see Oolite there are a number of videos on Youtube. It’s Opensource and has developed with a large number of addons, thanks to a keen support group.

One Oolite video

When drawing in 3D, I suggest you sort the meshes by distance (at every redraw) and then draw them from furthest to nearest. The background and star field should be drawn first.

I wouldn’t worry about the finishing touches on the ship until you know the game is going to work ok,and run fast enough.

I’ve written a lot of posts on 3D modelling in Codea that may help you.

Hi @Ignatz,

Followed your tutorials, code and comments for some time. Never seem to catch up - you are quite prolific. Thanks for your feedback.

One specific thing I would like to query - can you have more than one set of meshes on the screen at once?

If so, I take it, from your suggestion that I would need to put the backdrop at the back?

That looks fine until you consider that I will need to use a 2D mesh and a 3D mesh. The 2D at the back and the 3D in front. Also I need to generate some depth with the 3D mesh. Is that possible with the approach I’ve suggested?

Thanks (for all your contributions)



You can switch between 2D and 3D drawing at any time, ie draw one, then the other

You can have as many meshes as you need

What sort of ‘depth’ are you looking for in 3D?

To restore drawing back to the screen (appears 2D [Nothing in Codea is really 2D, it just uses a certain camera angle.]):


Sometimes things glitch into meshes, though, since nothing in Codea is really 2D. (OpenGL 3D Pipeline, I believe.) To fix that, in setup you can say

screen = image(WIDTH, HEIGHT)

In draw at the very top of the 3D drawing, call


(resetMatrix() translates back to 0, 0, 0 if you had translated it earlier.) And then when you want to draw in 2D, call

sprite(screen, WIDTH / 2, HEIGHT / 2)

and use the method at the top. Your drawing should be back to normal, appearing 2D, with no 2D sprites going into 3D objects. If you turn the iPad during them game to prevent glitching, in function orientationChanged(newOrientation) just say

screen = image(WIDTH, HEIGHT)

again. And if you want to apply a shader to the screen this works well, too. Just use the image “screen” as the texture for a mesh.

Try this shader too:


I’ve got the data for all of the elite models, I converted some of them by hand when I first wanted to try my hand at 3d, I’m on holiday at the moment but if you want the source and data I made then drop me a PM and I’ll send them to you when I get back next week.

Hi Guys,

Sorry I’ve been a bit slow in sorting out my problem - had to resolve a short term problem with my PC. Now it’s done and dusted can return to the coding.

@SkyTheCoder - hadn’t noticed the ortho() function but read up a little on it and it definitely looks like a way forward. Noticed some Codea links on this:




Plus others - coupled with your notes I’m hoping to be able to crack this.

My idea is to have a fixed 2D mesh as background and ultimately 3D moveable textured ships up front.

@juaxix - looked at this site (good find), thought I was using the wrong browser at this is all wire framed. Then I looked at the code. Question - I thought the shaders were routines for building up 3D scenarios not wire frames. I thought that Codea would build up the vector arrays etc and then use these in the shader for building up the final 3D image. But it looks like you could do either - all in shader or passed on data from Codea. Is that the case? Need to read up more on shaders and how they interface with Codea - could influence the way I approach this app.

@TechDojo - great to hear that someone else also had the same idea and pursued it. Like I said I found most of the data in formats used by java routines, and this data seemed incompatible with the format I was using (i.e. direct.X format for the java models). I now have two models Cobra MKIII and Krait. It would be great if you could send the data to save me time in producing this app. I’ll drop you a PM.

Thanks All,



Regarding the shadertoy example. Shadertoy is an interesting site to get inspiration from, but it only implements fragment shaders. The idea of the fragment shader instantiating hard coded vertices as this one does is very far from ideal. Also it then does mojo to make it wireframe. There are some posts about wireframing, but to be honest in Codea it is MUCH easier to do solid meshes than wireframes.

The way to do it is definitely to build up a mesh with the vertices in Codea and use more normal shaders for the output and don’t do wireframes as they are more effort.