The Beginner Guide to Getting CEGUI Rendering
Written for CEGUI 0.6
Works with versions 0.6.x (obsolete)
The Beginner Guide series
This tutorial is for CEGUI versions up to 0.6.2. For later releases, see the tutorials in the main documentation. |
In order to get CEGUI to render, no matter what your target engine is, there are basically three steps that must be done.
- Create an instance of a CEGUI::Renderer based object.
- Create the CEGUI::System object.
- Call the method to render the GUI.
Obviously you also need to load some data and perform very basic initialisation, which is covered in The Beginner Guide to Loading Data Files and Initialisation, and also you need to get your inputs into the system which is covered in The Beginner Guide to Injecting Inputs.
Contents
Create an instance of a CEGUI::Renderer based object
This is fairly straight forward and should pose no major obstacles for any of the supported renderers. You must of course remember to include the header file for the renderer that you will be using, also remember that for Ogre3D the renderer module now comes with CEGUI and not Ogre (Huh? Since when? As of 23/02/2010 (CEGUI 0.7.1, OGRE 1.7) the module is called CEGUIOgreRenderer, and is in CEGUI's sources, not Ogre's). (Note that you need to delete the Renderer object when you are cleaning up the program.)
The basic renderer creation code is:
Direct3D 8.1
CEGUI::DirectX81Renderer* myRenderer = new CEGUI::DirectX81Renderer( myD3D8Device );
Direct3D 9
CEGUI::DirectX9Renderer* myRenderer = new CEGUI::DirectX9Renderer( myD3D9Device, 0 );
OpenGL
CEGUI::OpenGLRenderer* myRenderer = new CEGUI::OpenGLRenderer( 0 );
Ogre3D
CEGUI::OgreCEGUIRenderer* myRenderer = new CEGUI::OgreCEGUIRenderer( myRenderWindow );
Note: Using Ogre 1.4.9 with CEGUI 0.6.2 binding the renderer to the scene manager seems to be required (in my case the GUI was not displayed while the mouse events were properly processed). To bind a scene manager to the renderer, use the setTargetSceneManager method:
myRenderer->setTargetSceneManager(mySceneManager);
Irrlicht Engine
CEGUI::IrrlichtRenderer* myRenderer = new CEGUI::IrrlichtRenderer( myIrrlichtDevice, true );
Create the CEGUI::System object to initialise the system
Another extremely simple step. Just instantiate the CEGUI::System object by using 'new' and passing in a pointer to the CEGUI::Renderer that you created in the previous step. This will cause the entire system to initialise itself.
new CEGUI::System( myRenderer );
Call the method to render the GUI
This is the only step that, depending upon your target engine, can be done differently. Basically what you need to do call the CEGUI::System::renderGUI method at the end of your rendering loop. For lucky users of the Ogre3D engine, this step is taken care of automatically. For everybody else, some simple example code can be seen below
Direct3D 8.1 / 9
// Start the scene myD3DDevice->BeginScene();
// clear display myD3DDevice->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
// user function to draw 3D scene draw3DScene();
// draw GUI CEGUI::System::getSingleton().renderGUI();
// end the scene myD3DDevice->EndScene();
// finally present the frame. myD3DDevice->Present(0, 0, 0, 0);
OpenGL
// user function to draw 3D scene draw3DScene();
// draw GUI (should not be between glBegin/glEnd pair) // make sure that before calling renderGUI, that any bound textures and shaders // used to render the scene above are disabled using glBindTexture(0) and glUseProgram(0) respectively // also set glActiveTexture(GL_TEXTURE_0) CEGUI::System::getSingleton().renderGUI();
Irrlicht
// start the scene myIrrlichtDriver->beginScene(true, true, irr::video::SColor(150,50,50,50));
// draw main scene myIrrlichtSceneManager->drawAll();
// draw gui CEGUI::System::getSingleton().renderGUI();
// end the scene myIrrlichtDriver->endScene();
Conclusion
This is the most basic introduction to setting up CEGUI to render. There are things not covered here, such as using different scene managers in Ogre and advanced options such as user specified resource providers, and so on.
User:CrazyEddie 03:34, 9 February 2008 (PST)