Bonjour,

Dans le cadre de mon application, je cherche simplement à afficher un texte (nom d'une mesh)
j'ai suivi un tutoriel mais le texte ne s'affiche pas
voilà mon code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
 
/*
-----------------------------------------------------------------------------
Filename:    OgreApp1.cpp
-----------------------------------------------------------------------------
 
 
This source file is generated by the
   ___                   _              __    __ _                  _ 
  /___\__ _ _ __ ___    /_\  _ __  _ __/ / /\ \ (_)______ _ _ __ __| |
 //  // _` | '__/ _ \  //_\\| '_ \| '_ \ \/  \/ / |_  / _` | '__/ _` |
/ \_// (_| | | |  __/ /  _  \ |_) | |_) \  /\  /| |/ / (_| | | | (_| |
\___/ \__, |_|  \___| \_/ \_/ .__/| .__/ \/  \/ |_/___\__,_|_|  \__,_|
      |___/                 |_|   |_|                                 
      Ogre 1.7.x Application Wizard for VC10 (July 5011)
      http://code.google.com/p/ogreappwizards/
-----------------------------------------------------------------------------
*/
 
#include "OgreApp1.h"
 
 
#include <OgreCamera.h>
#include <OgreEntity.h>
#include <OgreLogManager.h>
#include <OgreRoot.h>
#include <OgreViewport.h>
#include <OgreSceneManager.h>
#include <OgreRenderWindow.h>
#include <OgreConfigFile.h>
 
#include <OISEvents.h>
#include <OISInputManager.h>
#include <OISKeyboard.h>
#include <OISMouse.h>
 
#include <SdkTrays.h>
#include <SdkCameraMan.h> 
 
class ObjectTextDisplay {
 
public:
    ObjectTextDisplay(const Ogre::MovableObject* p, const Ogre::Camera* c) {
        m_p = p;
        m_c = c;
        m_enabled = false;
        m_text = "";
 
        // create an overlay that we can use for later
        m_pOverlay = Ogre::OverlayManager::getSingleton().create("shapeName");
        m_pContainer = static_cast<Ogre::OverlayContainer*>(Ogre::OverlayManager::getSingleton().createOverlayElement(
                  "Panel", "container1"));
 
        m_pOverlay->add2D(m_pContainer);
 
 
 
	 Ogre::FontPtr mFont = Ogre::FontManager::getSingleton().create("BlueHighway-8", "General");
	// Ogre::FontManager::getSingleton().getByName("BlueHighway-8")->load();
      mFont->setType(Ogre::FT_TRUETYPE);
      mFont->setSource("bluehigh.ttf");
      mFont->setTrueTypeSize(26);
      mFont->setTrueTypeResolution(50);
  mFont->load();
 
        m_pText = Ogre::OverlayManager::getSingleton().createOverlayElement("TextArea", "shapeNameText");
        m_pText->setDimensions(10000000000000000000000000.0, 1000000000000000000000000000.0);
        m_pText->setMetricsMode(Ogre::GMM_PIXELS);
        m_pText->setPosition(0, 0);
 
		 m_pText->setParameter("Font Name","ctrl_freak");
       m_pText->setParameter("char_height", "26");
               m_pText->setParameter("horz_align", "center");
        m_pText->setColour(Ogre::ColourValue(1.0, 1.0, 1.0));
 
        m_pContainer->addChild(m_pText);
        m_pOverlay->show();
    }
 
        virtual ~ObjectTextDisplay() {
 
                // overlay cleanup -- Ogre would clean this up at app exit but if your app 
                // tends to create and delete these objects often it's a good idea to do it here.
 
        m_pOverlay->hide();
        Ogre::OverlayManager *overlayManager = Ogre::OverlayManager::getSingletonPtr();
        m_pContainer->removeChild("shapeNameText");
        m_pOverlay->remove2D(m_pContainer);
        overlayManager->destroyOverlayElement(m_pText);
        overlayManager->destroyOverlayElement(m_pContainer);
        overlayManager->destroy(m_pOverlay);
        }
 
    void enable(bool enable) {
        m_enabled = enable;
        if (enable)
            m_pOverlay->show();
        else
            m_pOverlay->hide();
    }
 
    void setText(const Ogre::String& text) {
        m_text = text;
        m_pText->setCaption(m_text);
    }
 
    void update();
 
protected:
    const Ogre::MovableObject* m_p;
    const Ogre::Camera* m_c;
    bool m_enabled;
    Ogre::Overlay* m_pOverlay;
    Ogre::OverlayElement* m_pText;
    Ogre::OverlayContainer* m_pContainer;
    Ogre::String m_text;
	Ogre::Font* font;
};
 
void ObjectTextDisplay::update()  {
    if (!m_enabled)
        return;
 
    // get the projection of the object's AABB into screen space
    const Ogre::AxisAlignedBox& bbox = m_p->getWorldBoundingBox(true);
    Ogre::Matrix4 mat = m_c->getViewMatrix();
 
    const Ogre::Vector3* corners = bbox.getAllCorners();
 
    float min_x = 1.0f, max_x = 0.0f, min_y = 1.0f, max_y = 0.0f;
 
        // expand the screen-space bounding-box so that it completely encloses 
        // the object's AABB
    for (int i=0; i<8; i++) {
        Ogre::Vector3 corner = corners[i];
 
                // multiply the AABB corner vertex by the view matrix to 
                // get a camera-space vertex
        corner = mat * corner;
 
                // make 2D relative/normalized coords from the view-space vertex
                // by dividing out the Z (depth) factor -- this is an approximation
        float x = corner.x / corner.z + 0.5;
        float y = corner.y / corner.z + 0.5;
 
        if (x < min_x) 
            min_x = x;
 
        if (x > max_x) 
            max_x = x;
 
        if (y < min_y) 
            min_y = y;
 
        if (y > max_y) 
            max_y = y;
    }
 
    // we now have relative screen-space coords for the object's bounding box; here
    // we need to center the text above the BB on the top edge. The line that defines
    // this top edge is (min_x, min_y) to (max_x, min_y)
 
    //m_pContainer->setPosition(min_x, min_y);
    m_pContainer->setPosition(1-max_x, min_y);  // Edited by alberts: This code works for me
    m_pContainer->setDimensions(max_x - min_x, 0.1); // 0.1, just "because"
}
 
//-------------------------------------------------------------------------------------
OgreApp1::OgreApp1(void)
{
}
//-------------------------------------------------------------------------------------
OgreApp1::~OgreApp1(void)
{
}
 
//-------------------------------------------------------------------------------------
void OgreApp1::createScene(void)
{
	mSceneMgr->setAmbientLight(Ogre::ColourValue(1, 1, 1));
 
    // Create a light
    Ogre::Light* l = mSceneMgr->createLight("MainLight");
    l->setPosition(50,80,50);
    ogreHead = mSceneMgr->createEntity("Head", "ogrehead.mesh");
 
    headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
    headNode->attachObject(ogreHead);
	headNode->setPosition(0,0,0);
	 text = new ObjectTextDisplay(ogreHead, mCamera);
 
        text->setText("Ogre Head");
		text->enable(true);
		/*while (!mWindow->isClosed()) {
 
                // NOTE: this is Eihort (CVS HEAD, 1.3) specific -- if you are using Dagon or
                // older, you need to do Ogre::PlatformManager::getSingleton().messagePump() instead
        Ogre::WindowEventUtilities::messagePump();
 
                // update the object text position and size
        text->update();
 
        mRoot->renderOneFrame();
    }*/
 
//    delete text;
 
    // Set ambient light
 
 
}
 
 
 
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif
 
#ifdef __cplusplus
extern "C" {
#endif
 
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        // Create application object
        OgreApp1 app;
 
        try {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
#endif
        }
 
        return 0;
    }
 
#ifdef __cplusplus
}
#endif
je n'ai pas des erreurs