My app uses OpenGL to render almost everything when in game, but I would like to be able to render/overlay text as well. I can do this with no problems in the simulator - basically doing this:
1. Render all OpenGL, including clearing depth and colour buffers. This involves setting up the full-screen viewport, clearing depth and colour, rendering a skybox (without z test/writes), then rendering 3D geometry (and finally some 2D textures on the top for the UI).
2. Flush my OpenGL (not sure if this would be expected to be needed):
3. Clear the depth buffer, even though I don't see why the font rendering should need it (if I don't, my OpenGL rendering is corrupted, though I don't know why):
IwGxClear(IW_GX_DEPTH_BUFFER_F); // Or use glClear
4. Render the text using:
CIwGxFont* font = (CIwGxFont*) IwGetResManager()->GetResNamed("font_large", IW_GX_RESTYPE_FONT); IwGxFontSetFont(font); CIwColour origColour = IwGxFontGetCol(); IwGxFontSetCol(0xffa0a0a0); IwGxLightingOn(); uint16 fontHeight = font->GetHeight(); IwGxFontSetRect(CIwRect(0,(int16)IwGxGetScreenHeight() - fontHeight*5/4,(int16)IwGxGetScreenWidth(),fontHeight)); IwGxFontSetAlignmentHor(IW_GX_FONT_ALIGN_CENTRE); // fill in txt here IwGxFontDrawText(txt); // tidy up IwGxFontSetCol(origColour); IwGxLightingOff();
In the simulator, this works fine. However, under Android the top left of the display does not render my OpenGL correctly - in this region the depth buffer seems to be modified by the font rendering so that the terrain does not render over the skybox - see here:
In this region sometimes the 3D geometry shows through, and sometimes, as in this picture, you get z-fighting so partial rendering of the 3D geometry.
I've also tried pretty much every modification to this I can think of - trying to use suggestions in the docs (rather incomplete) and the Marmalade FAQ http://www.drmop.com/index.php/marmalade-sdk-faq/ Many of these alternatives (including splitting up the font rendering so that it uses IwGxFontPrepareText before my OpoenGL calls to prepare the text, and then renders afterwards) work correctly on the simulator, but none so far work correctly on device.
I'm using in the icf file:
but haven't had any success with Transform=SW either.
Any ideas? I'm on the brink of giving up on this and writing my own text rendering system in OpenGL...