This article mainly refer to the page
Http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Ogre+Wiki+Tutorial+Framework
Ogre is a very good open source object-oriented 3D engine, the structure is reasonable and clear, the source code overall (compared to such a large project) is quite neat, logic is almost at a glance. It is worth studying the students of 3D graphics.
As a beginning, we should grasp the main contradiction and have a grasp of the ogre frame. Therefore, discard the side branches, here only the smallest and most refined steps required to run the ogre are discussed here. Here is a record of my learning experience as follows:
Required classes in the Ogre
1 Ogre::root, this class is the origin of everything. Therefore, a ogre program, the first thing to do should be a new root, and save it.
Created by: none, direct new
Role:
The backbone of the ogre, the class in which the rendering process resides. But it doesn't do the exact thing, it just defines the abstract rendering process. Responsible for dispatching Framelistener. It is responsible for loading all plugins. The specific things in Ogre are done by plugins, such as scene management, renderers, and so on. And these are scattered throughout the specific work of the performers, by the Ogre::root to create and organize.
Before you create a condition:
Without any conditions
2 Ogre::renderwindow, this class represents the rendered window
Created by: Ogre::root
How to create:
Ogre::root::initialize (true,..); or Ogre::root::createrenderwindow.
Role:
Do you still have to say? You see a Cai guoqing without it.
Before you create a condition:
Ogre::root::initialize must be called, this function initializes the renderer, and no renderer can create the render window.
3 Ogre::scenemanager, this class represents the scene manager
Created by: Ogre::root
How to create: Ogre::root::createscenemanager
Role:
By organizing a series of Ogre::node, a scene is formed, and a variety of objects are hung in Node, allowing the 3D world to build up.
At the same time, the object in the scene is created by it. As a producer, it differs from root in that root creates a lower class, and it creates a living object class
4 Ogre::camera, this class represents the camera
Created by: Ogre::scenemanager
How to create: Ogre::scenemanager::createcamera
Role:
3D world view matrix and projection matrix, with it, the living 3D world can be turned into screen coordinates in order to display to the screen.
5 Ogre::viewport, viewport, this class represents an area in the game window that is used to display the rendered result
Created by: Ogre::renderwindow
How to create: Ogre::renderwindow::addviewport
Role:
Defines a piece of area on the screen to display the projection and cropping results of a camera. Therefore, a camera should be passed into the creation function.
With these, the Ogre world will run.
But just showing is not enough, we also need to enter for user interaction. So we have to initialize the OIS input device library.
1 Ois::inputmanager The base class of the OIS must be created first, and the specific input device is created to manage
Creator: None, created directly from the Createinputsystem static function of the class. You need to fill in the paramlist,paramlist the most important is the "window" value, this value as long as the window handle (in the case of Windows is hwnd, to Ogre, We can get a value named "Window" by calling the GetCustomAttribute method on Renderwindow, which is size_t to cross-platform resolution) and formatted into a string by%d. This way the OIS is bound to the window.
How to create: Ois::inputmanager::createinputsystem
Role:
The foundation of OIS
2 Ois::keyboard, Ois::mouse and other input
Created by: Ois::inputmanager
How to create: Ois::inputmanager::createinputobject
Role:
The proxy for the specific input object, which, after creation, can be registered with listener to listen for events
After the creation is not finished, must be in the game cycle the appropriate location for event distribution, this step through the appropriate location call input Ois::keyboard or ois::mouse, etc. capture method completed. For Ogre, it is most appropriate to put it in the framerenderingqueued of Framelistener.
Ogre the necessary listener of the program.
Ogre and OIS input devices have their own fixed processes, so we have to implement their listener to insert our processing logic into their fixed logic. The smallest ogre program should have the following listener
1 Ogre::framelistener
Identity: Called at a specific point in the frame loop
Recommended functions for rewriting:
Framerenderingqueued. You can think of this function as a tick in the game, which is called after the CPU sends a drawing instruction to the GPU, where the GPU is running at full speed, and the CPU performs this function in parallel with the CPU and GPU to improve the efficiency of the work. Since this function is called after rendering, the result of the execution is reflected in the next frame, which generally does not affect the game.
2 Ogre::windoweventlistener
Identity: An event that listens to a game window, such as resize move
Recommended functions for rewriting:
Windowresized. This function is called when the window resize, it is necessary to do one thing here, set the clipping area of mouse in Ois.
int width, height, depth; int Left , Top;window-getmetrics (width, height, depth, left, top); Const ois::mousestate& ms = mouse->=height;
WindowClosed. The Ois object is destroyed in this function.
if (window = = W) {if (InputManager) {inputmanager->destroyinputobject (keyboard);inputmanager-> Destroyinputobject (mouse);} Ois::inputmanager::d Estroyinputsystem (InputManager);}
3 Ois::mouselistener Ois::keylistener
These two are nothing to say, write on demand
Finally, summarize the process of the minimum Ogre program:
1 Creating Ogre::root
2 loading plugins with Ogre::root, the scene manager and renderer must be loaded
3 Call Ogre::resourcegroupmanager::getsingleton (). Addresourcelocation to set the resource search path (Ogre Resource management is smart and does not need to specify the path itself, Just give it a search path, and then all scripts and resource files such as material are loaded into the ResourceManager by name (but only a reference is saved to the resource, and there is no actual load), it can be accessed by name.
4 Creating a render window , as we often write here
if (Root->showconfigdialog ()) {root->initialise (false); window = Root->createrenderwindow ("window", 800, 600 , false);} Else{return false;}
This will play a Ogre configuration window, and then save the configuration to a file, the configuration file name is given when the root is created, if not given, will be the default name Ogre.cfg.
You can also start with a root->restoreconfig read the configuration from the configuration file, if True indicates that the read was successful, the next step is not needed.
5 Create scene manager, set scene ambient light by the way
6 Creating a camera
7 Creating Viewports
8 Initializing Ois
9 Call root->startrendering (); Enter the game cycle . This time the game enters this function and will never come out again until the window is destroyed.
Destruction of Ogre
How do I destroy Ogre? Very, very simple, just a word.
Delete root;
All the work has been done in the Ogre::root destructor. It's easy!
The specific code is not affixed, the top of the link is Ogre official, there is everything, and this link should never expire.
Beginning of Ogre: The simplest Ogre program skeleton