Setting up a GUI (Please Read Before Flaming)

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
Obsidian
Posts: 17
Joined: Fri Feb 17, 2006 10:42 pm

Setting up a GUI (Please Read Before Flaming)

Post by Obsidian »

First Off, i'd like to introduce myself, i've posted here once as a guest, and i LOVE this engine so far. So to everyone, hello. Now onto my question.

Ok, i started writting a game and i started by using the "collision" example. How do i create a GUI that will start before the collision part does. Please don't just say "read the user interface tutorial" i read that, and it shows how to create a GUI, but it doesnt show you how to setup the GUI and then lead into your game.


While i'm on this subject (and to keep me from posting again), how do you set an image as a background for the GUI window (so you dont use the default one)


Thanks For Any Help
Obs
Legality is a horrible barometer for morality.
iam13013
Posts: 31
Joined: Sun Dec 04, 2005 11:06 pm

Post by iam13013 »

I'm not sure if this is exactly what you want, but this is the way I tackled that particular problem.

I have an int called gameState. Each state means a different thing, for example:
1 = Main Menu
2 = Play Game
3 = Pause Menu
4 = etc, etc, etc...

My main loop is setup like this:

Code: Select all

while(device->run() && driver)
	if (device->isWindowActive())
	{
		switch(gameState)
		{
		case 1:
		driver->beginScene(true, true, SColor(0,150,150,150));

		guienv->drawAll();
	
		driver->endScene();
		break;

		case 2:
		driver->beginScene(true, true, SColor(0,0,128,128));
		
		smgr->drawAll();

		driver->endScene();
		break;
		};
	}
Simply use buttons or whatever to change the gamestate variable to access different areas.

If you need to use GUI elements in the main part of your game, make seperate GUI environments for, say.. the main menu, the pause menu, gui elements used during the game etc...

Hope this helps...
Guest

Post by Guest »

so how do you set case 1 to the init?
Obsidian
Posts: 17
Joined: Fri Feb 17, 2006 10:42 pm

Post by Obsidian »

yea i'm going to need a little bit more help with this. i've been playing with it for a while and i havent really made any progress. Is there a (working) source code out there that i can go look at for an example? I do so much better that way.
Legality is a horrible barometer for morality.
Andreas
Posts: 166
Joined: Sun Oct 31, 2004 7:15 am
Location: Münster / Germany
Contact:

Post by Andreas »

You could have a look at the tech demo in irrlicht/examples/Demo

That shows how to first display a main menu and then switch to "game mode".
Maybe that is what you're searching for...
Obsidian
Posts: 17
Joined: Fri Feb 17, 2006 10:42 pm

Post by Obsidian »

Maybe it's me. Maybe i'm just stupid (which is probably the case). When i run demo... it starts with a very short loading screen, and then it does a camera fly around thing... and then it drops me into a quake level. No GUI. I can see wher e the code is, and i can almost grasp the general idea. But if i cant see a code that actually works it doesnt end up helping me too much. :(
Legality is a horrible barometer for morality.
jam
Posts: 409
Joined: Fri Nov 04, 2005 3:52 am

Post by jam »

You might try and take a peek at Irrwizard or ICE. These frameworks have code that might point you in the right direction.

You can find both on this forum or you can go to the irrlicht wiki and download them.
Andreas
Posts: 166
Joined: Sun Oct 31, 2004 7:15 am
Location: Münster / Germany
Contact:

Post by Andreas »

Perhaps it helps if i show you what i've done. This is not efficient or elegant code, it just works for
me and is very similar to iam13013's code (except there are only two gamestates). :)

I have a Client.cpp, where initializations take place and the while loop is:

Code: Select all

...
int main(int argc, char *argv[]) {
...
bool ingame = false;
...
IrrlichtDevice *device = createDevice(EDT_OPENGL, ...);
MenuHandler menuHandler(device, &ingame);
GameHandler gamehandler(device, &ingame);
    device->setEventReceiver(&menuHandler);
...
while(device->run()) {
device->getVideoDriver()->beginScene(true, true, SColor(0,10,10,30));
    // If the player is in a game:
    if (ingame) {
        // this shouldn't be necessary every frame...
        device->setEventReceiver(&gameHandler);
        // update the game state
        gamehandler.updateGameState();
    }
    // If the player is in the main menu:
    else {
        device->setEventReceiver(&menuHandler);
        // draw the gui elements
        menuHandler.updateMenuState();
    }
    device->getVideoDriver()->endScene();
}
...

MenuHandler and GameHandler are derived from IEventReceiver (Tutorial 4). They get a handle to the ingame
variable. If the player clicks on the "Join Game" Button in the main menu, "ingame" is set to true and the
gameHandler is the new event receiver (All GUI Elements are made invisible). If the player presses ESC while
in a game, "ingame" is set to false and the player is in the main menu again (before, all temporary game data is erased:
level meshes, player mesh, etc.).
But i guess that's not an elegant/efficient/nice way to do it! If you have enough time, looking at
IrrWizard or ICE is probably the better idea...

I hope it helps nonetheless. :)
andreas
kburkhart84
Posts: 277
Joined: Thu Dec 15, 2005 6:11 pm

Post by kburkhart84 »

All of the Irrlicht scenenodes can get deleted with one function call(I can't remember what it is.) Why don't you have three functions, one for initialization, one for menu, one for game. In Init function, you set up the Irrlicht engine, create the window, stuff like that. Then you run the menu function, which at the beginning, attaches the scene nodes for the GUI stuff, then goes into the rendering loop where you detect what the user is selecting on the menu. If the user selects "Play" on the menu, you call the function PlayGame(), where you delete all the nodes and load all the scenenodes for the game. When you are done with the game, you delete the nodes again and reload the menu nodes, at which point you return to the menu. If you want, you can keep the nodes in memory, and just attach them when you need them. You can also detach the nodes as needed instead of calling the deleteall function, but it might be easier that way.
Obsidian
Posts: 17
Joined: Fri Feb 17, 2006 10:42 pm

Post by Obsidian »

eh. i tried using the IrrWizard. I only ever got errors with the skeletons. So i guess i'll just keep working with it until i get it figured out. thanks guys
Legality is a horrible barometer for morality.
Post Reply