Textures are blacked out - Special statement needed?

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
MM2forever
Posts: 3
Joined: Fri Jan 20, 2012 1:11 pm

Textures are blacked out - Special statement needed?

Post by MM2forever »

Hello People....

I'm doing my firsts steps with the irrlicht engine and c++... I used to program in other languages so far and i have to get used to both (irrlicht/c++)

I changed the standard example code a bit to have a fps camera and load a .3ds file with external textures

Now I wonder why the textures of the model are not shown... i tried different things like setting the lighting on and off, adding ambient light and so on... no texture.

Heres the code:

Code: Select all

 
#include <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(EDT_OPENGL, dimension2d<u32>(640, 480), 32,
            false, false, false, 0);
 
 
    device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
 
 
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
 
 
    guienv->addStaticText(L"Game Engine Prototype",
        rect<int>(10,10,200,22), true);
 
 
    IMesh* mesh = smgr->getMesh("mainboard.3DS");
    IMeshSceneNode* node = smgr->addMeshSceneNode( mesh );
 
 
    if (node)
    {
        node->setPosition(core::vector3df(0,-50,50));
        node->setMaterialFlag(EMF_LIGHTING, true);
        //node->setMaterialFlag(EMF_ANTI_ALIASING, true);
        //node->setMaterialFlag(EMF_ANISOTROPIC_FILTER, true);
       // node->setFrameLoop(0, 310);
       // node->setMaterialTexture( 0, driver->getTexture("p4sba-mb.jpg") );
    }
 
    smgr->setAmbientLight(video::SColorf(0.3,0.3,0.3,1));
 
 
      SKeyMap keyMap[8];
                 keyMap[0].Action = EKA_MOVE_FORWARD;
                 keyMap[0].KeyCode = KEY_UP;
                 keyMap[1].Action = EKA_MOVE_FORWARD;
                 keyMap[1].KeyCode = KEY_KEY_W;
 
                 keyMap[2].Action = EKA_MOVE_BACKWARD;
                 keyMap[2].KeyCode = KEY_DOWN;
                 keyMap[3].Action = EKA_MOVE_BACKWARD;
                 keyMap[3].KeyCode = KEY_KEY_S;
 
                 keyMap[4].Action = EKA_STRAFE_LEFT;
                 keyMap[4].KeyCode = KEY_LEFT;
                 keyMap[5].Action = EKA_STRAFE_LEFT;
                 keyMap[5].KeyCode = KEY_KEY_A;
 
                 keyMap[6].Action = EKA_STRAFE_RIGHT;
                 keyMap[6].KeyCode = KEY_RIGHT;
                 keyMap[7].Action = EKA_STRAFE_RIGHT;
                 keyMap[7].KeyCode = KEY_KEY_D;
 
    smgr->addCameraSceneNodeFPS(0,100.0f,0.1f,-1, keyMap, 8);
        device->getCursorControl()->setVisible(false);
 
 
    while(device->run())
    {
 
        driver->beginScene(true, true, SColor(255,200,200,200));
 
        smgr->drawAll();
        guienv->drawAll();
 
        driver->endScene();
    }
 
 
    device->drop();
 
    return 0;
}
 
I can provide the model and/or screenshots in case its needed...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Textures are blacked out - Special statement needed?

Post by hybrid »

At first you should check the console log. All textures that are found are also printed there. If none is mentioned, the mesh loader simply doesn't find any texture in the mesh file. If the proper files on disk are not found, such an error message will be presented. And last, also certain texture coord modes are just not supported in Irrlicht. You need to have explicit texture coords in the model. The latter can be checked in the model viewer. Load your mesh first, and then some texture file. This will be applied to the whole mesh. If nothing changes, texture coords are broken.
MM2forever
Posts: 3
Joined: Fri Jan 20, 2012 1:11 pm

Re: Textures are blacked out - Special statement needed?

Post by MM2forever »

i checked the log, the files are found...
i loaded the model with the meshviewer supplied with irrlicht and there it looks quite messed up like colorful static (in german: Bunter Ameisenkrieg)

is this an idicator for unexplicit texture coords? (i dont know so much about 3d modelling itself, i got the model from turbosquid)
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Textures are blacked out - Special statement needed?

Post by hybrid »

Yes, could be. Or the vertex colors are not initialized. Maybe upload it somewhere or send it to me privately if you cannot publish this easily.
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Re: Textures are blacked out - Special statement needed?

Post by teto »

Maybe you miscompiled when setting lightning to false:
node->setMaterialFlag(EMF_LIGHTING, false);
Try maybe : node->getMaterial(0).Lighting = false;
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
smso
Posts: 246
Joined: Fri Jun 04, 2010 3:28 pm
Location: Hong Kong

Re: Textures are blacked out - Special statement needed?

Post by smso »

You may also import the model into blender and see what it looks like. Or load it with other program e.g. osgviewer from openscenegraph.
MasterKira
Posts: 11
Joined: Mon Feb 07, 2011 7:40 am

Re: Textures are blacked out - Special statement needed?

Post by MasterKira »

Yes try first with
node->setMaterialFlag(EMF_LIGHTING, false);
if still black/white/gray whatever color, probably is a mesh color/texture/UV mapping problem... if you use blender as 3D editor, be sure to use correctly the UV editor, or maybe it does not export the UVmap.

But before, look at here:
if (node)
{
node->setPosition(core::vector3df(0,-50,50));
node->setMaterialFlag(EMF_LIGHTING, true);
//node->setMaterialFlag(EMF_ANTI_ALIASING, true);
//node->setMaterialFlag(EMF_ANISOTROPIC_FILTER, true);
// node->setFrameLoop(0, 310);
//
node->setMaterialTexture( 0, driver->getTexture("p4sba-mb.jpg") ); why comment and not source?
}
Look the "red" sentence... if you want to see the texture you need to remove the comment ( // ) no?

Let's hope it works
MM2forever
Posts: 3
Joined: Fri Jan 20, 2012 1:11 pm

Re: Textures are blacked out - Special statement needed?

Post by MM2forever »

I commented it out because it has no effect on having textures either... The model stays black.

Only chance i see is that theres something wrong with the model. I sent it to hybrid but he didnt respond yet...
MasterKira
Posts: 11
Joined: Mon Feb 07, 2011 7:40 am

Re: Textures are blacked out - Special statement needed?

Post by MasterKira »

probably is an error in UV mapping of the model
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Textures are blacked out - Special statement needed?

Post by REDDemon »

you can try to display some simple model like a cube. If the cube is also black maybe there's a bug somewhere else. If the cube display correctly the bug is in the model or in the loader of the model. Usually texture are not displayed when:

wrong UV coords. wrong normals. wrong lighting (or no lighting at all. At least try to set a WHITE AMBIENT LIGHT to be sure there is enough light for your models). Unsupported texture format. Incomplete mipmaps pyramids. Wrong texture size .

Also try to add ambient light in the 3D editor of your model (there can be still certain model formats wich may sets the ambient light to black if the model require that. Of course don't know if irrlicht loaders have this "feature" or not)

last causes are also very common with outdated videodrivers. (you should get some warnings if you provide wrong textures. I'm pretty sure that irrlicht prints a log if OpenGL was not able to use a texture)

(for example textures are not used if you use mipmap filtering/ anisotropic filtering and the mipmap piramid you have for your model is not complete)
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Re: Textures are blacked out - Special statement needed?

Post by teto »

could that be because the texture is not a power of 2 ?
Using trunk with mingw/gcc 4.6, Windows 7 64 bits driver opengl
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: Textures are blacked out - Special statement needed?

Post by REDDemon »

if you have buggy video drivers yes. A right drivers should at elast throw some kind of error (but they will don't do that if are really bugged). For be sure try powers of 2 and square textures.
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: Textures are blacked out - Special statement needed?

Post by hybrid »

I did test the model now. And it loads the texture without problems. However, there seems to be an addtional model overlayed to the first one, which is mainly blue. Depending on your zbuffer settings. this may overlap the correct model completely. If you load your model with the meshviewer and look onto it from straight above and a certain distance, you see everything correct. But if you go closer, or look from an angle, it gets wrong. I don't know what it is, but you should somehow get rid of this second copy.
Edit: Seems to be a problem with material settings, not a second mesh. When altering the material type in the mesh viewer, the effect changes heavily. Also with or without light. I guess it's something with shininess, emissive light, or so. Did you maybe specify a bump map? These are also often blue, but it's maybe applied wrongly.
Post Reply