Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using OpenGL in Brew Mobile Platform Applications

Base version:

Brew MP 1.0

Tested version:

Brew MP 1.0

Phone tested:

No

To provide support for OpenGL, Brew® Mobile Platform (Brew MP) includes two functions, EGL_Init() and GLES_Init(), that an application can call to do the initialization required to use OpenGL APIs in a Brew MP application. After this initialization is done, the application can call standard OpenGL functions.

Brew MP also includes EGL_Release() and GLES_Release() functions that should be called to release EGL and GL resources when the application is finished using EGL and OpenGL. No EGL calls can be made after calling EGL_Release(). No GL calls can be made after calling GLES_Release().

Note: Brew MP supports OpenGL ES 1.1 and EGL 1.3.

It is assumed that you are familiar with OpenGL programming. For more information on OpenGL ES and EGL, see http://www.opengl.org/.

Objective

This topic describes how to use OpenGL functions in a Brew MP application and shows examples of the required initialization.

Requirements

An application that uses OpenGL needs to do the following:

  • Include the following files from $(BREWMPSDK)\media\inc:
    • EGL_1x.h
    • GLES_1x.h
    • gles/egl.h
    • gles/gl.h
  • Before making any calls to OpenGL functions, call EGL_Init(), then call GLES_Init().
  • Call GLES_Release() and EGL_Release() before exiting.

In addition, when you compile an application that uses OpenGL, you need to do the following:

  • Specify $(BREWMPSDK)\media\opengles\lib\Win32_Release as an additional library directory.

    Note: If you are compiling for a device instead of the simulator, the $(BREWMPSDK)\media\opengles\lib directory also contains ADS12arm9_Release and RVCT22arm11_Release directories that contain libraries for the ADS and RVCT compilers.

  • Specify OGLExtension.lib as a required library.

Sample code location

Two versions of the sample code are available:

  • c_drawtriangle is for Brew MP 1.0.0
  • c_drawtriangle_1_0_1 is for Brew MP 1.0.1

ZIP filename

Location

Run app

c_drawtriangle

Brew MP Resources

  • Download and extract the ZIP file.
  • Compile the app.
  • Run it on the Brew MP Simulator.
c_drawtriangle_1_0_1

Example - initialization

The code examples in this section are from the c_drawTriangle sample. InitGLSurface(), which is called from c_drawTriangle_InitAppData(), calls EGL_Init() and GLES_Init() before calling EGL functions to setup the EGL display and EGL surface.

   if (EGL_Init( pMe->a.m_pIShell ) != SUCCESS)   
   {   
      return FALSE;   
   }   
   
   if (GLES_Init( pMe->a.m_pIShell ) != SUCCESS)   
   {   
      return FALSE;   
   }

Example - rendering

After c_drawTriangle_InitAppData() is called, the application sets a timer. When the timer expires, the RenderLoopTimerNotify() callback function is called, which draws the triangles and resets the timer. RenderLoopTimerNotify() calls Render(), which calls drawTriAngle() to draw the 3D geometry, then calls eglSwapBuffers() to swap the front buffer and back buffer, as shown in the following example:

void Render(c_drawTriangle* pMe, uint32 currTime) 
{ 
   drawTriAngle(pMe,currTime); 
   eglSwapBuffers(pMe->eglDisplay, pMe->eglSurface); 
} 
 
//------------------------------------------------------------------ 
void RenderLoopTimerNotify(void* pi) 
//------------------------------------------------------------------ 
{ 
   c_drawTriangle* pMe = (c_drawTriangle*)pi; 
   uint32 currTimeMs = ISHELL_GetUpTimeMS(pMe->a.m_pIShell); 
 
   Render(pMe, currTimeMs);   
   ISHELL_SetTimer(pMe->a.m_pIShell, REFRESH_IN_MS,
               (PFNNOTIFY)RenderLoopTimerNotify, pMe); 
}

Example - freeing resources

The FreeGLSurface() function, which is called from c_drawTriangle_FreeAppData() and DisplayErrorMsg(), calls a number of EGL functions to free resources, then calls GLES_Release() and EGL_Release():

   if (pMe->eglDisplay != EGL_NO_DISPLAY)   
   {   
      eglMakeCurrent( EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE,
                  EGL_NO_CONTEXT );   
      eglDestroyContext( pMe->eglDisplay, pMe->eglContext );   
      eglDestroySurface( pMe->eglDisplay, pMe->eglSurface );   
      eglTerminate( pMe->eglDisplay );   
      pMe->eglDisplay = EGL_NO_DISPLAY;   
   
      GLES_Release();   
      EGL_Release();   
   }

Related information