Display text on screen in Ogre1.9
-
- Gnoblar
- Posts: 8
- Joined: Tue Nov 18, 2014 1:22 pm
Display text on screen in Ogre1.9
Hey there, I want to be able to display text on the screen, but I have tried both:
http://www.ogre3d.org/tikiwiki/tiki-ind ... ext+Output
and
http://www.ogre3d.org/tikiwiki/tiki-ind ... imple+text
It gives me an error regarding Overlays. e.g.
For the first link:
error: 'OverlayManager' in namespace 'Ogre' does not name a type
error: 'Overlay' in namespace 'Ogre' does not name a type
error: 'OverlayContainer' in namespace 'Ogre' does not name a type
For the second link:
incomplete type 'Ogre::OverlayManager' used in nexted name specifier
invalid use of incomplete type 'class Ogre::OverlayManager'
...
Anyone know how to fix this, or a different way of display text?
I dont need complex text right now - just for debugging as well as displaying the score.
http://www.ogre3d.org/tikiwiki/tiki-ind ... ext+Output
and
http://www.ogre3d.org/tikiwiki/tiki-ind ... imple+text
It gives me an error regarding Overlays. e.g.
For the first link:
error: 'OverlayManager' in namespace 'Ogre' does not name a type
error: 'Overlay' in namespace 'Ogre' does not name a type
error: 'OverlayContainer' in namespace 'Ogre' does not name a type
For the second link:
incomplete type 'Ogre::OverlayManager' used in nexted name specifier
invalid use of incomplete type 'class Ogre::OverlayManager'
...
Anyone know how to fix this, or a different way of display text?
I dont need complex text right now - just for debugging as well as displaying the score.
-
- Kobold
- Posts: 27
- Joined: Mon Jan 26, 2015 8:27 pm
- x 1
Re: Display text on screen in Ogre1.9
At the moment I use OgreBites::Label* mInfoLabel; from one of the tutorials; I think it is very easy to setup (I you use BaseApplication):
------
EDIT: The second code - class OgreText - works fine for me, maybe you lack includes; Try to take all the includes from BaseApplication.h. Overlay includes lie in OgreSDK_***_v1-9-0\include\OGRE\Overlay folder.
I've placed that class in my .h after class TutorialApplication : public BaseApplication and declared OgreText *textItem; after it.
In FrameListener
Code: Select all
void TutorialApplication::createFrameListener(void)
{
BaseApplication::createFrameListener();
mInfoLabel = mTrayMgr->createLabel(OgreBites::TL_TOP, "TInfo", "", 350);
//this code must be only here of in framerendering, error if in createscene
mTrayMgr->moveWidgetToTray(mInfoLabel, OgreBites::TL_TOP, 0);
mInfoLabel->show();
Code: Select all
bool TutorialApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
...
mInfoLabel->setCaption(...);
EDIT: The second code - class OgreText - works fine for me, maybe you lack includes; Try to take all the includes from BaseApplication.h. Overlay includes lie in OgreSDK_***_v1-9-0\include\OGRE\Overlay folder.
I've placed that class in my .h after class TutorialApplication : public BaseApplication and declared OgreText *textItem; after it.
In FrameListener
Code: Select all
textItem= new OgreText;
// Now it is possible to use the Ogre::String as parameter too
textItem->setPos(0.1f,0.1f); // Text position, using relative co-ordinates
textItem->setCol(1.0f,1.0f,1.0f,0.5f);
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Display text on screen in Ogre1.9
AbroMaN124 wrote: error: 'OverlayManager' in namespace 'Ogre' does not name a type
error: 'Overlay' in namespace 'Ogre' does not name a type
error: 'OverlayContainer' in namespace 'Ogre' does not name a type
Code: Select all
#include <OgreOverlayManager.h>
#include <OgreOverlay.h>
#include <OgreOverlayContainer.h>
-
- Gnoblar
- Posts: 8
- Joined: Tue Nov 18, 2014 1:22 pm
Re: Display text on screen in Ogre1.9
I am not using BaseApplication, so I added all the header files in there and managed to get the program to compile without errors. However, now if I run it, it simply crashes the game. I have checked my ogrelog and it stops where I am declaring textItem (which is in my CreateScene function). Any suggestions?hcl14 wrote: ------
EDIT: The second code - class OgreText - works fine for me, maybe you lack includes; Try to take all the includes from BaseApplication.h. Overlay includes lie in OgreSDK_***_v1-9-0\include\OGRE\Overlay folder.
I've placed that class in my .h after class TutorialApplication : public BaseApplication and declared OgreText *textItem; after it.
In FrameListenerCode: Select all
textItem= new OgreText; // Now it is possible to use the Ogre::String as parameter too textItem->setPos(0.1f,0.1f); // Text position, using relative co-ordinates textItem->setCol(1.0f,1.0f,1.0f,0.5f);
-
- Gnoblar
- Posts: 8
- Joined: Tue Nov 18, 2014 1:22 pm
Re: Display text on screen in Ogre1.9
It fixes the errors I was getting before, but now I get this :c6burns wrote:AbroMaN124 wrote: error: 'OverlayManager' in namespace 'Ogre' does not name a type
error: 'Overlay' in namespace 'Ogre' does not name a type
error: 'OverlayContainer' in namespace 'Ogre' does not name a typeAs of 1.9 Overlay is a component, so if you are using the SDK the includes will be in include/OGRE/Overlay and you must link against the OgreOverlay libraryCode: Select all
#include <OgreOverlayManager.h> #include <OgreOverlay.h> #include <OgreOverlayContainer.h>
/home/abroman124/Desktop/osratch/TextRenderer.cpp|4|error: ‘TextRenderer* Ogre::Singleton<TextRenderer>::ms_Singleton’ is not a static member of ‘class Ogre::Singleton<TextRenderer>’|
No idea what to do about it :/
When you said I need to link against the OgreOverlay library, did you mean just put in the #includes, or do I have to explicitly state where the includes are? (I am using the SDK, on linux ubuntu).
-
- Kobold
- Posts: 27
- Joined: Mon Jan 26, 2015 8:27 pm
- x 1
Re: Display text on screen in Ogre1.9
It usually happens when you try to access by pointer some object that still doesn't exist.However, now if I run it, it simply crashes the game.
The second message about non-static member also points that you somehow address it not correctly;
I can't reproduce your error, so let's copy what I have placed in my app:
In your .h file:
You place the code of the class and *after* it declare
Code: Select all
static Ogre::String text;
OgreText *textItem;
Code: Select all
textItem= new OgreText;
textItem->setPos(0.1f,0.1f); // Text position, using relative co-ordinates
textItem->setCol(1.0f,1.0f,1.0f,0.5f); // Text colour (Red, Green, Blue, Alpha)
text = "Hello World!111111111111111111111111111111111111111111"; // Text to be displayed
Code: Select all
textItem->setText(text);
------------------
Edit:
Also try to add to your linker OgreOverlay_d.lib (or OgreOverlay.lib if you're in release mode). It depends on your compiler where are linker options.When you said I need to link against the OgreOverlay library
- jacmoe
- OGRE Retired Moderator
- Posts: 20570
- Joined: Thu Jan 22, 2004 10:13 am
- Location: Denmark
- x 179
- Contact:
Re: Display text on screen in Ogre1.9
'ms_Singleton' was renamed to 'msSingleton' in a recent commit.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
-
- Gnoblar
- Posts: 8
- Joined: Tue Nov 18, 2014 1:22 pm
Re: Display text on screen in Ogre1.9
Ok say I put the relevant code in the .h, .cpp and the setText() in my custom render loop (UpdateLogic(), which runs 60 times per second). I am now getting the following two errors:hcl14 wrote:It usually happens when you try to access by pointer some object that still doesn't exist.However, now if I run it, it simply crashes the game.
The second message about non-static member also points that you somehow address it not correctly;
I can't reproduce your error, so let's copy what I have placed in my app:
In your .h file:
You place the code of the class and *after* it declare
then in your .cpp file, in CreateScene() at the end you writeCode: Select all
static Ogre::String text; OgreText *textItem;
Then in your frameRenderingQueued()Code: Select all
textItem= new OgreText; textItem->setPos(0.1f,0.1f); // Text position, using relative co-ordinates textItem->setCol(1.0f,1.0f,1.0f,0.5f); // Text colour (Red, Green, Blue, Alpha) text = "Hello World!111111111111111111111111111111111111111111"; // Text to be displayed
Try and tell me which errors you get.Code: Select all
textItem->setText(text);
------------------
Edit:Also try to add to your linker OgreOverlay_d.lib (or OgreOverlay.lib if you're in release mode). It depends on your compiler where are linker options.When you said I need to link against the OgreOverlay library
/home/abroman124/Desktop/osratch/OgreText.h|99|error: redefinition of ‘int OgreText::init’|
/home/abroman124/Desktop/osratch/OgreText.h|99|error: ‘int OgreText::init’ previously defined here|
for the last line in OgreText.h which is:
int OgreText::init=0;
only change I have made to the OgreText.h file is adding a bunch of headers that BaseApplication had.
EDIT: This new error happens when including OgreText.h to my .h file
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Display text on screen in Ogre1.9
There's probably no include guard in whatever ghetto code you got from the wiki
-
- Kobold
- Posts: 27
- Joined: Mon Jan 26, 2015 8:27 pm
- x 1
Re: Display text on screen in Ogre1.9
Search your code, you have already defined this variable somewhere; delete the previous definition and leave the one under the class.redefinition of ‘int OgreText::init
PS I usually save the "clean" copy of my program before experimenting with some new feature, because it's sometimes quite hard to destroy all that left from those experiments, so it may cause problems in future.
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Display text on screen in Ogre1.9
See how the previous definition is in the same place as the redefinition ... that's the clue that there aren't two places in the code it is defined, it is just included twice from the same place. If you look:hcl14 wrote:Search your code, you have already defined this variable somewhere; delete the previous definition and leave the one under the class.redefinition of ‘int OgreText::init
http://www.ogre3d.org/tikiwiki/tiki-ind ... imple+text
You see that lo and behold there is an init defined outside the include guard
-
- Kobold
- Posts: 27
- Joined: Mon Jan 26, 2015 8:27 pm
- x 1
Re: Display text on screen in Ogre1.9
Oops, looks like it doesn't bother vc2010. Because I don't have include guards too.You see that lo and behold there is an init defined outside the include guard
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Display text on screen in Ogre1.9
It depends where you include it. If you include somewhere that is included multiple times, it will be a problem. If not then it won't.hcl14 wrote:Oops, looks like it doesn't bother vc2010. Because I don't have include guards too.You see that lo and behold there is an init defined outside the include guard
-
- Kobold
- Posts: 27
- Joined: Mon Jan 26, 2015 8:27 pm
- x 1
Re: Display text on screen in Ogre1.9
Well, that's what I expected. If he has no include guards, he must have got an error with class redefinition.If you include somewhere that is included multiple times
If it's just ::init, then it is somewhere in the code, I think.
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Display text on screen in Ogre1.9
That's what I'm saying ... it's in the code from the wiki that he linked and then I linked. It's not a class redef as the error states. It's a ghetto ass static int outside the header guard. Just move it in the header guard or write some non-ghetto ass code.
-
- Gnoblar
- Posts: 8
- Joined: Tue Nov 18, 2014 1:22 pm
Re: Display text on screen in Ogre1.9
Hey man, I have tried everything I could think of, but with no success. The already defined variable is not in my code but rather in the OgreText.h I got from the wiki. I tried simply removing the definition but then the code complains:hcl14 wrote:Search your code, you have already defined this variable somewhere; delete the previous definition and leave the one under the class.redefinition of ‘int OgreText::init
PS I usually save the "clean" copy of my program before experimenting with some new feature, because it's sometimes quite hard to destroy all that left from those experiments, so it may cause problems in future.
/home/abroman124/Desktop/osratch/OgreText.h|39|error: ‘init’ was not declared in this scope|
/home/abroman124/Desktop/osratch/OgreText.h|48|error: ‘class OgreText’ has no member named ‘init’|
Any help will be much appreciated, I just need some way to display text!
EDIT: Also, regarding your PS, I backup my work onto a SVN repository after implementing new features
-
- Kobold
- Posts: 27
- Joined: Mon Jan 26, 2015 8:27 pm
- x 1
Re: Display text on screen in Ogre1.9
Well, as c6burns has mentioned, there is a little weird code there, it's normal for me, but somehow doesn't work for you.
Lets rewrite this code (it's a workaround, only for debug purposes):
The usage changed a bit:
Now it must work.
Lets rewrite this code (it's a workaround, only for debug purposes):
Code: Select all
using namespace Ogre;
static int init=0;
class OgreText2
{
public:
OgreText2(int& init)
{
olm=OverlayManager::getSingletonPtr();
if(init==0)
{
panel=static_cast<OverlayContainer*>(olm->createOverlayElement("Panel","GUI"));
panel->setMetricsMode(Ogre::GMM_PIXELS);
panel->setPosition(0,0);
panel->setDimensions(1.0f,1.0f);
overlay=olm->create("GUI_OVERLAY");
overlay->add2D(panel);
}
//++(this->init);
init++;
szElement="element_"+StringConverter::toString(init);
overlay=olm->getByName("GUI_OVERLAY");
panel=static_cast<OverlayContainer*>(olm->getOverlayElement("GUI"));
textArea=static_cast<TextAreaOverlayElement*>(olm->createOverlayElement("TextArea",szElement));
panel->addChild(textArea);
overlay->show();
}
~OgreText2()
{
szElement="element_"+StringConverter::toString(init);
olm->destroyOverlayElement(szElement);
//--(this->init);
init--;
if(init==0)
{
olm->destroyOverlayElement("GUI");
olm->destroy("GUI_OVERLAY");
}
}
void setText(char *szString)
{
textArea->setCaption(szString);
textArea->setDimensions(1.0f,1.0f);
textArea->setMetricsMode(Ogre::GMM_RELATIVE);
textArea->setFontName("BlueHighway");
textArea->setCharHeight(0.03f);
}
void setText(String szString) // now You can use Ogre::String as text
{
textArea->setCaption(szString);
textArea->setDimensions(1.0f,1.0f);
textArea->setMetricsMode(Ogre::GMM_RELATIVE);
textArea->setFontName("BlueHighway");
textArea->setCharHeight(0.03f);
}
void setPos(float x,float y)
{
textArea->setPosition(x,y);
}
void setCol(float R,float G,float B,float I)
{
textArea->setColour(Ogre::ColourValue(R,G,B,I));
}
private:
OverlayManager *olm;
OverlayContainer *panel ;
Overlay *overlay;
TextAreaOverlayElement *textArea;
//static int init;
String szElement;
};
static Ogre::String text;
OgreText2 *textItem;
Code: Select all
void TutorialApplication::createFrameListener(void)
//createScene() works too
{
...
textItem= new OgreText2(init);
textItem->setPos(0.1f,0.1f); // Text position, using relative co-ordinates
textItem->setCol(1.0f,1.0f,1.0f,0.5f); // Text colour (Red, Green, Blue, Alpha)
text = "Hello World!111111111111111111111111111111111111111111"; // Text to be displayed
...
}
Code: Select all
bool TutorialApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
...
textItem->setText(text); // Text to be displayed
...
}
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Display text on screen in Ogre1.9
This pretty much beggars belief. It's not "normal" for you, the problem is multiple inclusion and header guards, so you rewrote the code to have no header guards at all. THE PROBLEM IS MULTIPLE INCLUSION (all caps because I explained this before and it didn't take)hcl14 wrote:Well, as c6burns has mentioned, there is a little weird code there, it's normal for me, but somehow doesn't work for you.
I will now wave my magic wand (and by magic I mean C / C++ fundamentals) and fix the wiki code by moving the static int inside the include guard:
http://www.ogre3d.org/tikiwiki/tiki-ind ... imple+text
-
- Kobold
- Posts: 27
- Joined: Mon Jan 26, 2015 8:27 pm
- x 1
Re: Display text on screen in Ogre1.9
Code: Select all
THE PROBLEM IS MULTIPLE INCLUSION
TS insists that "everything is OK". Actually, I can't imagine how this code can be included twice and I didn't want to start a discussion, so I simply renamed the class and moved the variable out. This should work regardless what's going on with previous class.
Plus, you should agree with me that if he will include your code now, he might get either OgreText class redefinition error, or no changes (depends on where is the dublicate - up/below - and does it have include guards or not).
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Display text on screen in Ogre1.9
I feel like that's simply a limit of your imagination. Imagine two headers both including the same .h and both of those are included in the current translation unit. This is the reason include guards exist.hcl14 wrote:I can't imagine how this code can be included twice
What the ... I don't even ...hcl14 wrote:... now, he might get either OgreText class redefinition error, or no changes (depends on where is the dublicate - up/below - and does it have include guards or not).
I feel like you haven't understood the problem this entire time, and still don't. This is the second time you mention class redefinition (which has never been the issue) ... do you understand what the purpose of an include guard is? How can you get a class redefinition when the class definition is inside an include guard? The problem was multiple definitions of int OgreText::init *because it was outside the include guard and being multiple included*. Move it inside the include guard (which I did now on the wiki). The end.
Want to understand how to replicate the issue?
Code: Select all
#include "HeaderWithShitNotIncludeGuarded.h"
#include "HeaderWithShitNotIncludeGuarded.h"
-
- Kobold
- Posts: 27
- Joined: Mon Jan 26, 2015 8:27 pm
- x 1
Re: Display text on screen in Ogre1.9
Well, may be you're right and I didn't understand.
I was thinking about possible problems like:
As long as I haven't used anything except vc2010 and was unsure that there can be multiple includes, I also thought that may be (theoretically) there can be something with the line
static int A::i =0;
I was thinking about possible problems like:
Code: Select all
#ifndef ***
#define ***
class A{
};
#endif
class A{ // error C2011: 'OgreText2' : 'class' type redefinition
};
Code: Select all
#ifndef ***
#define ***
class A{
};
#endif
static int A::i =0;
#ifndef ***
#define ***
class A{
};
static int A::i =0;
#endif
// no changes
Code: Select all
#ifndef ***
#define ***
class A{
};
static int A::i =0;
#endif
static int A::i =0; //error - already defined
static int A::i =0;
- c6burns
- Beholder
- Posts: 1512
- Joined: Fri Feb 22, 2013 4:44 am
- Location: Deep behind enemy lines
- x 138
Re: Display text on screen in Ogre1.9
The first definition in the middle block above is EXACTLY it ... imagine including it twice. Compiler will say there are multiple definitions for A::i and the previous one is in the same place as the new one (same file, same line number).
The fix is to change it exactly how you did in the second definition of the middle block. Multiple includes will not generate an error because the preprocessor will skip the definition of A::i on subsequent includes.
The fix is to change it exactly how you did in the second definition of the middle block. Multiple includes will not generate an error because the preprocessor will skip the definition of A::i on subsequent includes.
-
- Kobold
- Posts: 27
- Joined: Mon Jan 26, 2015 8:27 pm
- x 1
Re: Display text on screen in Ogre1.9
I understand, but I thought about the problem what to do if there is already a wrong code above, just as in second block.
As long as TS gets an error, he has it included twice somewhere and all that I wanted to say was that adding the corrected code with the same include guards will change nothing, without them - cause "'class' type redefinition" (block 1) error. Am I right?
As long as TS gets an error, he has it included twice somewhere and all that I wanted to say was that adding the corrected code with the same include guards will change nothing, without them - cause "'class' type redefinition" (block 1) error. Am I right?