Problem with textures, possible overwrite?
Posted: Wed Jan 09, 2008 7:39 pm
Another problem popped up, it seems that this code somehow manages to overwrite level textures when I add these two sydney meshes to the level.
Here is what happens when level is loaded:
And here is when I pull the camera out:
I tried to figure it out but just simply cannot find out why this happens. That first picture effect seems to be some way related to the mesh movement as if I direct my view to certain spot, textures chance as the mesh moves.
Could you help me out? Do I overwrite something when loading level and meshes or just fail to understand somethin critical?
Here is the code, I added everything involved to scene in one file to avoid posting all the classes involving to the scene so sorry about it being a bit messy.
core.h
core.cpp
Game.h
Game.cpp
SceneManager.h
SceneManager.cpp
Here is what happens when level is loaded:
And here is when I pull the camera out:
I tried to figure it out but just simply cannot find out why this happens. That first picture effect seems to be some way related to the mesh movement as if I direct my view to certain spot, textures chance as the mesh moves.
Could you help me out? Do I overwrite something when loading level and meshes or just fail to understand somethin critical?
Here is the code, I added everything involved to scene in one file to avoid posting all the classes involving to the scene so sorry about it being a bit messy.
core.h
Code: Select all
#ifndef _CORE_H_
#define _CORE_H_
#include <irrlicht.h>
//engine namespaces
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
class CGameCore //here we define the class and create our poiners
{
public:
//functions providing acess to engine componants.
//GUI Environment
IGUIEnvironment* getGUIEnv();
//Scene Manager
ISceneManager* getSceneMngr();
//video driver
IVideoDriver* getVideo();
//Engine core device
IrrlichtDevice* getDevice();
//constructor
CGameCore();
//destructor
virtual ~CGameCore();
private:
//used to insanianate device
void InitalizeDevice();
//corisponding pointers to engine core functions
IrrlichtDevice* pDevice;
IVideoDriver* pDrv;
ISceneManager* pSceneMngr;
IGUIEnvironment* pGUIEnv;
ICameraSceneNode *camera;
};
#endif
Code: Select all
#include "core.h"
#include <iostream>
CGameCore::CGameCore()
{
InitalizeDevice();
std::cout<<"Game Manager Created !\n";
}
CGameCore::~CGameCore()
{
std::cout<<"Game Manager Shut Down!!\n";
}
/* in thefuntion below we have 2 device types one that uses a directx
device with decent resolution settings and one using OpenGL with
minimal settings set up in an if statment. one cool thing about
doing ot this way is that if you have another app running that
wont release the directx driver, the game manager object
will automagicly use the openGL device instead and tell you
that its using it if you have a console app or a drop down style
console in your app ( quake style ) */
void CGameCore::InitalizeDevice()
{
pDevice = createDevice(EDT_DIRECT3D9, core::dimension2d<s32>(1024,768), 32, false, true, true);
std::cout<<"Device Creation Success !!\n";
//if above fails, use minimal config below
if(pDevice==NULL){
pDevice = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(1024,768),32,false,false,false);
std::cout<<"Warning : Minimal Device Config In Use !!\n";
}
//Init engine functions and store the pointers to them
pSceneMngr = pDevice->getSceneManager();
pDrv = pDevice->getVideoDriver();
pGUIEnv = pDevice->getGUIEnvironment();
/* one thing to note about Irredit is the fact that once the scene file
gets written out , upon loading it into the engine , you have to access
the nodes you want to work with by name, Id, or type, the commented
line below accesses the scene node named "home" by casting it as an
animated mesh scene node, then returning the name of the node
in question via getSceneNodeByName() then we can use the returned
node we cast it as to change material flag settings and the like. */
//IAnimatedMeshSceneNode* hnode = (IAnimatedMeshSceneNode*)pSceneMngr->getSceneNodeFromName("home");
//here we use the node name we casted above to change material flags
//hnode->setMaterialFlag(video::EMF_LIGHTING, false);
//core::dimension2d<s32> resolution ( 800, 600 );
//pDevice = createDevice(video::EDT_BURNINGSVIDEO,resolution, 32, false, false, false);
pSceneMngr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
}
//return a funtion to engine core fuctions here
IrrlichtDevice* CGameCore::getDevice()
{
return pDevice;
}
// GUI
IGUIEnvironment* CGameCore::getGUIEnv()
{
return pGUIEnv;
}
//Video
IVideoDriver* CGameCore::getVideo()
{
return pDrv;
}
//Scene Manager
ISceneManager* CGameCore::getSceneMngr()
{
return pSceneMngr;
}
Code: Select all
#ifndef _GAME_H_
#define _GAME_H_
#include <irrlicht.h>
#include "Core.h"
#include "SceneManager.h"
#include "CameraManager.h"
using namespace irr;
//! Main entry point to game
class CGame
{
public:
CGame();
~CGame();
bool run();
private:
CGameCore * pManager;
SceneManager *gameSceneManager;
CameraManager *gameCameraManager;
};
#endif
Code: Select all
#include "Game.h"
CGame::CGame()
{
pManager = new CGameCore;
gameSceneManager = new SceneManager(pManager);
gameCameraManager = new CameraManager(pManager);
}
CGame::~CGame()
{
delete gameSceneManager;
delete gameCameraManager;
delete pManager;
}
//! Main game loop
bool CGame::run()
{
// Name of game, displayed in window if windowed
pManager->getDevice()->setWindowCaption(L"some app name here");
int lastFPS = -1;
// Keep running game loop if device exists
gameSceneManager->SceneMansion();
//gameCameraManager->FirstPersonCamera();
while(pManager->getDevice()->run())
{
pManager->getVideo()->beginScene(true,true, SColor(255, 100, 101, 140));
pManager->getSceneMngr()->drawAll();
pManager->getGUIEnv()->drawAll();
pManager->getVideo()->endScene();
}
{
pManager->getDevice()->drop();
}
return 0;
}
Code: Select all
#ifndef _SCENEMANAGER_H_
#define _SCENEMANAGER_H_
#include "Core.h"
#include "irrlicht.h"
#include "GameObject.h"
class SceneManager
{
public:
SceneManager(CGameCore *core);
~SceneManager();
void SceneMansion();
private:
scene::ICameraSceneNode *camera;
scene::IAnimatedMeshSceneNode* model1;
scene::IAnimatedMeshSceneNode* model2;
video::IVideoDriver* driver;
IrrlichtDevice *gameDevice;
scene::ISceneManager *sm;
scene::IQ3LevelMesh *quakeLevelMesh;
scene::ISceneNode *quakeLevelNode;
scene::ITriangleSelector *mapSelector;
};
#endif
Code: Select all
#include "SceneManager.h"
SceneManager::SceneManager(CGameCore *core){
gameDevice = core->getDevice();
sm = core->getSceneMngr();
driver = core->getVideo();
gameDevice->getFileSystem()->addZipFileArchive("media/irrlicht.dat");
gameDevice->getFileSystem()->addZipFileArchive("media/map-20kdm2.pk3");
}
SceneManager::~SceneManager(){}
void SceneManager::SceneMansion()
{
SKeyMap keyMap[9];
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;
keyMap[8].Action = EKA_JUMP_UP;
keyMap[8].KeyCode = KEY_SPACE;
camera = sm->addCameraSceneNodeFPS(0, 100.0f, 400.0f, -1, keyMap, 9, false, .9f);
camera->setPosition(core::vector3df(108,140,-140));
quakeLevelMesh = (scene::IQ3LevelMesh*) sm->getMesh("maps/20kdm2.bsp");
if (quakeLevelMesh)
{
u32 i;
//move all quake level meshes (non-realtime)
core::matrix4 m;
m.setTranslation ( core::vector3df(-1300,-70,-1249) );
for ( i = 0; i!= scene::quake3::E_Q3_MESH_SIZE; ++i )
{
sm->getMeshManipulator()->transformMesh ( quakeLevelMesh->getMesh(i), m );
}
quakeLevelNode = sm->addOctTreeSceneNode(quakeLevelMesh->getMesh( scene::quake3::E_Q3_MESH_GEOMETRY),0,20);
if (quakeLevelNode)
{
//quakeLevelNode->setPosition(core::vector3df(-1300,-70,-1249));
quakeLevelNode->setVisible(true);
// create map triangle selector
mapSelector = sm->createOctTreeTriangleSelector(quakeLevelMesh->getMesh(0),
quakeLevelNode, 128);
// if not using shader and no gamma it's better to use more lighting, because
// quake3 level are dark
quakeLevelNode->setMaterialType ( video::EMT_LIGHTMAP_M4 );
// set additive blending if wanted
quakeLevelNode->setMaterialType(video::EMT_LIGHTMAP_ADD);
}
// the additional mesh can be quite huge and is unoptimized
scene::IMesh * additional_mesh = quakeLevelMesh->getMesh ( scene::quake3::E_Q3_MESH_ITEMS );
for ( i = 0; i!= additional_mesh->getMeshBufferCount (); ++i )
{
scene::IMeshBuffer *meshBuffer = additional_mesh->getMeshBuffer ( i );
const video::SMaterial &material = meshBuffer->getMaterial();
//! The ShaderIndex is stored in the material parameter
s32 shaderIndex = (s32) material.MaterialTypeParam2;
// the meshbuffer can be rendered without additional support, or it has no shader
const scene::quake3::SShader *shader = quakeLevelMesh->getShader ( shaderIndex );
if ( 0 == shader )
{
continue;
}
// Now add the MeshBuffer(s) with the current Shader to the Manager
sm->addQuake3SceneNode ( meshBuffer, shader );
}
// original mesh is not needed anymore
quakeLevelMesh->releaseMesh ( scene::quake3::E_Q3_MESH_ITEMS );
}
// load sydney model and create 2 instances
scene::IAnimatedMesh* mesh = 0;
mesh = sm->getMesh("media/sydney.md2");
if (mesh)
{
model1 = sm->addAnimatedMeshSceneNode(mesh);
model1->setID(20);
if (model1)
{
model1->setMaterialTexture(0, driver->getTexture("media/spheremap.jpg"));
model1->setPosition(core::vector3df(100,40,-80));
model1->setScale(core::vector3df(2,2,2));
model1->setMD2Animation(scene::EMAT_STAND);
model1->setMaterialFlag(video::EMF_LIGHTING, false);
model1->setMaterialType(video::EMT_SPHERE_MAP);
model1->addShadowVolumeSceneNode();
model1->setAutomaticCulling ( scene::EAC_BOX );
}
model2 = sm->addAnimatedMeshSceneNode(mesh);
model2->setID(21);
if (model2)
{
model2->setPosition(core::vector3df(120,80,-200));
model2->setScale(core::vector3df(3,3,3));
model2->setMD2Animation(scene::EMAT_STAND);
model2->setMaterialTexture(0, driver->getTexture("media/sydney.bmp"));
model2->setMaterialFlag(video::EMF_LIGHTING, true);
model2->addShadowVolumeSceneNode();
model2->setAutomaticCulling ( scene::EAC_BOX );
}
}
}