Understanding Hello World (questions comented)

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
namespace
Posts: 7
Joined: Thu Jul 09, 2009 6:30 pm

Understanding Hello World (questions comented)

Post by namespace »

I'm commenting my questions, I'm asking about what he did, not what he's about to do, I know you normally comment the other way, but these aren't comments.


#include <irrlicht.h>

using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif

// I know what he did here, and recognize what it did, I'm just not familiar with programmer comments, I'll just learn it eventualy I suppose.


int main()
{
IrrlichtDevice *device =
#ifdef _IRR_OSX_PLATFORM_
createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
false, false, false, 0);
#else
createDevice( video::EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
false, false, false, 0);
#endif
if (!device)
return 1;

device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

//There seem to be allot of commands just thrown at you, so, trying to understand, device is the irrlicht device (the highest class?) and it has a sub command to set the window caption?

IVideoDriver* driver = device->gtVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();

//I don't understand pointers quite yet, let me see, so, it's part of the IVideoDriver class and it assigns device->gtVideoDriver(); to driver?
//If this is the case why is IVideoDriver and the astrix needed, I'm not very familiar with pointers.

guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
rect<s32>(10,10,260,22), true);

IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
if (!mesh)
return 1;
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

//Again he's using the pointers, I suppose it's assigning the word mesh the model of sydney? (what does IAnimatedMesh do?) then he creates a node for the mesh and assigns it to the word node?

if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
}

smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));

driver->beginScene(true, true, SColor(255,100,101,140));

smgr->drawAll();
guienv->drawAll();

// If there were things from other classes I assume you would have to initiate those too?

driver->endScene();
}


device->drop();

return 0;
}
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Post by cobra »

There seem to be allot of commands just thrown at you, so, trying to understand, device is the irrlicht device (the highest class?) and it has a sub command to set the window caption?
The Irrlicht device is the device that runs everything. This is the main class of it all. Irrlicht is unusable without the device being initiated.

setWindowCaption is a function of the Irrlicht device.



I don't understand pointers quite yet, let me see, so, it's part of the IVideoDriver class and it assigns device->getVideoDriver(); to driver?
You set a variable name (ie, IVideoDriver *driver) so you can simply call driver->doThisFunction() instead of device->getVideoDriver()->doThisFunction().


device->getVideoDriver() returns type IVideoDriver, of course.

Again he's using the pointers, I suppose it's assigning the word mesh the model of sydney? (what does IAnimatedMesh do?) then he creates a node for the mesh and assigns it to the word node?
IAnimatedMesh is a mesh, yes. And it cannot do world-specific things like rotate or move. It only contains mesh data.

IAnimatedMeshSceneNode is the actual world object, and it loads the mesh data from the IAnimatedMesh that gets passed to it. It can do world-specific functions. This is mainly for animated meshes.

IMeshSceneNode handles non-animated meshes.

If there were things from other classes I assume you would have to initiate those too?
Those update the visuals of both the user interface and the scene every frame. Anything that would need to be called every frame is put in the mainloop. So yes, if you wanted to do something else like draw2dLine, you would need to call it every frame like he does here.

I hope that helps you some. I explained it the best and simplest way I could, and from what I know. I might have been wrong on some points because I'm programming and was trying to hurry. :P
Josiah Hartzell
Image
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Understanding Hello World (questions comented)

Post by CuteAlien »

You should use the code tag for code in the forum to make it more readable (list of tags is directly above the editfield when writing in the forum).

Check the FAQ in this forum to get links to some webpages which can help you learning c++.
namespace wrote: device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

//There seem to be allot of commands just thrown at you, so, trying to understand, device is the irrlicht device (the highest
class?) and it has a sub command to set the window caption?
The device is the main interface for Irrlicht. setWindowCaption is one of its memberfunctions. You can always check the documenation for what they do (for IrrlichtDevice it is: http://irrlicht.sourceforge.net/docu/cl ... evice.html)

namespace wrote: IVideoDriver* driver = device->gtVideoDriver();
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();

//I don't understand pointers quite yet, let me see, so, it's part of the IVideoDriver class and it assigns device->gtVideoDriver(); to driver?
//If this is the case why is IVideoDriver and the astrix needed, I'm not very familiar with pointers.
Well, you better learn about pointers then :-). As short introduction: All variables in c++ have types. That is why you need the IVideoDriver* to tell the compiler the type of the variable driver. The asterisk behind the type declaration tells that you want a special type called "pointer" which can contain the address of an object of the type which is in front of the asterisk. The assignment is just that - wouldn't even have to be in the same line.
namespace wrote: IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
if (!mesh)
return 1;
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );

//Again he's using the pointers, I suppose it's assigning the word mesh the model of sydney? (what does IAnimatedMesh do?) then he creates a node for the mesh and assigns it to the word node?
Yeah - mesh contains the model data and is loaded here from a file. Every SceneNode contains a 3D position and rotation and AnimatedMeshSceneNode is a special node which also can contains an animated mesh which will be displayed at the given position.
namespace wrote: // If there were things from other classes I assume you would have to initiate those too?
Not sure what you mean. If you refer to the mainloop - it already does most of the stuff you will need for a while.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9682
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

cobra wrote: device->getVideoDriver() returns type IVideoDriver, of course.
Actually it returns type IVideoDriver*
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
namespace
Posts: 7
Joined: Thu Jul 09, 2009 6:30 pm

Post by namespace »

Thanks! :) I think that answered all my questions, and it was prompt to, now I can continue working, thanks!
marmz
Posts: 7
Joined: Wed Jul 29, 2009 2:48 pm

Understanding texture mapping

Post by marmz »

Does anyone knows a good tutorial (possibly for GIMP) for understanding how to create BMP textures and bind them to 3d objects? I mean.. lookin at the file sydney.bmp i can't uderstand how the texture pieces are assigned tho the meshes when loaded in Irrlicht.

ty :roll:
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Re: Understanding texture mapping

Post by Virion »

marmz wrote:Does anyone knows a good tutorial (possibly for GIMP) for understanding how to create BMP textures and bind them to 3d objects? I mean.. lookin at the file sydney.bmp i can't uderstand how the texture pieces are assigned tho the meshes when loaded in Irrlicht.

ty :roll:
google for UV Mapping
Post Reply