开发者

Irrlicht is looking for files in the wrong path

开发者 https://www.devze.com 2023-02-06 02:31 出处:网络
I\'m writing a game using Irrlicht. And I have problem. I have game in /home/m4tx/Projects/Discoverer/Discoverer/bin/Debug/, and models in /home/m4tx/Projects/Discoverer/Discoverer/bin/Debug/media/.

I'm writing a game using Irrlicht. And I have problem.

I have game in /home/m4tx/Projects/Discoverer/Discoverer/bin/Debug/, and models in /home/m4tx/Projects/Discoverer/Discoverer/bin/Debug/media/. I have modified code from first Irrlicht example:

#include <irrlicht/irrlicht.h>

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

int main(int argc, char *argv[])
{
 IrrlichtDevice *device =
  createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 32,
   false, false, false, 0);

 if (!device)
  return 1;

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

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

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

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

 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));
 while(device->run())
 {
  driver->beginScene(true, true, SColor(255,100,101,140));

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

  driver->endScene();
 }

 device->drop();

 return 0;
}

But Irrlicht is looking for models only in /home/m4tx/...

How to repair it?


You need to get the working directory right.

A good debug line in your code is to print the current path, or log it. I normally put it was the first line in main.

#include <unisdt.h>
#include <stdlib.h>

char cwd[1024] = "";
getcwd( cwd, 1024 );
printf( "Current path: %s\n", cwd );

Also check in your code blocks projects file

look for:

<Option working_dir="." />

and change it as needed.

http://wiki.codeblocks.org/index.php?title=Project_file#Working_directory

0

精彩评论

暂无评论...
验证码 换一张
取 消