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
 
 
(18 intermediate revisions by 11 users not shown)
Line 1: Line 1:
 +
{{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].}}
 +
 
In order to get CEGUI to render, no matter what your target engine is, there are basically three steps that must be done.
 
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 an instance of a CEGUI::Renderer based object.
#Create the CEGUI::System object.
+
# Create the CEGUI::System object.
#Call the method to render the GUI.
+
# 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 Imbeciles Guide to Loading Data Files and Initialisation]], and also you need to get your inputs into the system which is covered in [[The Imbeciles Guide to Injecting Inputs]].
+
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 ===
 
=== 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 Ogre and not CEGUI.
+
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:
 
The basic renderer creation code is:
Line 16: Line 21:
 
'''Direct3D 8.1'''
 
'''Direct3D 8.1'''
 
  CEGUI::DirectX81Renderer* myRenderer =
 
  CEGUI::DirectX81Renderer* myRenderer =
new CEGUI::DirectX81Renderer(myD3D8Device);
+
    new CEGUI::DirectX81Renderer( myD3D8Device );
  
  
 
'''Direct3D 9'''
 
'''Direct3D 9'''
 
  CEGUI::DirectX9Renderer* myRenderer =
 
  CEGUI::DirectX9Renderer* myRenderer =
new CEGUI::DirectX9Renderer(myD3D9Device);
+
    new CEGUI::DirectX9Renderer( myD3D9Device, 0 );
  
  
 
'''OpenGL'''
 
'''OpenGL'''
 
  CEGUI::OpenGLRenderer* myRenderer =  
 
  CEGUI::OpenGLRenderer* myRenderer =  
new CEGUI::OpenGLRenderer();
+
    new CEGUI::OpenGLRenderer( 0 );
  
  
 
'''Ogre3D'''
 
'''Ogre3D'''
 
  CEGUI::OgreCEGUIRenderer* myRenderer =  
 
  CEGUI::OgreCEGUIRenderer* myRenderer =  
new CEGUI::OgreCEGUIRenderer(myRenderWindow);
+
    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'''
 
'''Irrlicht Engine'''
 
  CEGUI::IrrlichtRenderer* myRenderer =  
 
  CEGUI::IrrlichtRenderer* myRenderer =  
new CEGUI::IrrlichtRenderer(myIrrlichtDevice, true);
+
    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.
  
=== Create the CEGUI::System object ===
+
  new CEGUI::System( myRenderer );
Another extremely simple step.  Just 'new' the CEGUI::System object, passing in a pointer to the renderer created in the previous step.
+
 
+
  new CEGUI::System(myRenderer);
+
  
  
 
=== Call the method to render the GUI ===
 
=== 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
+
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'''
 
'''Direct3D 8.1 / 9'''
 
  // Start the scene
 
  // Start the scene
  myD3DDevice->BeginScene();<br>
+
  myD3DDevice->BeginScene();<br />
 
  // clear display
 
  // clear display
  myD3DDevice->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);<br>
+
  myD3DDevice->Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);<br />
 
  // user function to draw 3D scene
 
  // user function to draw 3D scene
  draw3DScene();<br>
+
  draw3DScene();<br />
 
  // draw GUI
 
  // draw GUI
  CEGUI::System::getSingleton().renderGUI();<br>
+
  '''CEGUI::System::getSingleton().renderGUI();'''<br />
 
  // end the scene
 
  // end the scene
  myD3DDevice->EndScene();<br>
+
  myD3DDevice->EndScene();<br />
 
  // finally present the frame.
 
  // finally present the frame.
 
  myD3DDevice->Present(0, 0, 0, 0);
 
  myD3DDevice->Present(0, 0, 0, 0);
Line 65: Line 70:
 
'''OpenGL'''
 
'''OpenGL'''
 
  // user function to draw 3D scene
 
  // user function to draw 3D scene
  draw3DScene();<br>
+
  draw3DScene();<br />
 
  // draw GUI (should not be between glBegin/glEnd pair)
 
  // draw GUI (should not be between glBegin/glEnd pair)
  CEGUI::System::getSingleton().renderGUI();
+
  // 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'''
 
'''Irrlicht'''
 
  // start the scene
 
  // start the scene
  myIrrlichtDriver->beginScene(true, true, irr::video::SColor(150,50,50,50));<br>
+
  myIrrlichtDriver->beginScene(true, true, irr::video::SColor(150,50,50,50));<br />
 
  // draw main scene
 
  // draw main scene
  myIrrlichtDriver->drawAll();<br>
+
  myIrrlichtSceneManager->drawAll();<br />
 
  // draw gui
 
  // draw gui
  CEGUI::System::getSingleton().renderGUI();<br>
+
  '''CEGUI::System::getSingleton().renderGUI();'''<br />
 
  // end the scene
 
  // end the scene
 
  myIrrlichtDriver->endScene();
 
  myIrrlichtDriver->endScene();
 
  
 
=== Conclusion ===
 
=== 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.
+
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)
  
--[[User:CrazyEddie|CrazyEddie]] 11:14, 11 Apr 2005 (BST)
+
[[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)