.x Model - No Texture
Posted: Tue Jan 23, 2007 11:38 pm
I'm creating a small game for school using Irrlicht.
I've loaded in an IAnimatedMesh as the level and followed the Collision Detection Tutorial.
No matter what I do I cannot get the level mesh to show the textures I've added. It also comes out all white. I've been searching for weeks now and can't solve the problem. Help!
I've loaded in an IAnimatedMesh as the level and followed the Collision Detection Tutorial.
No matter what I do I cannot get the level mesh to show the textures I've added. It also comes out all white. I've been searching for weeks now and can't solve the problem. Help!
Code: Select all
// LevelOne.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "LevelOne.h"
#include <irrlicht.h>
#include <iostream>
#include <windows.h>
#include <audiere.h>
#pragma comment(lib, "Irrlicht.lib")
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace audiere;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
// let user select driver type
video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;
// create device
IrrlichtDevice *device = createDevice(driverType, core::dimension2d<s32>(1024, 768), 32, true);
if (device == 0)
return 1;
// could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
scene::IAnimatedMesh* levelmesh = smgr->getMesh("LevelOne.x");
scene::ISceneNode* node = 0;
if (levelmesh)
node = smgr->addOctTreeSceneNode(levelmesh->getMesh(0));
scene::ITriangleSelector* selector = 0;
if (node)
{
node->setPosition(core::vector3df(0,0,0));
selector = smgr->createOctTreeTriangleSelector(levelmesh->getMesh(0), node, 128);
node->setTriangleSelector(selector);
selector->drop();
}
//node->SetMaterialFlag(MaterialFlag.LIGHTING,false);
//driver->setFog(video::SColor(0,200,200,200), true, 50, 3000, 0, true);
//driver->setAmbientLight(video::SColor(100,100,100,100));
node->setMaterialFlag(video::EMF_FOG_ENABLE, true);
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
//node->setMaterialTexture(0, driver->getTexture("texture/terrain.jpg"));
//node->setMaterialFlag(video::EMF_WIREFRAME, true);
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,300.0f);
camera->setPosition(core::vector3df(0,20,0));
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(selector, camera, core::vector3df(10,10,10),core::vector3df(0,-3,0),core::vector3df(0,20,0));
camera->addAnimator(anim);
device->getCursorControl()->setVisible(false);
scene::IBillboardSceneNode * bill = smgr->addBillboardSceneNode();
bill->setMaterialType(video::EMT_TRANSPARENT_ADD_COLOR );
bill->setMaterialTexture(0, driver->getTexture("texture/particle2.bmp"));
bill->setMaterialFlag(video::EMF_LIGHTING, false);
bill->setSize(core::dimension2d<f32>(20.0f, 20.0f));
video::SMaterial material;
/*
//material.Texture1 = driver->getTexture("texture/guard.bmp");
material.Lighting = false;
scene::IAnimatedMeshSceneNode* guard1 = 0;
scene::IAnimatedMeshSceneNode* guard2 = 0;
scene::IAnimatedMeshSceneNode* guard3 = 0;
scene::IAnimatedMesh* guard = smgr->getMesh("model/julia.x");
if (guard)
{
guard1 = smgr->addAnimatedMeshSceneNode(guard);
guard1->setPosition(core::vector3df(-70,0,-90));
//guard1->setMD2Animation(scene::EMAT_RUN);
//guard1->getMaterial(0) = material;
guard2 = smgr->addAnimatedMeshSceneNode(guard);
guard2->setPosition(core::vector3df(-70,0,-30));
// guard2->setMD2Animation(scene::EMAT_SALUTE);
//guard2->getMaterial(0) = material;
guard3 = smgr->addAnimatedMeshSceneNode(guard);
guard3->setPosition(core::vector3df(-70,0,-60));
// guard3->setMD2Animation(scene::EMAT_JUMP);
//guard3->getMaterial(0) = material;
}
scene::ISceneNodeAnimator* ani = smgr->createCollisionResponseAnimator(
selector, guard3, core::vector3df(60,0,60),
core::vector3df(0,-3,0),
core::vector3df(0,50,0));
guard3->addAnimator(ani);
ani->drop();
guard3->setMaterialFlag(video::EMF_LIGHTING, true);
*/
material.Texture1 = 0;
material.Lighting = false;
scene::ISceneNode* SkyBox = 0;
SkyBox = smgr->addSkyBoxSceneNode(
driver->getTexture("texture/default_skyboxup.jpg"),
driver->getTexture("texture/default_skyboxdn.jpg"),
driver->getTexture("texture/default_skybox3.jpg"),
driver->getTexture("texture/default_skybox1.jpg"),
driver->getTexture("texture/default_skybox2.jpg"),
driver->getTexture("texture/default_skybox0.jpg"));
scene::ISceneNode* selectedSceneNode = 0;
scene::ISceneNode* lastSelectedSceneNode = 0;
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, video::SColor(255,255,255,255));
smgr->drawAll();
core::line3d<f32> line;
line.start = camera->getPosition();
line.end = line.start + (camera->getTarget() - line.start).normalize() * 1000.0f;
core::vector3df intersection;
core::triangle3df tri;
if (smgr->getSceneCollisionManager()->getCollisionPoint(line, selector, intersection, tri))
{
bill->setPosition(intersection);
driver->setTransform(video::ETS_WORLD, core::matrix4());
driver->setMaterial(material);
driver->draw3DTriangle(tri, video::SColor(0,255,0,0));
}
selectedSceneNode = smgr->getSceneCollisionManager()->getSceneNodeFromCameraBB(camera);
if (lastSelectedSceneNode)
lastSelectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
if (selectedSceneNode == node || selectedSceneNode == bill)
selectedSceneNode = 0;
if (selectedSceneNode)
selectedSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
lastSelectedSceneNode = selectedSceneNode;
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Collision detection example - Irrlicht Engine [";
str += driver->getName();
str += "] FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}