Saturday, 26 June 2010

Repost - Tips for porting existing OpenGL applications to bada

Recycled from -

As OpenGL® is used for 3D graphics and has enormous features for game developers. It is not an exaggeration to say that without it, no mobile platform is complete. The good news for developers is that OpenGLES 1.1 as well as 2.0 are fully supported in bada and you can port your existing applications over to bada with negligible effort. Before getting into much depth, here is some quick information on important elements in the application framework, names spaces, classes, and functions, that are required to port an OpenGL application and some time-saving tips for porting.

Overview of application framework

The application framework in bada is very user friendly which makes for faster application development. The framework creates the base frame, which enables you to use all UI related functionalities and provides basic listeners (explained below) that are required to port an OpenGL application.
The OnAppInitializing() event handler fires to let you initialize all the components and modules that you need before the application actually comes up.
The OnForeground() event handler fires when the application is ready to display the data on the screen. You can add logic to have control over what you want to display on the screen first.

The OnBackground() event handler fires when a higher priority application takes over the screen to let you release resources and stop drawing on the screen
The OnAppTerminating() event handler fires to let you release all the resources used by your application. This event handler fires on user requests by calling Osp::App::Application::Terminate() or due to a system trigger to close the application.
Basic classes to be used in an application

To use the OpenGLES API, you must use the Osp::Graphics::Opengl namespace, which provides access to all OpenGL functionality.
While porting, the basic thing that you need is a continuous update of the screen. In bada, you must have a timer for this. The best part of using a timer is that you have complete control over how fast or slow you want the screen refresh to happen. For more information, see the Osp::Base::Runtime::Timer class in the bada API Reference.
For interactive graphics, you must use the Osp::Ui namespace, where you can register key and touch events. For more information, see Osp::Ui::Control for event listeners.

Tips for porting
1) You can add OpenGLES initialization code, timer creation, and other login in the OnAppInitializing call. For example:
a. Initialize EGL
b. Initialize GL
c. Create the timer and construct it:
__pTimer = new Timer; if (null == __pTimer) return; __pTimer->Construct(*this); // this is the class object pointer inheriting from the // Timer listener class
2) For eglCreateWindowSurface you need a window surface, which you can get by calling GetAppFrame()->GetFrame() and casting it to an EGLNativeWindowType
3) Start the timer in the OnForground() event handler.
GlApp::OnForeground(void) { if(__pTimer) { __pTimer->Start(TIME_OUT); } }
4) Update and draw the screen when the timer expires and restart the timer. Update() and Draw() functionalities are exactly the same as how they are in windowed GL applications.
GlApp::OnTimerExpired(Timer timer) { if (!__pTimer) { return; } Update(); if (!Draw()) { AppLog("Draw() has failed.\n"); } __pTimer->Start(TIME_OUT); }
5) Stop the timer in the OnBackground() event handler:
GlApp:: OnBackground(void) { if(__pTimer) { __pTimer->Cancel(); } }
6) For interactive graphics, register touch and key events for the frame with the GetAppFrame() methodand add logic to handle key and touch events within their respective event handlers. For example :
GlApp::OnAppInitializing(AppRegistry&; appRegistry) { result r = E_SUCCESS; IAppFrame* pAppFrame = GetAppFrame(); if (NULL == pAppFrame) { AppLog("GetAppFrame failed.\n"); return; } r = pAppFrame->AddKeyEventListener(*this); if (IsFailed(r)) { AppLog("AddKeyEventListener(*this) has failed.\n"); return; } r = pAppFrame->AddTouchEventListener(*this); if (IsFailed(r)) { AppLog("AddTouchEventListener(*this) has failed.\n"); return; } }
7) Use the shader compiler tool in \\Tools\GLES2 Shader Compiler to generate the shader binary for the target.
Sample existing OpenGL application ported over to bada
You can find many sample applications on the internet. One good resource for you to refer to is -
Below is a screenshot of one of the available sample applications ported to bada using the tips above. As previously mentioned, this took negligible effort to port. However, if the application is too big, then it is always recommended to know the logic and place the code appropriately while porting to get the optimal results.

No comments:

Post a Comment

Please don't post spam. Its tiresome.

Note: only a member of this blog may post a comment.