Difference between revisions of "The Beginner Guide to Getting CEGUI Rendering"

From CEGUI Wiki - Crazy Eddie's GUI System (Open Source)
Jump to: navigation, search
m (Robot: Cosmetic changes)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{VersionBadge|0.6}}
 
{{VersionBadge|0.6}}
 +
{{Series|The Beginner Guide|1}}
 +
 
{{notice|message=This tutorial is for CEGUI versions up to 0.6.2.  For later releases, see the tutorials in [http://www.cegui.org.uk/docs/current/ the main documentation].}}
 
{{notice|message=This tutorial is for CEGUI versions up to 0.6.2.  For later releases, see the tutorials in [http://www.cegui.org.uk/docs/current/ the main documentation].}}
  
Line 70: Line 72:
 
  draw3DScene();<br />
 
  draw3DScene();<br />
 
  // draw GUI (should not be between glBegin/glEnd pair)
 
  // 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();'''
 
  '''CEGUI::System::getSingleton().renderGUI();'''
  
Line 86: Line 91:
 
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.
 
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|CrazyEddie]] 03:34, 9 February 2008 (PST)
+
[[User:CrazyEddie]] 03:34, 9 February 2008 (PST)
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Latest revision as of 20:51, 17 July 2011

Written for CEGUI 0.6


Works with versions 0.6.x (obsolete)

The Beginner Guide series

This page is part of a series, use links above to easily navigate through all chapters of the 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.

  1. Create an instance of a CEGUI::Renderer based object.
  2. Create the CEGUI::System object.
  3. 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.


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)