More refactoring of the code to use the XBGLEngine.