I just started using irrlicht a couple weeks ago and have been working through tutorials learning all the bits and pieces. I'm having a problem that I'm sure is simple and hope someone can clear it up for me, because it's making me insane .
I'm using irrlicht 1.5.1 on Windows XP with Code::Blocks, and OpenGL. Nothing special.
Tutorial 9 (the mesh viewer) illustrates a bunch of GUI features I want to incorporate, but I can't get any of them to work in my application.
At the moment, all I'm trying to do is display some text on top of my rendered scene. In the mesh viewer, if you press F1, the camera position and target are displayed in the upper left corner of the rendered scene. This is exactly what I'm trying to do. I've copied the relevant bits into my application, compile and and run it, but no text appears. I even tried copying the code to build the toolbox, and same thing. It compiles cleanly and displays my test scene fine, but no toolbox.
Please tell me what I'm missing.
Here's the code:
Code: Select all
#include <irrlicht.h>
#include "MCamera.h"
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
enum
{
mainCameraID = 1000,
GUI_ID_cameraStatus
};
// Define some global variables
bool keys[irr::KEY_KEY_CODES_COUNT];
IrrlichtDevice *irrDevice;
IVideoDriver* irrDriver;
ISceneManager* smgr;
ISceneNode* cube;
ISceneNode* sphere;
ISceneNode* skyBox;
IAnimatedMesh* meshShip;
IMeshSceneNode* nodeShip;
// ICameraSceneNode* mainCamera;
MCameraFPS* mainCamera;
IGUIEnvironment* Gui;
IGUIStaticText* cameraStatus;
// This is the movement speed in units per second.
const f32 MOVEMENT_SPEED = 10.f;
class MyEventReceiver : public IEventReceiver {
public:
virtual bool OnEvent(const SEvent& event) {
if(event.EventType == irr::EET_KEY_INPUT_EVENT){
keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
return false;
}
};
void HandleInput(f32);
int main(int argc, char** argv)
{
MyEventReceiver rv;
core::stringw strTemp, strTemp2;
irrDevice = createDevice(EDT_OPENGL);
irrDevice->setResizeAble(true);
irrDriver = irrDevice->getVideoDriver();
smgr = irrDevice->getSceneManager();
irrDevice->setEventReceiver(&rv);
// Get GUI environment for adding status boxes and controls
Gui = irrDevice->getGUIEnvironment();
IGUISkin* skin = Gui->getSkin();
IGUIFont* font = Gui->getFont("../../media/fonthaettenschweiler.bmp");
if (font) {
skin->setFont(font);
}
else {
skin->setFont(Gui->getBuiltInFont(), EGDF_TOOLTIP);
}
rect<s32> cRect = rect<s32>(100,100,220,40);
cameraStatus = Gui->addStaticText(L"Camera:", cRect,
true, // Border?
false, // wordwrap
0, // parent
-1, // id
true); // Fill background
// Initialize key state
for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;
/* Add some stuff to the scene */
cube = smgr->addCubeSceneNode();
cube->setPosition(vector3df(-100,0,15)); // vector3df(X,Y,Z)
cube->setScale(vector3df(1,1,1));
cube->setMaterialTexture(0, irrDriver->getTexture("res/img/ALUM_8L4.JPG"));
cube->setMaterialFlag(video::EMF_LIGHTING, false);
sphere = smgr->addSphereSceneNode();
sphere->setPosition(vector3df(10,20,30));
sphere->setScale(vector3df(10,10,10));
sphere->setMaterialTexture(0, irrDriver->getTexture("res/img/moonmap1k.jpg"));
sphere->setMaterialFlag(video::EMF_LIGHTING, false);
ISceneNodeAnimator* sphereAnimator = smgr->createRotationAnimator(vector3df(0,0.01667,0));
if(sphereAnimator) {
sphere->addAnimator(sphereAnimator);
sphereAnimator->drop();
}
// mainCamera = smgr->addCameraSceneNodeFPS(0, 100, .5, -1, 0, 0, false, 0);
// mainCamera = smgr->addCameraSceneNode(0, vector3df(0,0,0),cube->getPosition(),-1);
// mainCamera->bindTargetAndRotation(true); // FPS style camera
mainCamera = new MCameraFPS(smgr);
skyBox = smgr->addSkyBoxSceneNode(
irrDriver->getTexture("res/img/sky23.jpg"), //top
irrDriver->getTexture("res/img/moonmap1k.jpg"), // bottom
irrDriver->getTexture("res/img/stars4.bmp"), // left
irrDriver->getTexture("res/img/sun.jpg"), // right
irrDriver->getTexture("res/img/alum_8l4.jpg"), // front
irrDriver->getTexture("res/img/alum_8L4.jpg") // back
);
/*
We have done everything, so lets draw it. We also write the current
frames per second and the name of the driver to the caption of the
window.
*/
int lastFPS = -1;
cameraStatus = Gui->addStaticText(L"Camera:", rect<s32>(20,20,220,40), true,false,0,-1,true);
/* cameraStatus->setVisible(true); // Tried adding this but it didn't help */
// In order to do framerate independent movement, we have to know
// how long it was since the last frame
u32 then = irrDevice->getTimer()->getTime();
// add a tabcontrol
while(irrDevice && irrDevice->run()) {
// Work out a frame delta time.
const u32 now = irrDevice->getTimer()->getTime();
const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
then = now;
HandleInput(frameDeltaTime);
// Update the camera status text
vector3df vTemp = mainCamera->getPosition();
strTemp = L"Camera: Pos: ";
strTemp += vTemp.X;
strTemp += L",";
strTemp += vTemp.Y;
strTemp += L",";
strTemp += vTemp.Z;
cameraStatus->setText(strTemp.c_str());
// Save this to add to window caption while I debug the problem with this
// stupid control not being visible
strTemp2 = strTemp;
irrDriver->beginScene(true, true, video::SColor(255,0,0,255));
smgr->drawAll();
irrDriver->endScene();
int fps = irrDriver->getFPS();
if (lastFPS != fps)
{
strTemp = L"Irrlicht Engine [";
strTemp += irrDevice->getVersion();
strTemp += L"] fps: ";
strTemp += fps;
if (Gui) { strTemp += " Gui "; } else { strTemp += " noGui "; }
strTemp += strTemp2;
irrDevice->setWindowCaption(strTemp.c_str());
lastFPS = fps;
}
}
irrDevice->drop();
return 0;
}
Thanks in advance.
Steve