i try to load textures at runtime but it doesn't work
Code: Select all
IrrlichtDevice*device = 0;
int mdl_id =100000;
int m_a_n =0;
class Eventhandle : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
...
break;
case EGET_FILE_SELECTED:
if (id == 107)
{
if (model_select_change== 1 )
{
model_select_change= 0;
}
if (model_select_change== 0 && mdl_id > 100000)
{
model_select_change= 1;
mdl_id-=1;
}
IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller;
loadModel(core::stringc(dialog->getFilename()).c_str());
debug_tab_fb_m->setText(debug_tab_fo_m ->getFilename());
}
else
if (id == 108)
{
IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller;
loadTexture1(core::stringc(dialog->getFilename()).c_str());
debug_tab_fb_t1->setText(debug_tab_fo_t1 ->getFilename());
}
else
if (id == 109)
{
IGUIFileOpenDialog* dialog = (IGUIFileOpenDialog*)event.GUIEvent.Caller;
//loadTexture1(core::stringc(dialog->getFilename()).c_str());
debug_tab_fb_t2->setText(debug_tab_fo_t2 ->getFilename());
}
return true;
...
}
void loadModel(const c8* filename)
{
scene::ISceneManager* sm = device->getSceneManager();
scene::ICameraSceneNode* camera = sm->getActiveCamera();
core::vector3df camera_pos =camera->getPosition();
scene::IAnimatedMesh* mesh[99999];
scene::ISceneNode *node[99999];
//device->getFileSystem()->addZipFileArchive(filename);
mesh[m_a_n] = sm->getMesh(filename);
if (!mesh[m_a_n])
{
// model konnte nicht geladen werden
device->getGUIEnvironment()->addMessageBox(L"Nein, nein, nein! SO geht das nicht",
L"Das Model konnte nicht geladen werden. Kein unterstütztes Format (.x, .3ds, .ms3d, .md2). ");
return;
}
node[m_a_n] = device->getSceneManager()->addAnimatedMeshSceneNode(mesh[m_a_n],0,mdl_id);
node[m_a_n]->setPosition(vector3df(camera_pos));
node[m_a_n]->setVisible(true);
node[m_a_n]->setMaterialFlag(video::EMF_LIGHTING, false);
debug_tab_fb_m->setEnabled(false);
node[m_a_n]->setMaterialType(video::EMT_SOLID_2_LAYER); //Lightmaps? SOLID deaktiviert die Lightmaps
//mdl_id+=1;
//m_a_n+=1;
return;
}
void loadTexture1(const c8*filename)
{
scene::ISceneManager* sm = device->getSceneManager();
scene::ISceneNode* temp_node= sm->getSceneNodeFromId(mdl_id);
IGUIEnvironment *guienv = device->getGUIEnvironment();
if (!temp_node)
{
guienv->addMessageBox(L"Nein, nein, nein! SO geht das nicht",
L"Die Textur konnte nicht geladen werden, weil noch kein Model ausgewählt wurde!. ");
return;
}
else
{
temp_node-> setMaterialTexture(0, device->getVideoDriver()->getTexture(filename));
}
}
...
};
can anyone help me?