Analysis of demo_compositor examples

Source: Internet
Author: User
Tags example of manual
By studying this example, we initially learned how to view a large program. In addition, I learned some usage of the cegui list box in ogre and how to add synthesizer content.
The core method in this example is to use the compositormanager method addcompositor and setcompositorenabled to add scripts.

The main classes used are compositordemo, compositordemo_framelistener, itemselectorviewmanager, and itemselectorinterface.
The compositordemo class implements the framework architecture and creates scenarios.
Compositordemo_framelistener implements the changed content of each frame and initializes the cegui interface, such as adding list options.
Itemselectorviewmanager is used to control the addition of list options and add an event processing function for each option.
Itemselectorinterface is the interface between the frame listener and itemselectorviewmanager. It facilitates enabling and disabling some synthesizer functions in the option processing function set by itemselectorviewmanager.

1. You can load the cegui interface with two codes.
Mguirenderer = new cegui: ogreceguirenderer (mwindow, ogre: render_queue_overlay, false, 3000, mscenemgr );
Mguisystem = new cegui: System (mguirenderer, (cegui: resourceprovider *) 0, (cegui: xmlparser *) 0,
(Cegui: scriptmodule *) 0, (cegui: utf8 *) "compositordemocegui. config ");

Use the compositordemocegui. config file to configure scheme, layout, and defaultfont in XML format.
Layout is the component arrangement, including the component name.

The following code sets the default mouse Style
Cegui: System: getsingleton (). setdefadefamousecursor ("taharezlook", "mousearrow ");

2. ogreceguirenderer. H is the header file of Some APIs of cegui packaged by ogre.
The constructor can directly create the cegui Renderer.
Ogreceguirenderer (Ogre: renderwindow * window,
Ogre: uint8 queue_id,
Bool post_queue,
Uint max_quads,
Ogre: scenemanager * scene_manager );
Parameters:
Window: pointer to ogre: renderwindow object
Queue_id: used to specify the order of rendering results in ogre
Post_queue: True indicates rendering after the queue queue_id is rendered, and false indicates
Max_quads: No, set to 0
Scene_manager: pointing to ogre: scenemanager object

3. Ogre: movableobject: setdefavisvisibilityflags (0x00000001 );
Set visible labels for all movable objects.
4. tudorhouse. Mesh: Housing background Mesh
5. Three Important functions used by createscene: createtextures, connecteventhandlers, createeffects
Createeffects can be used to view examples of synthesizer writing in code.
Createtextures is an example of manual texture creation.
Connecteventhandlers is the code for adding an event processing function to the cegui component.
Createtextures
Create a manual texture halftonevolume
Obtain the pixel hardware cache of the texture.
Lock the hardware Cache
Get the current locked area
Obtain data pointers by region
Obtain the width and depth of the region.
Set texture data. This seems to be a cube texture. The texture data of one part is 0xff, and the other part is 0x00.
Create a manual texture dithertex with the size of the view. This is a 2D texture.
The manual texture data is a random value.
Connecteventhandlers ()
Customize the exitdemobtn button and click the processing function compositordemo: handlequit.
Handlequit
Call the queueendrendering () function of the root node to exit the program.

Createeffects (void) // creates two synthesizer motion blur and heat vision
Creates a synthesizer "motion blur" and the resource is the default Resource Group.
Synthesizer Technology
Texture definition scene
Set the definition, and add pf_r8g8b8 to the format list.
Texture definition sum
Set the definition, and add pf_r8g8b8 to the format list.
Texture definition temp
Set the definition, and add pf_r8g8b8 to the format list.
Create synthesizer target path
Set the input mode to im_previous.
Output name: Scene
Create synthesizer target path
Set the input mode to im_previous.
Output name: Sum
The setonlyinitial function is set to true.
Create synthesizer target path
Set the input mode to im_none.
The output name is temp.
This target path is created again
Type: pt_renderquad
Material: ogre/compositor/combine
Set the input to "scene" and "sum"
Create synthesizer target path
Set the input mode to im_none.
Output name: Sum
This target path is created again
Type: pt_renderquad
Material: ogre/compositor/copyback
Set input to "Temp"
Create synthesizer target path
Set the input mode to im_none.
This target path is created again
Type: pt_renderquad
Material: ogre/compositor/motionblur
Set the input to "sum"

Create a synthesizer "heat vision"
Synthesizer Technology
Texture definition scene
Set the width and height to 256, and add pf_r8g8b8 to the format list.
Texture definition temp
Set the width and height to 256, and add pf_r8g8b8 to the format list.
Create synthesizer target path
Set the input mode to im_previous.
Output name: Scene
Create synthesizer target path
Set the input mode to im_none.
The output name is temp.
Create a path
Set the type to pt_renderquad.
Set tag no. 0 xdeadbabe
Set material to Fury/heatvision/lighttoheat
Set the input to "scene"
Create synthesizer target path
Set the input mode to im_none.
Create a path
Set the type to pt_renderquad.
Set material to Fury/heatvision/blur
Set input to "Temp"

6. compositordemo_framelistener class
The initdebugrttwindow function is used to add events and image sets to The ListBox of the cegui window.
Connecteventhandlers adds event processing functions to the cegui window. These event processing functions can also affect some variables used by the Ogre frame listener.
Registercompositors Function
Get the view of the current rendering window
Create an itemselectorviewmanager object
Set the interactive interface (itemselectorinterface derived class, current object)
Create a compositormanager: resourcemapiterator object
Traverse this iterator
Get the next Resource
Obtain the Resource Name.
Determines whether ogre/scene. If yes, the next loop
Add an option to the list box.
The HDR synthesizer must be at the first position.
Call the addcompositor function of the synthesizer manager to add a synthesizer.
All synthesizer invalid at initial time
Whether the synthesizer name is heat vision. If yes, add a listener.
If the synthesizer name is HDR, add the listener and call the notifyviewportsize and notifycompositor functions of the listener.
Whether the synthesizer name is Gaussian blur. If yes, add the listener and call the notifyviewportsize of the listener.


7. To receive events, cegui must call the inject * function. Therefore, all mouse and key functions must use inject to register information with cegui.
Here, the mouse and buttons use the cegui processing function to update the variables used by the frame listener.

8. In handle * series Functions
When the mouse moves, it determines the status of the left and right keys, and moves or rotates according to the status. Note that the mouse can be hidden.
When the mouse pops up, the mouse is displayed and the status is updated.
When you press the mouse, pay attention to whether the previous position is changed. When you move the mouse, the mouse position remains unchanged.

9. itemselectorviewmanager Class Analysis
Constructor
Obtain the cegui window from cegui Based on the parent window name
Create a scroll panel named taharezlook/scrollabgateane and named mainscrollpane
Scroll panel horizontal alignment cegui: ha_centre
SET SIZE
The scroll panel is added to the parent window.
Set the position of the panel (relative to the parent window)

Additemselector Function
Add a struct itemselector object (struct created in this class)
Create a cegui: checkbox object
Set ID, size, attribute, subscribe event handler, set location

Handlecheckstatechanged Function
Used to process selection box changes
If an interface object interacting with ogre exists (itemselectorinterface derived class)
Get the checkbox
Call the function of the corresponding interface of the Ogre listener to start or disable the synthesizer of this option in the listener class object.
Set the normaltextcolour attribute of the checkbox

Setitemselectorcontroller
Set the interface object for interacting with ogre (itemselectorinterface derived class)

Struct itemselector
A struct that stores option information.
Its member checkboxwidget is a cegui: checkbox pointer.

9. itemselectorinterface class
This is a pure virtual function. itemselectorinterface has only one constructor and itemstatechanged (virtual function)
In the derived class of this example;
Call the setcompositorenabled function of compositormanager according to the parameter to enable the synthesizer.

10. The synthesizer is written in a script and the file suffix is compositor. For more information, see the script file.
Use the compositormanager function addcompositor and setcompositorenabled to add scripts.
In addition, the createeffects function provides a method to manually create a synthesizer.

11. Now let's look at the details of the synthesizer listener.
The base class is Ogre: compositorinstance: listener.
The base class has two main functions: yymaterialsetup and notifymaterialrender.
In the yymaterialsetup Function
Get the Ogre: gpuprogramparameterssharedptr variable.
This function is activated when compiling the material contained in the rendering target operation.

In notifymaterialrender
Call the etnamedconstant function to set the fragment parameters.
This function is activated before the rendering target operation.

12. In this example, the synthesizer instance listener also has the yyviewportsize and notifycompositor functions.
After the listener is added to the instance, add the two functions for some basic parameter settings.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.