Head Up Display (HUD)

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
ktyrer496
Posts: 15
Joined: Tue Nov 20, 2007 2:22 pm
Location: Preston, UK

Head Up Display (HUD)

Post by ktyrer496 »

hi,

we are making a game with an airship and we are going to to have a cockpit view but so far usin code in the tutorials i cant get the HUD texture to load along with my irredit level, could you please advise on what i am doing wrong, as i am new to this. i can get my hud texture into the example program.

my code as follows:


IrrlichtDevice* device = createDevice( EDT_DIRECT3D9, dimension2d<s32>(640,480), 32, false, false, false, &receiver );


device->setWindowCaption(L"NAVIGATOR");

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

env->addImage(driver->getTexture("../media/HUD.jpg"),position2d<int>(10,10));

any help will be mcuh appreciated

regards
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You might need to render the scene, probably with some camera instantiated first.
ktyrer496
Posts: 15
Joined: Tue Nov 20, 2007 2:22 pm
Location: Preston, UK

Post by ktyrer496 »

right, not sure how to do this, quite new to this engine, this is my camera code it fixes to my ship which moves through the level, help please:

int lastFPS = -1;


while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(0,200,200,200));
smgr->drawAll();
driver->endScene();

core::vector3df v = Munch->getPosition();
v.Z += 1.0f;
Munch->setPosition(v);



//==========================================CAMERA SYSTEM==========================================

vector3df MunchRot = Munch->getRotation();
vector3df MunchPos = Munch->getPosition();

float DirY = ((MunchRot.Y + 90) * 3.14) / 180; //original 3.14
int CamX = (MunchPos.X - cos(DirY)*45);
int CamY = (MunchPos.Z - sin(DirY)*35);
int CamZ = (MunchPos.Y + 4);

camera = smgr->addCameraSceneNode();
camera->setTarget(MunchPos);
camera->setPosition( vector3df( CamX, CamZ, CamY ) );


//============================================CAM END==============================================



int fps = driver->getFPS();

if (lastFPS != fps)
{
core::stringw str = L"Load Irrlicht File example - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;

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

eventReceiver.startEventProcess();
}


regards
The idea of war is not to die for your country, but to make the other bastard die for his!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You need to draw the gui. That means you need to put a call to env->drawAll() between driver->beginScene() and driver->endScene() [usually after the call to smgr->drawAll()]. This would have been very easy to answer for yourself by looking at one of the tutorials that use the gui.

One other note... You might want to use code tags around source code when you post. They preserve formatting and make your posts much easier to read.

Travis
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

If what vitek said didn't help try setting up your HUD in one of the tutorials and learn from it what you're doing wrong or not doing at all.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
ktyrer496
Posts: 15
Joined: Tue Nov 20, 2007 2:22 pm
Location: Preston, UK

Post by ktyrer496 »

cheers for your help, ill go and try it now, ive tries putting my HUD in the tutorial it works fine, so i used to same code in my game and now it wont display!?!?
The idea of war is not to die for your country, but to make the other bastard die for his!
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

So post the code you use in here so we can check.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

From the code posted above it's just a simple case of doing what vitek said and actually rendering the gui environment.
Image Image Image
ktyrer496
Posts: 15
Joined: Tue Nov 20, 2007 2:22 pm
Location: Preston, UK

Post by ktyrer496 »

Code: Select all

int main()
{

	
eventReceiver.init();

MyEventReceiver receiver;

	IrrlichtDevice* device = createDevice( EDT_DIRECT3D9, dimension2d<s32>(640,480), 32, false, false, false, &receiver );


	device->setWindowCaption(L"NAVIGATOR");

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

	smgr->loadScene("../media/Level(st).irr");


//=====================================================MESHES===================================================

	IAnimatedMesh *MunchMesh = smgr->getMesh("../media/virus4.obj");
	Munch = smgr->addAnimatedMeshSceneNode(MunchMesh, 0, 999, vector3df(0,0,0), vector3df(0,0,0), vector3df(1,1,1), false);
	Munch->setPosition(core::vector3df(0,0,30));
	Munch->setMaterialTexture(0, driver->getTexture("../media/XF_1_HULL.jpg"));
	Munch->setMaterialFlag(video::EMF_LIGHTING, false);

//=============================================MESHES END=======================================================

		eventReceiver.endEventProcess();



//==========================================HUD=================================================================

	env->addImage(driver->getTexture("../media/HUD.jpg"),position2d<int>(10,10));
	env->addImage(driver->getTexture("../media/Health.jpg"),position2d<int>(10,240));
	env->addImage(driver->getTexture("../media/Health.jpg"),position2d<int>(10,250));
	env->addImage(driver->getTexture("../media/Health.jpg"),position2d<int>(10,260));
	env->addImage(driver->getTexture("../media/Health.jpg"),position2d<int>(10,270));
	env->addImage(driver->getTexture("../media/Health.jpg"),position2d<int>(10,280));
	env->addImage(driver->getTexture("../media/Health.jpg"),position2d<int>(10,290));
	env->addImage(driver->getTexture("../media/Health.jpg"),position2d<int>(10,300));

//==========================================HUD END=============================================================

	int lastFPS = -1;


	while(device->run())
	if (device->isWindowActive())
	{
	
	if(receiver.KeyIsDown[KEY_KEY_A]) 
	{
	Xpos ++;
	camera->setPosition(vector3df(Xpos, Ypos, Zpos));
	}

		driver->beginScene(true, true, video::SColor(0,200,200,200));
		smgr->drawAll();
		env->drawAll();
		driver->endScene();

			Zpos = Zpos + 2;
			Munch->setPosition(vector3df(Xpos, Ypos, Zpos));



//==========================================CAMERA SYSTEM==========================================

		vector3df MunchRot = Munch->getRotation();
		vector3df MunchPos = Munch->getPosition();

		float DirY = ((MunchRot.Y + 90) * 3.14) / 180; //original 3.14
		int CamX = (MunchPos.X - cos(DirY)*45);
		int	CamY = (MunchPos.Z - sin(DirY)*35);
		int CamZ = (MunchPos.Y + 5);

		camera = smgr->addCameraSceneNode();
		//camera->setTarget(MunchPos);
		//camera->setPosition( vector3df( CamX, CamZ, CamY ) );


//============================================CAM END==============================================



		int fps = driver->getFPS();

		if (lastFPS != fps)
		{
		  core::stringw str = L"Load Irrlicht File example - Irrlicht Engine [";
		  str += driver->getName();
		  str += "] FPS:";
		  str += fps;

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

			eventReceiver.startEventProcess();
	}

	device->drop();
	
	return 0;
}
thats basically my code for everything, well theres a eventreceiver for movement but that wont effect this

regards
The idea of war is not to die for your country, but to make the other bastard die for his!
Post Reply