Page 1 of 1

Head Up Display (HUD)

Posted: Sat Jan 26, 2008 11:37 pm
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

Posted: Sun Jan 27, 2008 12:17 am
by hybrid
You might need to render the scene, probably with some camera instantiated first.

Posted: Sun Jan 27, 2008 12:42 am
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

Posted: Sun Jan 27, 2008 2:43 am
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

Posted: Sun Jan 27, 2008 1:48 pm
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.

Posted: Sun Jan 27, 2008 2:06 pm
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!?!?

Posted: Sun Jan 27, 2008 2:16 pm
by MasterGod
So post the code you use in here so we can check.

Posted: Sun Jan 27, 2008 3:17 pm
by JP
From the code posted above it's just a simple case of doing what vitek said and actually rendering the gui environment.

Posted: Sun Jan 27, 2008 8:02 pm
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