Painting with Stage3D using Starling
7 years ago
I’ve been trying to find ways to improve the performance of paint mixing with Flash and I though I could try using Stage3D for hardware accelerated graphics. But then I realised that Stage 3D is optimised for polygons and 3D models so it was probably not the best solution. I wanted to see if it was possible anyway and thanks to the Starling Framework and a bit of help from Thibault Imberts book it turns out its possible using the RenderTexture on an Image object, but it’s not really possible to do any complex drawing. Starling’s Image object is the equivalent of the Bitmap class, which is using to display any BitmapData. I made an example which you can see below.
By creating a RenderTexture for an Image object, you can use the RenderTexture’s draw() method to draw another Image’s texture onto it. This is similar to using BitmapData and draw() to draw one bitmap onto another. But Stage3 doesn’t use pixels, it uses textures mapped to triangles instead therefore at this stage it’s not possible to use something like getPixel() for get colour data from the ‘canvas’.
The demo below is a basic drawing application where you can adjust the size and colour of the brush. As you can see there is no real advantage of using Stage3D so I think I’ll stick with the standard Bitmap classes. Another possible route to explore next could be using PixelBender or NativeExtensions to handle the heavy calculations of colour mixing.
Update: Check out my PixelBender paint mixing here.
But for now here is the demo:
- SPACE to change colour
- UP to increase brush size
- DOWN to decrease brush size