(with the help of GLKit)
There are many ways to do this, its often used in paint programs.
Philip Rideout’s iPhone 3D Programming has a way to do it in C++, but its hard to abstract the method from the code.
There is a nice article written here which gives the method I used.
In my case the lines are temporary exhaust lines – so I don’t need to bake the lines into a texture as the above solution does.
The method just draws line segments from point to point as rectangles. Each line segment is a sprite which is rendered which ever way you render your OpenGL sprites.
Here is a picture of a ship emitting an exhaust – that uses the code below – the ship is moving very fast – so the sharp angles don’t matter so much.
And below is the code I wrote to do the lines:
The development of my game Kondrian is coming to an end.
Here is a miscellany of what I think we’re useful lessons, each too small to warrant a blog post:
- Each of the levels in Kondrian can be 100 x 100 tiles wide. It’s simple enough to only draw the tiles when they are on screen, but I also created a scheme a bit like UITableviewCells in a UITableview in order to conserve memory. There are in fact only about 200 tiles (depending on whether its an iPhone or iPad) created, and they are reused when they go off screen. Reusing usually involves giving the tiles the appropriate texture for a tile potentially appearing onscreen in the direction that the player is moving.
All sprites (and the vertices, indices, VBOs VAs) are created at startup.
When a sprite is needed it is de-queued and enabled, only enabled sprites are updated and drawn. No on the fly malloc-ing or creation of gl buffers.