Using Flash in your 3D games
Posted on June 11th, 2008 in Tutorials |
This post will cover how to use flash in your 3D games in a really fast and easy way. The library that we are going to use is gameswf (pronounced “game swiff”) and it is open source. Of course, this is not the only solution available, there is also a commercial middleware called Scaleform but this time I want to focus on the open source solution.
What is GameSWF ?
Gameswf is designed to be used as a UI library for computer and console games. To show that it is possible to integrate it with any engine I have implemented 2 solutions, the first one uses GLUT and, in the second one (in another tutorial) I have integrated it with Irrlicht.
Why I am writing this post? Because I don’t want any other programmer feels that there is not enough information in internet about using Flash in your 3D games! I have been working with this library lasts months and the results are pretty good, it can render shapes, text, gradients, sprites and it is even compatible with ActionScript (very basic actions). The only difference you will see between this solution and the original Flash Player is the aliasing. If you want antialiasing then you will have to either improve it or rewrite it.
What you should not expect? Don’t expect the most stable fast library ever but it is more than enough to start working with Flash in your 3d environments. If you are looking for a very stable version of it with more support and performance, I would strongly recommend you to use Scaleform. It is a commercial solution and the results are almost the same as the ones you get with the original Flash Player. In one of the companies I worked for, I integrate it with their 3D engine and it is really flexible, scalable and well-designed, so, it is up to you.
I am ready! Ok, since this is not a really in-depth tutorial, I will not show all the details of the integration but I have attached the source code to play a swf file with Gameswf. In theĀ source code of this article you will not find the libraries, you need to download them by your own.
You can find gameswf here. Once you have it, you should generate the library (actually I have changed some properties to used as a .lib but this is also up to you)
To use this library for rendering your flash files is going to be as easy as these two steps (maybe 3 more lines of code).
First step
Set the renderer your are going to use.
- g_pRenderHandler = gameswf::create_render_handler_ogl();
- gameswf::set_render_handler(g_pRenderHandler);
Load the movie.
- g_pMovieDefinition = gameswf::create_movie( cpFilename );
And finally create an instance of it.
- g_pMovieInterface = g_pMovieDefinition->create_instance();
Second step
Update the time and render the movie.
- // You should do this with deltaTime
- g_pMovieInterface->advance(0.02f);
- g_pMovieInterface->display();
That’s all ! Pretty easy huh.
Downloads :
6 Responses
[...] Usando Flash en juegos 3Dwww.poljeremias.com/2008/06/11/using-flash-in-your-3d-games/ por galchwyn hace pocos segundos [...]
Tahnks for posting
If you’re following this tutorial, make sure you have the 2008-01-05 snapshot of gameswf. The 2008-06-17 snapshot changes some of the data structures used here.
Good post. Thanks.
A question: instead of display frames, how to do if we want to redirect frames to AVI file? So, in result we can converting the SWF to AVI format.
Regards
I’ve never given this a try, but I think it’s about time I do.
Buen sitio, encontr