Log System:
The log records all the events, system initialization, status, and performance information of the ogre-based program each time it runs. The output content is stored on the disk file. The default file name is ogre. log. You can also manually display the creation log system, which needs to be implemented before the Root object is created.
// Create an instance of LogManager prior to using LogManager: getSingleton ()
LogManager * logMgr = new LogManager;
Log * log = LogManager: getSingleton (). createLog ("mylog. log", true, true, false );
// Third param is not used since we already created a log in the previous step
Root * root = new Root ("","");
You can use Ogre LogManager to register a Log Listener and redirect log data in any way. This method can be used to shield any log information. Then, a simpler method is provided to achieve the above purpose: Before instantiating the Root, after instantiating a LogManager, The createLog () method is not called.
The following is a code snippet for implementing log information interception:
Class MyLogListener: public LogListener
{
Public:
Void write (const String & name, const String & message,
LogMessageLevel level, bool maskDebug)
{
// Redirect log output here as needed
};
MyLogListener * myListener = new MyLogListener;
// This is the same as calling LogManager: getSingletonPtr () after
// LogManager has first been instanced; the same pointer value is returned
LogManager * logMgr = new LogManager;
LogMgr-> addListener (myListener );
LogMgr-> createLog ("mylog. log", true, false, true );
LogMgr-> setLogDetail (LL_NORMAL );
Root * root = new Root ("", "", "mylog. log ");
Ogre manual Initialization
Int main (int argc, char * argv [])
{
// Tell Root not to load from any plugins or settings file
Root * root = new Root ("","");
// Load feature plugins. Scene managers will register
// Themselves for all scene types they support
Root-> loadPlugin ("Plugin_CgProgramManager ");
Root-> loadPlugin ("Plugin_OctreeSceneManager ");
// Load rendersystem plugin (s). The order is important in that GL
// Shocould be available on platforms, while D3D9 wocould be available
// Only on Windows -- the try/catch will intercept the exception in this
// Case where D3D9 is not available and continue gracefully.
Try {
Root-> loadPlugin ("RenderSystem_GL ");
Root-> loadPlugin ("RenderSystem_Direct3D9 ");
}
Catch (...){}
Try {
// We'll simulate the selection of a rendersystem on an arbirtary basis; normally
// You wowould have your own code to present the user with options and select
// Rendersystem on that basis. Since a GUI is beyond the scope of this example, we'll
// Just assume the user selected OpenGL.
RenderSystemList * rList = root-> getAvailableRenderers ();
RenderSystemList: iterator it = rList-> begin ();
RenderSystem * rSys = 0;
While (it! = RList-> end ()){
RSys = * (it ++ );
If (rSys-> getName (). find ("OpenGL ")){
Root-> setRenderSystem (rSys );
Break;
}
}
// Check to see if a render system was selected; if we reached the end of the list
// Without selecting a render system then none was found.
If (rSys = 0 ){
Delete root;
Std: cerr <"No RenderSystem available, exiting..." <std: endl;
Return-1;
}
// We can initialize Root here if we want. "false" tells Root NOT to create
// A render window for us
Root-> initialise (false );
// Set up the render window with all default params
RenderWindow * window = rSys-> createRenderWindow (
"Manual Ogre Window", // window title
800, // window width, in pixels
600, // window height, in pixels
False, // fullscreen or not
0); // use defaults for all other values
// From here you can set up your camera and viewports as normal
// Get a pointer to the default base scene manager -- sufficient for our purposes
SceneManager * sceneMgr = root-> createSceneManager (ST_GENERIC );
// Create a single camera, and a viewport that takes up the whole window (default behavior)
Camera * camera = sceneMgr-> createCamera ("MainCam ");
Viewport * vp = window-> addViewport (camera );
Vp-> setDimensions (0.0f, 0.0f, 1.0f, 1.0f );
Camera-> setAspectRatio (float) vp-> getActualWidth ()/(float) vp-> getActualHeight ());
Camera-> setFarClipDistance (1000.0f );
Camera-> setNearClipDistance (5.0f );
// Run the manual render loop. Since we are not using a frame listener in this case, we
// Will count to 15 seconds and then instead of exiting, we'll change the render window settings
// And re-initialize it.
Bool renderLoop = true;
Timer * timer = Ogre: PlatformManager: getSingleton (). createTimer ();
Timer-> reset ();
Float s = 0.0f;
While (renderLoop & window-> isActive ()){
RenderLoop = root-> renderOneFrame ();
// Accumulate total elapsed time
S + = (float) timer-> getMilliseconds ()/1000.0f;
// If greater than 15 seconds, break out of the loop
If (s> = 15.0f)
RenderLoop = false;
// We must call the processing Wing system's message pump each frame
// Allow Ogre to process messages
// PlatformManager: getSingleton (). messagePump ();
}
}
Catch (Exception & e ){
Std: cerr <e. getFullDescription () <std: endl;
}
Delete root;
Return 0;
}
View
Generate a ray of light in the world space through a point in the viewport and the origin of the camera.
// X and y are in "normalized" (0.0 to 1.0) screen coordinates
Ray getCameraToViewportRay (Real x, Real y) const;
Create multiple views. The overwrite effect is determined by the Z-order (higher and higher). Each view can have a different background.
// Assume window is a valid pointer to an existing render window, and
// A valid pointer to an existing camera instance
Viewport * vpTop, * vpBottom;
// Second parameter is z-order, remaining params are position and size,
VpBottom = window-> addViewport (camera, 0 );
// Create a smaller viewport on top, in the center, 25% of main vp size
VpTop = window-> addViewport (camera, 1,
0.375f, 0.375f,
0.25, 0.25 );
// Set the background of the top window to blue (the default is black
// Need to set the bottom window explicitly)
VpTop-> setBackgroundColour (ColourValue (0.0f, 0.0f, 1.0f ));
// An alternate way to set the color is to use the manifest constant
// VpTop-> setBackgroundColour (ColourValue: Blue );
In multi-view mode, overlay is rendered in each view by default. You can turn it off. This is also true for Skybox and Shadow.
VpTop-> setOverlaysEnabled (false );
VpTop-> setSkiesEnabled (false );
VpTop-> setShadowsEnabled (true );