Irrlicht在错误的路径中查找文件。

4
我正在使用Irrlicht编写游戏,但遇到了问题。
我的游戏位于/home/m4tx/Projects/Discoverer/Discoverer/bin/Debug/,模型位于/home/m4tx/Projects/Discoverer/Discoverer/bin/Debug/media/。我已经修改了第一个Irrlicht示例的代码。
#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;
}

但Irrlicht只在/home/m4tx/中寻找模型...

如何修复?


你是如何调用你的程序的?它启动时的工作目录是什么? - Nate C-K
程序的工作目录是/home/m4tx/Projects/Discoverer/Discoverer/,但是也有一个包含所有必需文件的/media/目录。我还尝试了/home/m4tx/Projects/Discoverer/Discoverer/bin/Debug/,但它不起作用... - m4tx
我不知道为什么它不工作。我从Code::Blocks或Dolphin(文件管理器)启动它,它不起作用。我从终端或bash脚本启动它,它就可以工作了... - m4tx
在Visual Studio中,调试器中有一个选项可以设置工作目录(默认情况下,这是项目文件所在的目录)。Code::Blocks可能有类似的功能,并且可能设置为非常不同的目录。 - LiMuBei
1个回答

3

你需要正确获取工作目录。

在代码中添加一个好的调试行是打印当前路径或记录它。我通常把它放在main函数的第一行。

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

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

请在您的代码块项目文件中进行检查

查找:

<Option working_dir="." />

并根据需要进行更改。

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接