I've run into some issues using the TerrainMesh when I updated my 3d viewer from Irrlicht-1.6 to 1.7.1.
It looks like the textures are being applied incorrectly to the terrain and the memory needed by the textures has increased.
I'm including a screenshot comparing the two versions of Irrlicht driven by the same program, logs showing what got piped to the screen and the memory usage, and the source code used to do the tests.
If there's something I need to modify in my code to use the TerrainMesh in 1.7.1, or some patch that could be applied to Irrlicht, I'd like to hear about it.
If this is an actual bug in Irrlicht, feel free to move this into the Bug Reports secion.
Here's the screenshot:
Here's the log from version 1.6:
Irrlicht Engine version 1.6
Microsoft Windows XP Professional Service Pack 3 (Build 2600)
Using renderer: Direct3D 9.0
NVIDIA GeForce 8600 GT nv4_disp.dll 6.14.11.5827
Generated terrain texture (256x256): terrain175225_0
Generated terrain texture (256x256): terrain175225_1
Generated terrain texture (256x256): terrain175225_2
Generated terrain texture (256x256): terrain175225_3
Generated terrain texture (16x256): terrain175225_4
Generated terrain texture (256x256): terrain175225_5
Generated terrain texture (256x256): terrain175225_6
Generated terrain texture (256x256): terrain175225_7
Generated terrain texture (256x256): terrain175225_8
Generated terrain texture (16x256): terrain175225_9
Generated terrain texture (256x256): terrain175225_10
Generated terrain texture (256x256): terrain175225_11
Generated terrain texture (256x256): terrain175225_12
Generated terrain texture (256x256): terrain175225_13
Generated terrain texture (16x256): terrain175225_14
Generated terrain texture (256x256): terrain175225_15
Generated terrain texture (256x256): terrain175225_16
Generated terrain texture (256x256): terrain175225_17
Generated terrain texture (256x256): terrain175225_18
Generated terrain texture (16x256): terrain175225_19
Generated terrain texture (256x16): terrain175225_20
Generated terrain texture (256x16): terrain175225_21
Generated terrain texture (256x16): terrain175225_22
Generated terrain texture (256x16): terrain175225_23
Generated terrain texture (16x16): terrain175225_24
CPU = 50%
Memory Usage = 24,440K
Here's the log from version 1.7.1:
Here's the source code derived from the terrain tute and run with VS2005:Irrlicht Engine version 1.7.1
Microsoft Windows XP Professional Service Pack 3 (Build 2600)
Using renderer: Direct3D 9.0
NVIDIA GeForce 8600 GT nv4_disp.dll 6.14.11.5827
Generated terrain texture (1024x1024): terrain174839_0
Generated terrain texture (1024x1024): terrain174839_1
Generated terrain texture (1024x1024): terrain174839_2
Generated terrain texture (1024x1024): terrain174839_3
Generated terrain texture (1024x1024): terrain174839_4
Generated terrain texture (1024x1024): terrain174839_5
Generated terrain texture (1024x1024): terrain174839_6
Generated terrain texture (1024x1024): terrain174839_7
Generated terrain texture (1024x1024): terrain174839_8
Generated terrain texture (1024x1024): terrain174839_9
Generated terrain texture (1024x1024): terrain174839_10
Generated terrain texture (1024x1024): terrain174839_11
Generated terrain texture (1024x1024): terrain174839_12
Generated terrain texture (1024x1024): terrain174839_13
Generated terrain texture (1024x1024): terrain174839_14
Generated terrain texture (1024x1024): terrain174839_15
Generated terrain texture (1024x1024): terrain174839_16
Generated terrain texture (1024x1024): terrain174839_17
Generated terrain texture (1024x1024): terrain174839_18
Generated terrain texture (1024x1024): terrain174839_19
Generated terrain texture (1024x1024): terrain174839_20
Generated terrain texture (1024x1024): terrain174839_21
Generated terrain texture (1024x1024): terrain174839_22
Generated terrain texture (1024x1024): terrain174839_23
Generated terrain texture (1024x1024): terrain174839_24
CPU = 50%
Memory Usage = 156,388K
Code: Select all
// Edit following 3 lines for correct version of Irrlicht
#include "C:\Program Files\irrlicht-1.7.1\include\irrlicht.h"
#pragma comment(lib, "C:\\Program Files\\irrlicht-1.7.1\\lib\\Win32-visualstudio\\Irrlicht.lib")
// Remember to add "C:\Program Files\irrlicht-1.7.1\bin\Win32-VisualStudio" to Path in Environment Variables
#include <iostream>
#include <iomanip>
using namespace irr;
using namespace scene; // needed for mesh import
using namespace video; // needed for EMF_LIGHTING
class MyEventReceiver : public IEventReceiver
{
public:
MyEventReceiver(scene::ISceneNode* terrain)
{
// store pointer to terrain so we can change its drawing mode
Terrain = terrain;
}
bool OnEvent(const SEvent& event)
{
// check if user presses the key 'W' or 'D'
if (event.EventType == irr::EET_KEY_INPUT_EVENT &&
!event.KeyInput.PressedDown)
{
switch (event.KeyInput.Key)
{
case irr::KEY_KEY_W: // switch wire frame mode
Terrain->setMaterialFlag(video::EMF_WIREFRAME,
!Terrain->getMaterial(0).Wireframe);
return true;
case irr::KEY_KEY_D: // toggle detail map
Terrain->setMaterialType(
Terrain->getMaterial(0).MaterialType
== video::EMT_SOLID ?
video::EMT_DETAIL_MAP : video::EMT_SOLID);
return true;
}
}
return false;
}
private:
scene::ISceneNode* Terrain;
};
int main()
{
float fTerrainScale = 40.f;
int iTerrainType;
iTerrainType = 1;
std::cout << "Enter Terrain Type 1 (mesh) or 2 (LOD)" << std::endl;
std::cin >> iTerrainType;
video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;
// create device
irr::SIrrlichtCreationParameters params;
params.DriverType=driverType;
params.WindowSize=core::dimension2d<u32>(320, 240);
IrrlichtDevice* device = createDeviceEx(params);
if (device == 0)
return 1; // could not create selected driver.
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
gui::IGUIEnvironment* env = device->getGUIEnvironment();
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
// add camera
scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,2.0f);
camera->setPosition(core::vector3df(2000.0f,5000.f,0.0f));
camera->setTarget(core::vector3df(0.0f,0.0f,0.0f));
camera->setFarValue(200000.0f);
device->getCursorControl()->setVisible(false); // disable mouse cursor
if (iTerrainType == 1){ //Terrain Mesh
video::IImage* colorMapImage = driver->createImageFromFile("C:/Program Files/irrlicht-1.7.1/media/terrain-texture.jpg");
video::IImage* heightMapImage = driver->createImageFromFile("C:/Program Files/irrlicht-1.7.1/media/terrain-heightmap.bmp");
scene::IAnimatedMesh* terrain = smgr->addTerrainMesh ("TerrainMeshName", colorMapImage, heightMapImage,
core::dimension2d< f32 >(fTerrainScale, fTerrainScale), // size of a pixel
8.f*fTerrainScale); // maximum height
scene::ISceneNode* room = 0;
ISceneNode* node = smgr->addAnimatedMeshSceneNode(terrain);
node->setMaterialFlag(video::EMF_LIGHTING, false);
node->setPosition(core::vector3df(-5000,0,-5000));
} else if (iTerrainType == 2){ // height map needs to be 2n+1 resolution
// add terrain scene node
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
"C:/Program Files/irrlicht-1.7.1/media/terrain-heightmap.bmp"
,0,-1
,core::vector3df(0.0f,0.0f,0.0f) // position
,core::vector3df(0.0f,0.0f,0.0f) // rotation
,core::vector3df(1.0f,1.0f,1.0f) // scale
,video::SColor(255,255,255,255)
,0 // Level of detail
,ETPS_17 // terrain patch size
,0 //smooth factor
);
terrain->setScale(core::vector3df(fTerrainScale, 1.0f, fTerrainScale));
terrain->setPosition(core::vector3df(-5000,0,-5000));
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->setMaterialTexture(0, driver->getTexture("C:/Program Files/irrlicht-1.7.1/media/terrain-texture.jpg"));
terrain->setMaterialTexture(1, driver->getTexture("C:/Program Files/irrlicht-1.7.1/media/detailmap3.jpg"));
terrain->setMaterialType(video::EMT_DETAIL_MAP);
terrain->scaleTexture(1.0f, 20.0f);
}
int lastFPS = -1;
while(device->run())
if (device->isWindowActive())
{
driver->beginScene(true, true, 0 );
smgr->drawAll();
env->drawAll();
driver->endScene();
// display frames per second in window title
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"Terrain Mesh - Irr-1.7.1 ";
str += " FPS:";
str += fps;
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}