Skip to main content
Easy debug text         SetDebugText helper

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...

Copy to clipboard
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

Copy to clipboard
#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

Copy to clipboard
#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:

Copy to clipboard
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:

Copy to clipboard
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:

Copy to clipboard
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:

Copy to clipboard
acDebug::getSingleton().printText();