[Solved] addBillboardTextSceneNode issue

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
trnrez
Posts: 28
Joined: Wed Dec 27, 2006 5:56 pm
Location: Murfreesboro, TN
Contact:

[Solved] addBillboardTextSceneNode issue

Post by trnrez »

This is probably extremely rudimentary but I can't figure out what the problem is. I would like to add text to the four corners of a landscape so I can do some debugging. The issue I am having is that I can't get the text to show up in the system at all. I tried it in Tutorial 12 and I couldn't get it to work either so I must be doing something silly.

Code: Select all

scene::ISceneNode* text =
          smgr->addBillboardTextSceneNode(env->getBuiltInFont(), L"Hello?", terrain, core::dimension2d<f32>(50.f, 20.f), core::vector3df(0,0,0));
I have messed with the position vector placing it way in the x,y,or z and haven't gotten anything to be placed on screen. Any help would be greatly appreciated.

Complete Source:

Code: Select all

#include <irrlicht.h>
#include <iostream>

using namespace irr;

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif


class MyEventReceiver : public IEventReceiver
{
public:

        MyEventReceiver(scene::ISceneNode* terrain, scene::ISceneNode* skybox, scene::ISceneNode* skydome) :
                Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true)
        {
                Skybox->setVisible(true);
                Skydome->setVisible(false);
        }

        bool OnEvent(const SEvent& event)
        {
                // check if user presses the key 'W' or 'D'
                if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
                {
                        switch (event.KeyInput.Key)
                        {
                        case irr::KEY_KEY_W: // switch wire frame mode
                                Terrain->setMaterialFlag(video::EMF_WIREFRAME,
                                                !Terrain->getMaterial(0).Wireframe);
                                Terrain->setMaterialFlag(video::EMF_POINTCLOUD, false);
                                return true;
                        case irr::KEY_KEY_P: // switch wire frame mode
                                Terrain->setMaterialFlag(video::EMF_POINTCLOUD,
                                                !Terrain->getMaterial(0).PointCloud);
                                Terrain->setMaterialFlag(video::EMF_WIREFRAME, false);
                                return true;
                        case irr::KEY_KEY_D: // toggle detail map
                                Terrain->setMaterialType(
                                        Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ?
                                        video::EMT_DETAIL_MAP : video::EMT_SOLID);
                                return true;
                        case irr::KEY_KEY_S: // toggle skies
                                showBox=!showBox;
                                Skybox->setVisible(showBox);
                                Skydome->setVisible(!showBox);
                                return true;
                        default:
                                break;
                        }
                }

                return false;
        }

private:
        scene::ISceneNode* Terrain;
        scene::ISceneNode* Skybox;
        scene::ISceneNode* Skydome;
        bool showBox;
};

int main()
{
        // let user select driver type

        video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;

        printf("Please select the driver you want for this example:\n"\
                " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n"\
                " (d) Software Renderer\n (e) Burning's Software Renderer\n"\
                " (f) NullDevice\n (otherKey) exit\n\n");

        char i;
        std::cin >> i;

        switch(i)
        {
                case 'a': driverType = video::EDT_DIRECT3D9;break;
                case 'b': driverType = video::EDT_DIRECT3D8;break;
                case 'c': driverType = video::EDT_OPENGL;   break;
                case 'd': driverType = video::EDT_SOFTWARE; break;
                case 'e': driverType = video::EDT_BURNINGSVIDEO;break;
                case 'f': driverType = video::EDT_NULL;     break;
                default: return 1;
        }       

        // create device

        IrrlichtDevice* device = createDevice(driverType,
                        core::dimension2d<s32>(640, 480));

        if (device == 0)
                return 1; // could not create selected driver.

        video::IVideoDriver* driver = device->getVideoDriver();
        scene::ISceneManager* smgr = device->getSceneManager();
        gui::IGUIEnvironment* env = device->getGUIEnvironment();

        driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);

        // add irrlicht logo
        env->addImage(driver->getTexture("../../media/irrlichtlogo2.png"),
                core::position2d<s32>(10,10));

        //set other font
        env->getSkin()->setFont(env->getFont("../../media/fontlucida.png"));

        // add some help text
        env->addStaticText(
                L"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome",
                core::rect<s32>(10,421,250,475), true, true, 0, -1, true);

        // add camera
        scene::ICameraSceneNode* camera =
                smgr->addCameraSceneNodeFPS(0,100.0f,1.2f);

        camera->setPosition(core::vector3df(2700*2,255*2,2600*2));
        camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
        camera->setFarValue(42000.0f);

        // disable mouse cursor
        device->getCursorControl()->setVisible(false);

        // add terrain scene node
        scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
                "../../media/terrain-heightmap.bmp",
                0,                                      // parent node
                -1,                                     // node id
                core::vector3df(0.f, 0.f, 0.f),         // position
                core::vector3df(0.f, 0.f, 0.f),         // rotation
                core::vector3df(40.f, 4.4f, 40.f),      // scale
                video::SColor ( 255, 255, 255, 255 ),   // vertexColor
                5,                                      // maxLOD
                scene::ETPS_17,                         // patchSize
                4                                       // smoothFactor
                );

        terrain->setMaterialFlag(video::EMF_LIGHTING, false);

        terrain->setMaterialTexture(0,
                        driver->getTexture("../../media/terrain-texture.jpg"));
        terrain->setMaterialTexture(1,
                        driver->getTexture("../../media/detailmap3.jpg"));
        
        terrain->setMaterialType(video::EMT_DETAIL_MAP);

        terrain->scaleTexture(1.0f, 20.0f);
        //terrain->setDebugDataVisible ( true );

        // create triangle selector for the terrain     
        scene::ITriangleSelector* selector
                = smgr->createTerrainTriangleSelector(terrain, 0);
        terrain->setTriangleSelector(selector);

        scene::ISceneNode* text =
          smgr->addBillboardTextSceneNode(env->getBuiltInFont(), L"Hello?", terrain, core::dimension2d<f32>(50.f, 20.f), core::vector3df(0,0,0));

        // create collision response animator and attach it to the camera
        scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
                selector, camera, core::vector3df(60,100,60),
                core::vector3df(0,0,0),
                core::vector3df(0,50,0));
        selector->drop();
        camera->addAnimator(anim);
        anim->drop();

        scene::CDynamicMeshBuffer* buffer = new scene::CDynamicMeshBuffer(video::EVT_2TCOORDS, video::EIT_16BIT);
        terrain->getMeshBufferForLOD(*buffer, 0);
        video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer->getVertexBuffer().getData();
        // Work on data or get the IndexBuffer with a similar call.
        buffer->drop(); // When done drop the buffer again.

        // create skybox and skydome
        driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);

        scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode(
                driver->getTexture("../../media/irrlicht2_up.jpg"),
                driver->getTexture("../../media/irrlicht2_dn.jpg"),
                driver->getTexture("../../media/irrlicht2_lf.jpg"),
                driver->getTexture("../../media/irrlicht2_rt.jpg"),
                driver->getTexture("../../media/irrlicht2_ft.jpg"),
                driver->getTexture("../../media/irrlicht2_bk.jpg"));
        scene::ISceneNode* skydome=smgr->addSkyDomeSceneNode(driver->getTexture("../../media/skydome.jpg"),16,8,0.95f,2.0f);

        driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);

        // create event receiver
        MyEventReceiver receiver(terrain, skybox, skydome);
        device->setEventReceiver(&receiver);

                int lastFPS = -1;

        while(device->run())
        if (device->isWindowActive())
        {
                driver->beginScene(true, true, 0 );

                smgr->drawAll();
                env->drawAll();

                driver->endScene();

                // display frames per second in window title
                int fps = driver->getFPS();
                if (lastFPS != fps)
                {
                        core::stringw str = L"Terrain Renderer - Irrlicht Engine [";
                        str += driver->getName();
                        str += "] FPS:";
                        str += fps;
                        // Also print terrain height of current camera position
                        // We can use camera position because terrain is located at coordinate origin
                        str += " Height: ";
                        str += terrain->getHeight(camera->getAbsolutePosition().X,
                                        camera->getAbsolutePosition().Z);

                        device->setWindowCaption(str.c_str());
                        lastFPS = fps;
                }
        }

        device->drop();
        
        return 0;
}
Thanks!
Last edited by trnrez on Thu Jan 15, 2009 10:35 pm, edited 1 time in total.
Jon Jones
Portfolio - needs updating
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The text is probably below the terrain.

Travis
trnrez
Posts: 28
Joined: Wed Dec 27, 2006 5:56 pm
Location: Murfreesboro, TN
Contact:

Post by trnrez »

vitek wrote:The text is probably below the terrain.

Travis
This was my intial thought as well but I have gathered the info about the bounding box it is min(0,0,0) max(9600,1070,9600). I then made the position vector to be (0,1100,0) and I still get nothing rendering.
Jon Jones
Portfolio - needs updating
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

No, the text is indeed rendering. Try the following changes...

Code: Select all

    //camera->setPosition(core::vector3df(2700*2,255*2,2600*2)); 
    camera->setPosition(core::vector3df(0, 0, -100));

    //camera->setTarget(core::vector3df(2397*2,343*2,2700*2)); 
    camera->setTarget(core::vector3df(0, 0, 0)); 

    // ...

    //// create collision response animator and attach it to the camera 
    //scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( 
    //    selector, camera, core::vector3df(60,100,60), 
    //    core::vector3df(0,0,0), 
    //    core::vector3df(0,50,0)); 
    //selector->drop(); 
    //camera->addAnimator(anim); 
    //anim->drop(); 
trnrez
Posts: 28
Joined: Wed Dec 27, 2006 5:56 pm
Location: Murfreesboro, TN
Contact:

Post by trnrez »

vitek you are awesome! Thanks for the help!

Sorry it was a silly problem. All my problems are silly things on my part. :)
Jon Jones
Portfolio - needs updating
Post Reply