IwGame – How to mix raw Open GL with IwGame Scenes

A fellow developer recently had the need to mix raw Open GL with IwGame scenes so I decided to take a look into the matter. The problem with mixing the Marmalade SDK’s graphics sub systems IwGx and Iw2D with raw Openm GL is two fold:

  • Marmalade’s IwGxClear() / Iw2DSurfaceClear() functions seem to do something internally that prevents the display of Open GL rendering code. I believe that the actual underlying call to clear the screen is called when IwGxFlush() gets called so any Open GL rendering carried out during the frame is wiped out as soon as IwGxFlush() is hit.
  • IwGx / Iw2D rendering is deferred until either IwGxFlush() or Iw2DSurfaceShow() is called. This means that anything you draw using Open GL during the frame will be drawn over when the flush is done at the end of the frame because Marmalade does all its rendering when the flush occurs

Ok, problem 1 is easy to fix. We’ve added a new property to CIwGame called GLCompatible. If you have any scenes in your app that need to render using raw Open GL then call GAME->setGLCompatible(true) to force IwGame to clear the display buffer using Open GL instead of IwGx. (You will need to download http://www.drmop.com/wp-content/uploads/2012/06/GameSceneGLTest.zip and use the new IwGame that is contained in the archive to use this new feature.

Problem 2 is also easy to fix. In the scene that you call raw Open GL rendering code, call IwGxFlush() before you begin rendering using Open GL. This will force Marmalade to draw everything that’s waiting to be drawn. As IwGx is built upon Open GL you should also NOT rely on GL to be in the state that you left it in previous frame, so ensure that you restore matrices, shade model and any other GL specifics that IwGx may have modified.

You can download an example that shows the complex UI example with a GL scene on top. The GL scene also contains a stack panel that shows that you can also add IwGame stuff on top of GL rendering. The example is located at http://www.drmop.com/wp-content/uploads/2012/06/GameSceneGLTest.zip

Leave a Reply