applying a texture to a mesh

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
daemon

applying a texture to a mesh

Post by daemon »

hey,

i'm a newbie, newcomer, beginner, blablabla..

i loaded a mesh from an .obj file (wavefront),

scene::IAnimatedMesh* terr = smgr->getMesh("terr.obj");
scene::ISceneNode* tnode = 0;
if (terr) tnode = smgr->addOctTreeSceneNode(terr->getMesh(0));

and applied a texture to it using :
tnode->setMaterialTexture(0, driver->getTexture("terr.jpg"));

the mesh shows up.. but it's black..
it's supposed to be a mountain (grassy)..

is it allowed to put textures on meshes at all ? or am I doing something wrong ? (which is probably the cause)

dunno if this helps :
when instead of 0 i put 1 in setMaterialTexture, the mountain came up green, but the whole mountain was all the same kind of green, just one colour.. obviously terr.jpg contains more than 1 colour..

thx

daemon
Masdus
Posts: 186
Joined: Tue Aug 26, 2003 1:13 pm
Location: Australia

Post by Masdus »

what sort of lighting do you have in the level?
daemon

Post by daemon »

i dunno.. default.. i didn't do anything with the lighting..

there are other nodes in the scene and i see them perfectly..

there's a testnode with texture just next to it and it's ok..

anyway.. i now think the problem might lie elsewhere..
i tried applying a texture to this mountain from another program (3d modeller) and it did the same.. so it's not irrlicht.. (sorry about posting here :P).

anyone has a clue of what's going on ?

i opened a md2 model applied a texture it was ok..
i opened a obj file (which was a mountain created with bryce) applied a texture and it was monochromatic

thx
daemon
arras
Posts: 1622
Joined: Mon Apr 05, 2004 8:35 am
Location: Slovakia
Contact:

Post by arras »

Its look like your mesh dont have UV data. You have to UV map your model before using texture. Use your modeler to UV map your mesh or look at my site for good free UV maper LithUnwrap
daemon

Post by daemon »

ok.. it was the UV maps after all..

now when i open the mesh with any 3d editor and apply the texture it looks fine..but irrlicht still shows it black or monochrome

i exported the mesh to a directx .x file, and it does the same thing. the mountain shows up, but it's black..
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

You need to manually load the textures into Irrlicht with the setMaterialTexture() function. Set the texture level to 0 and it will override the texture you have set in ( unless you want to put the textures in the same folder as the mesh ). I don't know how to override two textures on a model, however I would like to *hint hint*

Edit: I noticed on a second glance that you did put the setMaterialTexture in the first one so you have probably already done that, soz my bad. Does Irrlicht's console say that the texture is loaded?
daemon

Post by daemon »

yes it is loaded.. the mesh and the texture..
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Oh yeah, I didn't notice that before. You haven't got any lights in the scene right? You need to set this:

Code: Select all

node->setMaterialFlag(video::EMF_LIGHTING, false);
That will light the model, at the moment nothing is lit up so they would look black.
daemon

Post by daemon »

ahhhhhhhh now i get it :D
it works fine.

thanks a million !

daemon
Post Reply