Table of contents
About acDebug
The following code is a class, I created for use with the OgreDebugPanel overlay that is added into all the demos and sample applications. The reason for creating it was to be able to change the debug text at different points in the code. If you do something like this...
mWindow->setDebugText(mWindow->getDebugText() + "new text");
...you end up with a never ending line of text that would keep growing and slowly kill your application. So I created the following code. Hopefully it might come in useful for someone.
Source Code
acDebug.h
#ifndef acDebug_H #define acDebug_H #pragma once #include <string> using namespace std; #include "Ogre.h" using namespace Ogre; class _acSystemExport acDebug : public Ogre::Singleton<acDebug> { public: acDebug(SceneManager* sm,RenderWindow* window); ~acDebug(); static acDebug& getSingleton(void); static acDebug* getSingletonPtr(void); void addDebugText(String text); void printText(); protected: SceneManager* mSceneMgr; RenderWindow* mWindow; std::list<String>* mDebugLines; }; #endif
acDebug.cpp
#include "acDebug.h" template<> acDebug* Singleton<acDebug>::ms_Singleton = 0; acDebug* acDebug::getSingletonPtr(void) { return ms_Singleton; } acDebug& acDebug::getSingleton(void) { assert( ms_Singleton ); return ( *ms_Singleton ); } acDebug::acDebug(SceneManager* sm,RenderWindow* window){ mSceneMgr = sm; mWindow = window; mDebugLines = new std::list<String>; } acDebug::~acDebug(){ if (mDebugLines) delete mDebugLines; } void acDebug::addDebugText(String text){ mDebugLines->push_back(text); } void acDebug::printText(){ String output; std::list<String>::iterator itr = mDebugLines->begin(); std::list<String>::iterator itrEnd = mDebugLines->end(); for (;itr!=itrEnd;itr++){ output += (*itr) + ", "; } mWindow->setDebugText(output); mDebugLines->clear(); }
Using acDebug
As most people might know to use an ogre singleton you have to first create it like this:
acDebug* debug = new acDebug(sceneMgr,window);
Then anywhere that you include acDebug.h you can use the following code to add another string to the debug text:
acDebug::getSingleton().addDebugText("result count:" + StringConverter::toString(result.size())); acDebug::getSingleton().addDebugText("position:" + StringConverter::toString(mSceneNode.getPosition()));
What this will output is something like this:
result count: 1, position: 2 5 7
Now to actually get the text on the overlay you need to add the following into your main render loop, either your own loop or in the frameEnded:
acDebug::getSingleton().printText();