I am using OpenGL ES 2.0 to create a 2D game for Android 2.2 and was planning on using LibRocket for the GUI. Does anyone have any links or knowledge they would share on how to integrate LibRocket with the android platform? I know that it is a c++ library that would need to go through the NDK, however I rather not change my OpenGL rendering code to the NDK unless I have to.
1 Answer
This might be tough and I'm not convinced that you will have acceptable performance on android devices at the end, but it seems that at least one game has been released on android using LibRocket.
You can write a few wrapper classes in c++ that allow LibRocket to use your own rendering functions. These classes can call back the proper java functions of your engine. You will also need, on the other hand, to forward input from java back to LibRocket using the provided method.
Here is a more straightforward description of the steps:
- Build LibRocket for Android platform using the NDK (this already might be difficult, but LibRocket shouldn't have much external dependency. Iirc, it only requires the STL).
- Write your interface between java and LibRocket as a second C++ lib. You must write three classes that inherit from
Rocket::Core::RenderInterface
,Rocket::Core::SystemInterface
, andRocket::Core::FileInterface
. Each method of these classes should forward calls to an equivalent java method that can do the proper things in your engine. Here you can find some good help to do that. - Write some static functions that will be called by java (check any sample from the NDK to see how to call c++ from java) to forward inputs. Check Injecting Input from the official LibRocket doc to see what you'll need.
Then simply write an initializer in c++ that will instantiate each of the three interface and bind them to LibRocket. Call it from Java at the beginning:
Rocket::Core::SetRenderInterface(new MyRenderInterface(Width, Height));
Rocket::Core::SetSystemInterface(new MySystemInterface());
Rocket::Core::SetFileInterface(new MyFileInterface());
Hope this will help.
-
1\$\begingroup\$ I have implemented and actually use libRocket in my cross-platform engine, which means it runs well on Android, but everything is done from C++.. I don't think my use case applies well here but if you need something ask. \$\endgroup\$– GrimshawJun 10, 2012 at 0:34