Tag Archives: EasyAGAL

Playing with Adobe Stage3D

I’ve been playing with Adobe Stage3D a fair bit lately. For the uninitiated, Stage3D is Adobe’s new API for hardware-accelerated 3D in Flash. The transition from programming in a mature API (i.e. Direct3D 11) to Adobe’s new one is a bit jarring, and the documentation is pretty sparse, but it’s definitely fun to play with!

I’m currently working on creating a 3D shoot-em-up, with the project hosted on github.

Thoughts on the API

Setting up the development environment was painful back in late 2011 when one needed to modify the Flex SDK, but since then it’s become pretty much painless. In FlashDevelop, you just need to make sure you set the compiler option “-swf-version=13″ along with targeting Flash Player 11+, and you’re all set. FlashBuilder is equally straightforward.

The Stage3D API is definitely usable, but figuring out how to sanely structure a program with it was a bit of a headache at first. The most important thing I had to keep in mind was that Stage3D is not DirectX – things are simply done differently. When parsing a mesh, my gut instinct was to define a vertex structure with position, UV coordinates, normals, etc., which drove me right into a wall. Stage3D does not have an equivalent to Direct3D’s D3D11_INPUT_ELEMENT_DESC. Ultimately, it turned out that it was both easier and clearer to just keep a separate Vector for each of the vertex attributes and then upload those separately to the graphics card.

Switching from HLSL to AGAL hasn’t been too difficult, but to be fair I have enough experience with assembly languages that I’m comfortable with them. Also, I’m a bit of a newbie when it comes to shaders, and thus most shaders I’ve written have been pretty simple. That all being said, the EasyAGAL library makes AGAL a lot less painful and significantly more usable by wrapping all of the instructions in ActionScript. You still write the same programs with the same instructions, but code completion, syntax highlighting, being able to effectively write macros, etc. is a huge step forward.

Of course, you could bypass that entire headache by using a 3D engine like Away3D, but that’s no fun. =]

Useful Stage3D Links

Given how relatively new Stage3D is, there aren’t many resources available online. That being said, here are a few pages I found useful:

  • The main Stage3D page has some useful links to get you started.
  • Make sure to check out Adobe’s game development page.
  • This tutorial walks you through making a 2D shoot-em-up using Stage3D for hardware acceleration. I’ve only skimmed it, but it has some cool examples of things like batched geometry and generating mipmaps dynamically.
  • The book Adobe Flash 11 Stage3D (Molehill) Game Programming Beginner’s Guide is decent, though most of what I’ve gotten out of it has been seeing some examples of using Stage3D’s API. The book doesn’t really walk you through Stage3D so much as show examples and explain them chunk by chunk, but it’s a start. The code is unfortunately rather messy… in particular, it suffers from the same fate as most “intro to 3D game programming” type books where almost everything is shoved into one file. The final game’s main AS file is over 2000 lines of code, for example. All that being said, it’s still incredibly helpful when so few resources are currently available. While it’s by no means the best programming book I’ve laid my eyes on, it gets the job done and provides some much-needed examples of Stage3D in use.
  • EasyAGAL is an awesome library.
  • Pixelante Game Studios has a number of tutorials up on their site, though they’re more along the lines of useful code snippets and tips than full-on tutorials.
  • iFlash3D.com has some useful blog posts, though it seems like most things posted lately are thinly-veiled plugs for their Flash3D Librarian tool for sale.