OGRE Tutorial Three Terrain n Sky n Fog

  • Slides: 68
Download presentation
OGRE Tutorial Three Terrain n Sky n Fog n The Root object n 1

OGRE Tutorial Three Terrain n Sky n Fog n The Root object n 1

Choose a Scene. Manager - To render terrain, set the Scene. Manager to the

Choose a Scene. Manager - To render terrain, set the Scene. Manager to the Terrain. Scene. Manager In Example. Application: : choose. Scene. Manager m. Scene. Mgr = m. Root ->create. Scene. Manager(ST_EXTERIOR_CLOSE); - The Root object (m. Root is an instance of Root) is the "core" Ogre object. (To see UML diagram of the relationships between Ogre objects here. ) - After invoking the function, the Root object then queries the Scene. Manager. Enumerator to find the Scene. Manager of the requested type and returns it. 2

Scene. Manager n n Scene. Managers are not Singletons. Allow multiple Scene. Managers Display

Scene. Manager n n Scene. Managers are not Singletons. Allow multiple Scene. Managers Display multiple Scene. Managers at the same time using multiple Viewports. The Octree. Scene. Manager registers itself as ST_GENERIC and overrides the base Scene. Manager class if the Octree. Scene. Manager plugin is used. (The Octree. Scene. Manager uses a system of culling objects that are not visible and thus it's generally faster than the default Scene. Manager. ) n Remove Octree. Scene. Manager plugin from plugins. cfg ? 3

Scene. Manager - Use a Root object to create Scene. Managers. -OGRE is flexible?

Scene. Manager - Use a Root object to create Scene. Managers. -OGRE is flexible? -install a plugin for creating Scene. Managers called “My. Scene. Manager". -To create a Scene. Manager of the type, call: m. Scene. Mgr = m. Root->create. Scene. Manager( “My. Scene. Manager“, SCENE_MANAGER_NAME); - Root: : destroy. Scene. Manager : clean up a Scene. Manager 4

Terrain n Scene. Manager: : set. World. Geometry : create scene - By using

Terrain n Scene. Manager: : set. World. Geometry : create scene - By using the Terrain. Scene. Manager, it is able to load a terrain configuration which is stored in a file. Code: Derive a new class Demo. App from Example. Application. In Demo. App: : create. Scene m. Scene. Mgr->set. World. Geometry("terrain. cfg"); n Problems : (1) Standard lighting not work properly in terrain (2) Not easy to get Shadows to work 5

Options for Terrain Generation The Terrain. Scene. Manager uses Heightmaps to generate terrain. -

Options for Terrain Generation The Terrain. Scene. Manager uses Heightmaps to generate terrain. - Specify the heightmap (gray level image) Heightmap. image=image. Name -Set the texture World. Texture=image. Name -Set detail Texture (which is interlaced with the World. Texture to make the terrain look more realistic. -Detail. Texture=image. Name A more detailed explanation of the terrain config file can be found here. 6

Terrain texture Height Map Detail texture 7

Terrain texture Height Map Detail texture 7

2 x 2 Tilings of Detail texture 8

2 x 2 Tilings of Detail texture 8

Terrain With detail texture Without detail texture 9

Terrain With detail texture Without detail texture 9

About Terrain. Scene. Manager - Designed with paging functionality. Paging terrain system : (1)

About Terrain. Scene. Manager - Designed with paging functionality. Paging terrain system : (1) the terrain is broken into chunks (2) display the portion which can be seen Advantages: -> (1) Be able to use a huge world (2) Maintain framerate For details, read Paging Scene Manager. 10

Sky Three types of sky: (1) Sky. Boxes (2) Sky. Domes (3) Sky. Planes

Sky Three types of sky: (1) Sky. Boxes (2) Sky. Domes (3) Sky. Planes To use the Example/* textures for sky, add the following line to the Example. Application: : choose. Scene. Manager: Resource. Group. Manager : : get. Singleton(). initialise. All. Resource. Groups(); 11

Sky. Boxes - A giant cube that surrounds all of the objects in the

Sky. Boxes - A giant cube that surrounds all of the objects in the scene In create. Scene(): m. Scene. Mgr->set. Sky. Box( true, "Examples/Space. Sky. Box"); 12

Sky. Domes - A giant cube is created around the Camera and rendered onto

Sky. Domes - A giant cube is created around the Camera and rendered onto - the texture is "projected" onto the Sky. Box in a spherical manner. -It looks as if the texture is wrapped around the surface of a sphere. -Drawback : the bottom of the cube will be untextured ->have some type of terrain that hides the base. In Example. Application: : create. Scene: m. Scene. Mgr->set. Sky. Dome(true, "Examples/Cloudy. Sky", 5, 8); 13

Sky. Planes - A single plane. - Best position: be somewhere towards the middle

Sky. Planes - A single plane. - Best position: be somewhere towards the middle of the terrain and close to the ground. In Example. Application: : create. Scene. Plane plane; plane. d = 1000; plane. normal = Vector 3: : NEGATIVE_UNIT_Y; m. Scene. Mgr->set. Sky. Plane( true, plane, "Examples/Space. Sky. Plane", 1500, 75); 14

Fog - When use the Terrain. Scene. Manager - call the set. Fog function

Fog - When use the Terrain. Scene. Manager - call the set. Fog function before the set. World. Geometry function - depending on which is called first, a different vertex program will be chosen to create the fog and terrain. - When creating fog, it doesn't create a fog entity in empty space. - Fog is a filter applied to whatever objects are rendered - When nothing is seen -> no fog; only see the background color. -To have fog look correct, set the background to the fog color. 15

set. Fog void Ogre: : Scene. Manager: : set. Fog ( Fog. Mode mode

set. Fog void Ogre: : Scene. Manager: : set. Fog ( Fog. Mode mode = FOG_NONE, const Colour. Value & colour = Colour. Value: : White, Real exp. Density = 0. 001, linear. Start = 0. 0, linear. End = 1. 0 ) 1 st parameter: set the type of fog 2 nd parameter: set the color of the fog 3 rd parameter: fog density (not used in linear fog) 4 th , 5 th parameters: specify the range where the fog gets thicker. 16

Steps to create fog (1) set the background color (2) create the fog (3)

Steps to create fog (1) set the background color (2) create the fog (3) If necessary, use the get. Num. Viewports member function to get the number of viewports and iterate through them Colour. Value fade. Colour(0. 9, 0. 9); m. Window ->get. Viewport(0) ->set. Background. Colour(fade. Colour); 17

Types of fog Two types of fog (1) Linear fog (2) Exponential fog To

Types of fog Two types of fog (1) Linear fog (2) Exponential fog To create a linear fog: m. Scene. Mgr->set. Fog(FOG_LINEAR, fade. Colour, 0. 0, 500); (Remember, this code must appear before the set. World. Geometry call) 18

Exponential Fog Two types of exponential fog: (1) FOG_EXP (2) FOG_EXP 2: IE fog

Exponential Fog Two types of exponential fog: (1) FOG_EXP (2) FOG_EXP 2: IE fog gets much thicker each unit compared to FOG_EXP - set a density for the fog m. Scene. Mgr->set. Fog(FOG_EXP, fade. Colour, 0. 0005); m. Scene. Mgr->set. Fog(FOG_EXP 2, fade. Colour, 0. 0005); -Using Direct. X Renderer, it completely fogged out -calling set. Fog after set. World. Geometry fixes this. -The Open. GL Renderer behaves as documented. 19

Open. GL Fog m. Scene. Mgr->set. Fog( FOG_LINEAR, fade. Colour, 0. 0, 500); m.

Open. GL Fog m. Scene. Mgr->set. Fog( FOG_LINEAR, fade. Colour, 0. 0, 500); m. Scene. Mgr->set. Fog( FOG_EXP, fade. Colour, 0. 0005); m. Scene. Mgr->set. Fog( FOG_LINEAR, fade. Colour, 0. 0, 5000); m. Scene. Mgr->set. Fog( FOG_EXP 2, fade. Colour, 0. 0005); Any problems? There is no fog when there’s no object. (see at the back) 20

Problem when Using Sky. Box and Sky. Dome with Fog - The problem: unnatural

Problem when Using Sky. Box and Sky. Dome with Fog - The problem: unnatural fog - Sky. Domes and Sky. Boxes are cubes - fog works in a spherical manner -Let’s try this: . -Problem one: if the skybox’s setting too small. Colour. Value fade. Colour(0. 9, 0. 9); m. Scene. Mgr->set. Fog(FOG_LINEAR, fade. Colour, 0. 0, 5000); m. Window->get. Viewport(0)->set. Background. Colour(fade. Colour); m. Scene. Mgr->set. World. Geometry("terrain. cfg"); m. Scene. Mgr->set. Sky. Dome(true, "Examples/Cloudy. Sky", 5, 8, 1000); -Problem two: move the camera aroundnotice the blue coming through on the sides, but not in the middle) Question: How to solve the problem ? 21

22

22

Correct settings 23

Correct settings 23

Fog as Darkness - Not use sky at all when you set fog, -

Fog as Darkness - Not use sky at all when you set fog, - set the fog to be thick enough so that the sky cannot be seen. - Set the fog to be very dark Colour. Value fade. Colour(0. 1, 0. 1); m. Window->get. Viewport(0) ->set. Background. Colour( fade. Colour ); m. Scene. Mgr->set. Fog( FOG_LINEAR, fade. Colour, 0. 0, 10, 2000); m. Scene. Mgr->set. World. Geometry( "terrain. cfg“ ); 24

Tutorial Four Frame Listeners and Unbuffered Input -Use Frame. Listeners to do things that

Tutorial Four Frame Listeners and Unbuffered Input -Use Frame. Listeners to do things that require updates every frame -Use Ogre's unbuffered input system 25

Frame. Liseners - Use Frame. Listeners to receive notification before and after a frame

Frame. Liseners - Use Frame. Listeners to receive notification before and after a frame is rendered to the screen. Two functions: bool frame. Started(const Frame. Event& evt) bool frame. Ended(const Frame. Event& evt) 26

Major part of call graph Game. Application: : go() Game. Application: : setup() Root:

Major part of call graph Game. Application: : go() Game. Application: : setup() Root: : start. Rendering() Root: : render. One. Frame() Root: : _fire. Frame. Started() Frame. Listener: : frame. Started(evt) Root: : _fire. Frame. Ended(); Frame. Listener: : frame. Ended(evt) Root: : _update. All. Render. Targets(); 27

Frame. Liseners - An Application may have two or more Frame. Listeners. - Cannot

Frame. Liseners - An Application may have two or more Frame. Listeners. - Cannot determine which Frame. Listener is called first, second, third. . . and so on. - To ensure that Frame. Listeners are called in a certain order -> register only one Frame. Listener and have it call of the objects in the proper order. 28

Example for Constructing a Frame. Lisener Derive a new framelistener from Example. Frame. Listerner:

Example for Constructing a Frame. Lisener Derive a new framelistener from Example. Frame. Listerner: Class Demo. Frame. Listener : public Example. Frame. Listener { public: Demo. Frame. Listener( Render. Window* win, Camera* cam, : Scene. Manager *scene. Mgr) Example. Frame. Listener(win, cam, false) { } bool frame. Started(const Frame. Event &evt) { return Example. Frame. Listener: : frame. Started(evt); } …… } 29

Registering a Frame. Listener - Create an instance of our Demo. Frame. Listener and

Registering a Frame. Listener - Create an instance of our Demo. Frame. Listener and register it with the Root object: In Example. Application: : create. Frame. Listener method, and add this code to it: m. Frame. Listener = new Demo. Frame. Listener( m. Window, m. Camera, m. Scene. Mgr); m. Root->add. Frame. Listener(m. Frame. Listener); - The m. Root and m. Frame. Listener variables are defined in the Example. Application class. 30

Frame. Liseners Root: : add. Frame. Listener: add a Frame. Listener, Root: : remove.

Frame. Liseners Root: : add. Frame. Listener: add a Frame. Listener, Root: : remove. Frame. Listener : remove a Frame. Listener Note: add|remove. Frame. Listener methods only take in a pointer to a Frame. Listener - Frame. Listeners do not have names ->Need to hold a pointer to each Frame. Listener 31

32

32

Unbuffered input -“Unbuffered" mouse and key input: call methods in frame listener to query

Unbuffered input -“Unbuffered" mouse and key input: call methods in frame listener to query the state of the keyboard and mouse. -A problem: If a key is down, action can be taken on this information. However, what happens in the next frame? Is the same key down and do the same thing again? (1) Keep track of whether or not the mouse was also down the previous frame (2) Define a variable m. Toggle for indicating the state of an action (3) Allow actions to happen after a certain amount of time has elapsed 33

Specifying unbuffered input mode Class Demo. Frame. Listener : public Example. Frame. Listener {

Specifying unbuffered input mode Class Demo. Frame. Listener : public Example. Frame. Listener { public: Demo. Frame. Listener( Render. Window* win, Camera* cam, Scene. Manager *scene. Mgr) : Example. Frame. Listener(win, cam, false) { } …. . } Example. Frame. Listener's constructor: : Example. Frame. Listener(win, cam, false) -3 rd variable: specify whether using buffered key input -4 th variable: specify whether using buffered mouse input 34

Specifying unbuffered input mode m. Keyboard = static_cast<OIS: : Keyboard*> (m. Input. Manager->create. Input.

Specifying unbuffered input mode m. Keyboard = static_cast<OIS: : Keyboard*> (m. Input. Manager->create. Input. Object( OIS: : OISKeyboard, false )); m. Mouse = static_cast<OIS: : Mouse*> (m. Input. Manager->create. Input. Object( OIS: : OISMouse, false )); 35

Open Input System (OSI) - OSI povides three primary classes to retrieve input: (1)

Open Input System (OSI) - OSI povides three primary classes to retrieve input: (1) Keyboard, (2) Mouse, and (3) Joystick. - OSI key codes: OSI: : KC_* (More details: read Key. Code) - To use the Keyboard and Mouse objects. Steps: (1) Capture the current state of the keyboard and mouse. In Demo. Frame. Listener: : frame. Started: m. Mouse->capture(); m. Keyboard->capture(); (2) Implement methods to handle key and mouse events. For example, 36 if(m. Keyboard->is. Key. Down(OIS: : KC_ESCAPE)) return false;

Code: An Example: Control the movement of a camera m. Cam. Node->translate( trans. Vector

Code: An Example: Control the movement of a camera m. Cam. Node->translate( trans. Vector * evt. time. Since. Last. Frame, Node: : TS_LOCAL); Note: the magnitude of the translation should be depended on the amount of time since the last frame. Otherwise, how fast the movement of the camera would be dependent on the framerate of the application. 37

Control the rotation of the camera - use Quaternions for all rotation operations. -

Control the rotation of the camera - use Quaternions for all rotation operations. - use a Quaternion to rotate a vector - apply all of the rotations done to the Scene. Node to the translation vector. 38

Transformation Space - Specify which Transformation Space to use to move the object. -

Transformation Space - Specify which Transformation Space to use to move the object. - TS_PARENT : In parent node - TS_LOCAL : In object node - TS_WORLD: In world coordinate system m. Cam. Node->translate( trans. Vector * evt. time. Since. Last. Frame, Node: : TS_LOCAL); 39

Transformation Space To move a Scene. Node along the direction specified by the orientation

Transformation Space To move a Scene. Node along the direction specified by the orientation Method one: m. Cam. Node->translate( m. Cam. Node->get. Orientation() * trans. Vector * evt. time. Since. Last. Frame, Node: : TS_WORLD); Method Two: m. Cam. Node->translate( trans. Vector * evt. time. Since. Last. Frame, Node: : TS_LOCAL); 40

Tutorial Five: Buffered input - Use OIS's buffered input - Handle keyboard and mouse

Tutorial Five: Buffered input - Use OIS's buffered input - Handle keyboard and mouse events by using Listeners. -For more information about OSI, read Using OIS article. 41

Buffered input - Unbuffered input : every frame the state of OIS: : Keyboard

Buffered input - Unbuffered input : every frame the state of OIS: : Keyboard and OIS: : Mouse instances is queried to see what keys and mouse buttons were being held down. -Buffered input: use listener interfaces to inform the program that events have occurred. - When a key is pressed, a Key. Listener: : key. Pressed event is fired. - When the button is released (no longer being pressed) a Key. Listener: : key. Released event is fired to all registered Key. Listener classes. 42

OSI - OIS's listener system : allow one listener per Keyboard, Mouse, or Joystick

OSI - OIS's listener system : allow one listener per Keyboard, Mouse, or Joystick object. - call the set. Event. Callback function (which we will cover later) multiple times will result in only the last registered listener getting events. - If two or more objects have to get Key, Mouse, or Joystick events, write a message dispatch yourself. - call the Keyboard: : capture and Mouse: : capture in the frame. Started method. (OIS does not use threads (or magic) to determine the keyboard and mouse states. ) 43

The Key. Listener Interface OIS's Key. Listener interface provides two pure virtual functions. (1)

The Key. Listener Interface OIS's Key. Listener interface provides two pure virtual functions. (1) key. Pressed function (which is called every time a key is pressed) (2) key. Released (which is called every time a key is released). The parameter passed to these functions is a Key. Event, which contains the key code of what is being pressed/released. 44

The Mouse. Listener Interface - Mouse. Listener: : mouse. Pressed - Mouse. Listener: :

The Mouse. Listener Interface - Mouse. Listener: : mouse. Pressed - Mouse. Listener: : mouse. Released - Mouse. Listener: : mouse. Moved - Each receives a Mouse. Event object: the current state of the mouse -The Mouse. State (const OIS: : Mouse. Event &arg) object contains (1) the relative X and Y coordinates of the mouse move, i. e. ( arg. state. X. rel, arg. state. Y. rel ) (2) the absolute X and Y coordinates (that is, where exactly on the screen they are). i. e. ( arg. state. X. abs, arg. state. Y. abs ) 45

Registering keyboard callback and mouse callback The OIS m. Mouse and m. Keyboard objects

Registering keyboard callback and mouse callback The OIS m. Mouse and m. Keyboard objects are already obtained in the Example. Frame. Listener constructor. - To register the Demo. Frame. Listener as the listener by calling the set. Event. Callback method on these input objects: m. Mouse->set. Event. Callback(this); m. Keyboard->set. Event. Callback(this); 46

Frame. Listener for buffered input class Demo. Frame. Listener : public Example. Frame. Listener,

Frame. Listener for buffered input class Demo. Frame. Listener : public Example. Frame. Listener, public OIS: : Mouse. Listener, public OIS: : Key. Listener { public: Demo. Frame. Listener( Render. Window* win, Camera* cam, Scene. Manager *scene. Mgr) : Example. Frame. Listener(win, cam, true) { …… in Example. Frame. Listener: : Example. Frame. Liste …… ner } { … …… m. Keyboardbool frame. Started(const Frame. Event &evt) { >set. Event. Callback(this); m. Mouseif(m. Mouse) m. Mouse->capture(); >set. Event. Callback(this); if(m. Keyboard) m. Keyboard->capture(); … return m. Continue; } } 47 } ;

Example for Key Bindings In Demo. Frame. Listener: : key. Pressed : It is

Example for Key Bindings In Demo. Frame. Listener: : key. Pressed : It is called with a Key. Event object when a button of the keyboard is pressed. bool key. Pressed(const OIS: : Key. Event &e) { switch (e. key) { case OIS: : KC_ESCAPE: m. Continue = false; break; default: break; } return m. Continue; } 48

Example for Mouse Bindings - Find the mouse. Pressed function - Access to both

Example for Mouse Bindings - Find the mouse. Pressed function - Access to both a Mouse. Event and a Mouse. Button. ID. - Switch on the Mouse. Button. ID to determine the button that was pressed in mouse. Pressed Mouse key code: OIS: : MB_* 49

Other Input System: SDL - Cross platform windowing/input systems - Support joystick/gamepad input 50

Other Input System: SDL - Cross platform windowing/input systems - Support joystick/gamepad input 50

Tutorial Six CEGUI 51

Tutorial Six CEGUI 51

CEGUI - Use CEGUI (an embedded GUI system) with Ogre. - Add basic CEGUI

CEGUI - Use CEGUI (an embedded GUI system) with Ogre. - Add basic CEGUI functionality -Require two libraries: (1) CEGUIBase_d. lib (2) Ogre. GUIRenderer_d. lib - add them to the input of the linker (debug_mode) - for release mode, remove the _d on them See CEGUI home page for more information.

Introduction to CEGUI - A fully featured GUI library - Can be embedded in

Introduction to CEGUI - A fully featured GUI library - Can be embedded in 3 D applications such as Ogre (it also supports pure Direct. X and Open. GL as well). - Highly customizable -> allow to define the look and feel of the application by changing its skin. - Only a GUI library -> not do its own rendering nor do it hook into any mouse or keyboard events. (1) To render the content of CEGUI - provide a renderer for it (which is the Ogre. GUIRenderer library included in the SDK), (2) To let it receive mouse and keyboard events - manually inject the events into the CEGUI system. (3) Advantage: 53 - have full control over the rendering and the input

Initializing CEGUI -To initialize CEGUI, (1) get a renderer and (2) create a CEGUI

Initializing CEGUI -To initialize CEGUI, (1) get a renderer and (2) create a CEGUI system. In create. Scene: m. Renderer = new CEGUI: : Ogre. CEGUIRenderer( m. Window, Ogre: : RENDER_QUEUE_OVERLAY, false, 3000, m. Scene. Mgr); m. System = new CEGUI: : System(m. Renderer); - Select the skin (to download CEGUI skin from their website): CEGUI: : Scheme. Manager: : get. Singleton(). load. Scheme((CEGUI: : utf 8*)"Taharez. Look. Skin. scheme"); - Set the default mouse cursor image and the default font: m. System->set. Default. Mouse. Cursor( (CEGUI: : utf 8*)"Taharez. Look", (CEGUI: : utf 8*)"Mouse. Arrow"); 54 m. System->set. Default. Font((CEGUI: : utf 8*)"Blue. Highway-

Mouse Cursor Two ways to display a mouse cursor: (1) use CEGUI to display

Mouse Cursor Two ways to display a mouse cursor: (1) use CEGUI to display the mouse cursor (2) create the mouse cursor using Ogre directly To set the default mouse cursor, call Mouse. Cursor: : set. Image 55

Injecting Key Events - CEGUI does not handle input in any way. - It

Injecting Key Events - CEGUI does not handle input in any way. - It does not read mouse movements or keyboard input. -> the user should inject key and mouse events into the system -> both the key. Pressed and key. Released functions should be modified. - Work with CEGUI, - set the mouse and keyboard as buffered mode -> receive the events directly and inject them as they happen. - Both OIS and CEGUI use the same key codes for keyboard input -> not necessary to convert the key 56

key. Pressed - In key. Pressed : CEGUI: : System *sys = CEGUI: :

key. Pressed - In key. Pressed : CEGUI: : System *sys = CEGUI: : System: : get. Singleton. Ptr(); sys->inject. Key. Down(arg. key); // (1): inject down event sys->inject. Char(arg. text); // (2): actual character After getting the system object, Do two things (1) Inject the key down event into CEGUI. (2) Inject the actual character that was pressed. - Injecting the key down will not always bring about the desired result when using a non-English keyboard. - The inject. Char was designed with Unicode support. 57

key. Released - Inject the key up event into the system. - In key.

key. Released - Inject the key up event into the system. - In key. Released: CEGUI: : System: : get. Singleton(). inject. Key. Up(arg. ke y); Note : do not need to inject a character up event, only the key up event is required. 58

Converting and Injecting Mouse Events -Different mouse button codes between OIS and CEGUI. Three

Converting and Injecting Mouse Events -Different mouse button codes between OIS and CEGUI. Three steps: - (1) convert OIS button IDs into CEGUI button IDs - (2) inject mouse button presses into CEGUI - (3) inject mouse movement into CEGUI (1) Convertion function: CEGUI: : Mouse. Button convert. Button(OIS: : Mouse. Button. ID button. ID) { switch (button. ID) { case OIS: : MB_Left: return CEGUI: : Left. Button; case OIS: : MB_Right: return CEGUI: : Right. Button; case OIS: : MB_Middle: return CEGUI: : Middle. Button; default: return CEGUI: : Left. Button; } } (2) Injecting inject mouse events. In mouse. Pressed: CEGUI: : System: : get. Singleton(). 59 inject. Mouse. Button. Down(convert. Button(id));

Injecting Mouse Movement Events (3) injecting mouse motion into CEGUI. In mouse. Moved: CEGUI:

Injecting Mouse Movement Events (3) injecting mouse motion into CEGUI. In mouse. Moved: CEGUI: : System: : get. Singleton(). inject. Mouse. Move(arg. state. X. rel, arg. state. Y. rel); The OIS: : mouse. Moved handler gives those relative movements in the state. X. rel variable and the state. Y. rel variables. After the three steps: CEGUI is fully setup and receiving 60 mouse and keyboard events.

Windows, Sheets, and Widgets (1) In CEGUI, everything that is displayed is a subclass

Windows, Sheets, and Widgets (1) In CEGUI, everything that is displayed is a subclass of the CEGUI: : Window class (2) A window can have any number of children windows. ->This means that when you create a frame to contain multiple buttons, that frame is a Window. -> Can place a button inside another button, (3) Not necessary to create each individual object through code. (4) Create a GUI layout for the application in an editor such as the CEGUI Layout Editor. After placing all of the windows, buttons, and other widgets onto the screen, the editor saves the layout into a text file. - Load the layout into what CEGUI calls a GUI sheet (which is a subclass of CEGUI: : Window). Remark: read CEGUI website for more information. 61

Loading a Sheet (1) The Window. Manager: : load. Window. Layout: load the sheet

Loading a Sheet (1) The Window. Manager: : load. Window. Layout: load the sheet and puts it into a CEGUI: : Window object. (2) call CEGUI: : System: : set. GUISheet to display it. CEGUI: : Window* sheet = CEGUI: : Window. Manager: : get. Singleton(). load. Window. Layout((CEGUI: : utf 8*)"ogregui. layout" ); m. System->set. GUISheet(sheet); - To retrieve this sheet, call System: : get. GUISheet. - To swap the GUI sheet, call System: : set. GUISheet - Have to maintain the sheet pointer(s) 62

Mannually Creating an Object Example, adding a Quit button (1) Create a default CEGUI:

Mannually Creating an Object Example, adding a Quit button (1) Create a default CEGUI: : Window containing all of the widgets. (2) Add code to create. Scene: CEGUI: : Window. Manager *win = CEGUI: : Window. Manager: : get. Singleton. Ptr(); CEGUI: : Window *sheet = win->create. Window( "Default. GUISheet", "CEGUIDemo/Sheet"); - Create a "Default. GUISheet" called "CEGUIDemo/Sheet". - Common (and encouraged) to name the widget in a hierarchical manner such as "Some. App/Main. Menu/Submenu 3/Cancel. Button". (3) Create the Quit button and set its size: CEGUI: : Window *quit = win->create. Window( "Taharez. Look/Button", "CEGUIDemo/Quit. Button"); quit->set. Text("Quit"); quit->set. Size(CEGUI: : UVector 2( 63 CEGUI: : UDim(0. 15, 0), CEGUI: : UDim(0. 05, 0)));

Mannually Creating an Object - CEGUI uses a "unified dimension" system for its sizes

Mannually Creating an Object - CEGUI uses a "unified dimension" system for its sizes and positions. - Create a UDim object to tell it what size it should be. 1 st parameter : the relative size of the object in relation to its parent. 2 nd parameter: the absolute size of the object (in pixels). - only supposed to set one of the two parameters to UDim. - The other parameter must be 0. 15% 5% - Attach the Quit button to the sheet we have created - Set the current GUI sheet for the system to be that sheet: sheet->add. Child. Window(quit); m. System->set. GUISheet(sheet); 64

Handling Events - CEGUI uses a callback mechanism which binds any public function to

Handling Events - CEGUI uses a callback mechanism which binds any public function to be the event handler. For example: register Quit button's click event to exit the program when it is pressed. (1) need a pointer to the Quit button (2) subscribe to the clicked event CEGUI: : Window. Manager *wmgr = CEGUI: : Window. Manager: : get. Singleton. Ptr(); CEGUI: : Window *quit = wmgr->get. Window( (CEGUI: : utf 8*)"CEGUIDemo/Quit. Button"); quit->subscribe. Event( CEGUI: : Push. Button: : Event. Clicked, 65 CEGUI: : Event: : Subscriber(&Demo. Listener: : quit, this));

Handling Events - Every widget in CEGUI has a set of events that it

Handling Events - Every widget in CEGUI has a set of events that it supports, and they all begin with "Event". To subscribe to the event: quit->subscribe. Event( CEGUI: : Push. Button: : Event. Clicked, // (1) CEGUI: : Event: : Subscriber(&Demo. Listener: : quit, this)); // (2) 1 st parameter: the event itself. 2 nd parameter: an Event: : Subscriber object. Remark: Which event and which handler to handle the event? The subsriber answer these two questions. 66

Render to Texture Purpose: Create a render to texture window. - Allow to create

Render to Texture Purpose: Create a render to texture window. - Allow to create a second Viewport which can be rendered directly into a CEGUI widget. Eight Steps: -(1) Setup a scene for us to look at. -(2) Create the Render. Texture. The Render. System object provides the functionality to render to a texture. -(3) Create a texture with the Render. System: : create. Render. Texture function. -(4) create camera -(5) create a viewport using Render. Texture: : add. Viewport -(6) Use render. System: : create. Texture to render the scene onto a texture -(7) Setup CEGUI image set to store the texture in CEGUI system -(8) create Static. Image widget for rendering the texture stored in the image set See http: //www. ogre 3 d. org/wiki/index. php/Basic_Tutorial_7 for more information. 67

References: Terrain, Sky, Fog http: //www. ogre 3 d. org/wiki/index. php/Basic_Tutorial_3 Frame. Listener and

References: Terrain, Sky, Fog http: //www. ogre 3 d. org/wiki/index. php/Basic_Tutorial_3 Frame. Listener and Unbuffered Input http: //www. ogre 3 d. org/wiki/index. php/Basic_Tutorial_4 Buffered Input http: //www. ogre 3 d. org/wiki/index. php/Basic_Tutorial_5 CEGUI http: //www. ogre 3 d. org/wiki/index. php/Basic_Tutorial_7 68