problem with compiling in VC++

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
manju

problem with compiling in VC++

Post by manju »

:roll: I've alrady set up the IDE but While compiling in VC++ the tutorial-1 I can't see the animation. please please some body help me.
manju

Re: problem with compiling in VC++

Post by manju »

[quote="manju"]:roll: I've alrady set up the IDE but While compiling in VC++ the tutorial-1, I can't see the animation. please please some body help me.
Guest

Post by Guest »

Since your head is blocking the monitor, I can't see the screen to
be able to tell which folder you are trying to execute the program
from, further I can't tell if you just opened the project file from
the default location of the Irrlicht install, or copied it to another
folder to re-compile. So either move your head out of the way
or provide a little more information as to what it is you are doing,
'cause the crystal ball is in the shop for repairs this week.
manju

Re: problem with compiling in VC++

Post by manju »

I've done all these things bellow, but after compiling I can just see an empty window with no animation and no character. Now please help me,

This Tutorial shows how to set up the IDE for using the Irrlicht Engine and how to write a simple HelloWorld program with it. The program will show how to use the basics of the VideoDriver, the GUIEnvironment and the SceneManager.
The result of this example will look like this:





Setting up the IDE
To use the engine, we will have to include the header file <irrlicht.h>, which can be found in the Irrlicht Engine SDK directory \include. To let the compiler find this header file, the directory where it is located should be specified somewhere. This is different for every IDE and compiler. I will explain how to do this in Microsoft Visual Studio C++ 6.0 and .NET:

If you use Version 6.0, select the Menu Extras -> Options. Select the directories tab, and select the 'Include' Item in the combo box. Add the \include directory of the Irrlicht Engine folder to the list of directories. Now the compiler will find the Irrlicht.h header file. We also need the location of irrlicht.lib to be listed, so select the 'Libraries' tab and add the \lib\VisualStudio directory.




If your IDE is Visual Studio .NET, select Tools -> Options. Select the Projects entry and then select VC++ directories. Select 'show directories for include files' in the combo box, and add the \include directory of the Irrlicht Engine folder to the list of directories so the compiler will find the Irrlicht.h header file. We also need the irrlicht.lib to be found, so select 'show directories for Library files' and add the \lib\VisualStudio directory.






Lets start!
After we have set up the IDE, the compiler will know where to find the Irrlicht Engine header files so we can include it now into our code.

#include <irrlicht.h>


In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if you want to use a class of the engine, you'll have to type an irr:: before the name of the class. For example, to use the IrrlichtDevice, write: irr::IrrlichtDevice. To avoid having to put irr:: before of the name of every class, we tell the compiler that we use that namespace.

using namespace irr;


There are 5 sub-namespaces in the Irrlicht Engine. Take a look at them: you can read a detailed description of them in the documentation by clicking on the top menu item 'Namespace List'. To keep this example simple, we don't want to have to specify the name spaces, Hence:

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


To be able to use the Irrlicht.DLL file, we need to link with the Irrlicht.lib. We could set this option in the project settings, but to make it easy we use a pragma comment:

#pragma comment(lib, "Irrlicht.lib")


Now the main method: to keep this example simple we use void main(), which can be used on any platform. However, on Windows platforms, we could also use the WinMain method if we would want to get rid of the console window which pops up when starting a program with main().

int main(){


The most important function of the engine is the 'createDevice' function. The Irrlicht Device, which is the root object for doing everything with the engine, can be created with it. createDevice() has 7 parameters:

deviceType: Type of the device. This can currently be the Null device, the Software device, DirectX8, DirectX9, or OpenGL. In this example we use EDT_SOFTWARE, but, to try them out, you might want to change it to EDT_NULL, EDT_DIRECTX8 or EDT_OPENGL.
windowSize: Size of the window or full screen mode to be created. In this example we use 512x384.
bits: Number of bits per pixel when in full screen mode. This should be 16 or 32. This parameter is ignored when running in windowed mode.
fullscreen: Specifies if we want the device to run in full screen mode or not.
stencilbuffer: Specifies if we want to use the stencil buffer for drawing shadows.
vsync: Specifies if we want to have vsync enabled. This is only useful in full screen mode.
eventReceiver: An object to receive events. We do not want to use this parameter here, and set it to 0.
IrrlichtDevice *device = createDevice(EDT_SOFTWARE, dimension2d<s32>(512, 384), 16, false, false, false, 0);


Now we set the caption of the window to some nice text. Note that there is a 'L' in front of the string: the Irrlicht Engine uses wide character strings when displaying text.

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


Now we store a pointer to the video driver, the SceneManager, and the graphical user interface environment so that we do not always have to write device->getVideoDriver(), device->getSceneManager(), and device->getGUIEnvironment().

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


We add a hello world label to the window using the GUI environment. The text is placed at the position (10,10) as top left corner and (200,22) as lower right corner.

guienv->addStaticText(L"Hello World! This is the Irrlicht Software engine!", rect<int>(10,10,200,22), true);


To display something interesting, we load a Quake 2 model and display it. We only have to get the Mesh from the Scene Manager with getMesh() and add a SceneNode to display the mesh with addAnimatedMeshSceneNode(). Instead of loading a Quake2 file (.md2), it is also possible to load a Maya object file (.obj), a complete Quake3 map (.bsp), or a Milshape file (.ms3d).
By the way, that cool Quake 2 model called sydney.md2 was modelled by Brian Collins.

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


To make the mesh look a little bit nicer, we change its material a little bit: we disable lighting because we do not have a dynamic light in here and the mesh would be totally black. Then we set the frame loop so that the animation is looped between the frames 0 and 310. Then, at last, we apply a texture to the mesh. Without it the mesh would be drawn using only a solid color.

if (node){ node->setMaterialFlag(EMF_LIGHTING, false); node->setFrameLoop(0, 310); node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );}


To look at the mesh, we place a camera into 3d space at the position (0, 10, -40). The camera looks from there to (0,5,0).

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


Ok. Now that we have set up the scene, let's draw everything: we run the device in a while() loop until the device does not want to run any more. This would be when the user closes the window or presses ALT+F4 in Windows.

while(device->run()){


Everything must be drawn between a beginScene() and an endScene() call. The beginScene clears the screen with a color and also the depth buffer, if desired. Then we let the Scene Manager and the GUI environment draw their content. With the endScene() call, everything is presented on the screen.

driver->beginScene(true, true, SColor(0,200,200,200));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}


After we are finished, we have to delete the Irrlicht Device created earlier with createDevice(). With the Irrlicht Engine, you should delete all objects you created with a method or function that starts with 'create'. The object is deleted simply by calling ->drop(). See the documentation for more information.

device->drop(); return 0;
}
Xilande
Posts: 3
Joined: Tue Apr 26, 2005 1:50 pm

Post by Xilande »

#1 - You didn't have to tell us the contents of the tutorial, we all know which tutorial you're talking about

#2 - This isn't a compile problem

#3 - I know what the problem is, but it's hard to explain... the thing to do here is use common sense, get knowledge of programming prior to using this engine, get knowledge on how windows (well... if you're using linux, then you'll want to get knowledge on it) operates with the file system.

Here's what to do:
go into the directory with the irrlicht files in it, go into the media folder, and copy sydney.bmp and sydney.md2 into the folder with your project in it

next, change

Code: Select all

IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
to

Code: Select all

IAnimatedMesh* mesh = smgr->getMesh("sydney.md2");
and change

Code: Select all

node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );}
to

Code: Select all

node->setMaterialTexture( 0, driver->getTexture("sydney.bmp") );}


If this doesn't help you, then you should just give up now...
a lazy squareball

Post by a lazy squareball »

Moving the media into your project folder is probably the easiest thing you can do.

Why's it not finding your media files?
They're supposed to be in ../../media/insertfilehere.ext
../.. means it's looking in the same place you're in.

So, even though you do have c:\irrlicht-0.9\media\insertfilehere.ext,
you might have your project elsewhere, such as
c:\project\another_folder\projectname.ext

Your code is looking inside c:\project\media\insertfilehere.ext, which doesn't exist, leaving your graphic empty.

How do I know this? I had the same problem, and was also confused until I realized this.
Post Reply