TerrainMesh Problem

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
Hobi

TerrainMesh Problem

Post by Hobi »

Hi!

Could someone please post a small code for displaying a terrainmesh?

Im a beginner and i dont know, what im doing wrong:

device = createDevice(video::EDT_DIRECTX9, core::dimension2d<s32>(640, 480), 32, false, true, 0);
driver = device->getVideoDriver();
smgr = device->getSceneManager();

TerrainNode = smgr->addTerrainMesh("Terrain",
driver->createImageFromFile("media/terrainmap.jpg"),
driver->createImageFromFile("media/heightmap.png"),
dimension2d< f32 >(300.0f, 300.0f),
500.0f,
dimension2d< s32 >(512, 512));




TerrainSceneNode = smgr->addAnimatedMeshSceneNode( TerrainNode );

smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
device->getCursorControl()->setVisible(false);

there is no syntax error. I dont know what im doing wrong, because there is nothing displayed.
:?: :?:
agrif

Post by agrif »

You might want to set the scene node's lighting to false. Without any lights, the scene would be completly black. By setting the lighting flag to false, the object will be displayed even with no lights.

Set the flag with:

Code: Select all

TerrainSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);
place this after you make the scene node, of course.


agrif
agrif

Post by agrif »

Woops. Forgot somthing. Sorry for the double post.

did you add a loop to draw anything?

somthing like:

Code: Select all

while(device->run() && driver)
{
        driver->beginScene(true, true, video::SColor(255,0,0,255));
        scenemgr->drawAll();
        driver->endScene();
}

device->drop();
should go at the end of the main() function.

Also, you didn't seem to declare the variables at all. For example, the device should be declared as "IrrlichtDevice *device = createDevice()". Make sure you declare your variables.

agrif
Guest

Post by Guest »

Thank you for your posting, but when i add these code:

device = createDevice(video::EDT_DIRECTX9, core::dimension2d<s32>(640, 480), 32, false, true, 0);
driver = device->getVideoDriver();
smgr = device->getSceneManager();


TerrainNode = smgr->addTerrainMesh("Terrain",
driver->createImageFromFile("media/terrainmap.jpg"),
driver->createImageFromFile("media/heightmap.png"),
dimension2d< f32 >(300.0f, 300.0f),
500.0f,
dimension2d< s32 >(512, 512));




TerrainSceneNode = smgr->addAnimatedMeshSceneNode( TerrainNode );

TerrainSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
device->getCursorControl()->setVisible(false);

I receive a null-pointer-exception....

TerrainSceneNode doesnt seem to be set???
Guest

Post by Guest »

Thank you for your posting, but when i add these code:

device = createDevice(video::EDT_DIRECTX9, core::dimension2d<s32>(640, 480), 32, false, true, 0);
driver = device->getVideoDriver();
smgr = device->getSceneManager();


TerrainNode = smgr->addTerrainMesh("Terrain",
driver->createImageFromFile("media/terrainmap.jpg"),
driver->createImageFromFile("media/heightmap.png"),
dimension2d< f32 >(300.0f, 300.0f),
500.0f,
dimension2d< s32 >(512, 512));




TerrainSceneNode = smgr->addAnimatedMeshSceneNode( TerrainNode );

TerrainSceneNode->setMaterialFlag(video::EMF_LIGHTING, false);

smgr->addCameraSceneNodeFPS(0, 100.0f, 100.0f);
device->getCursorControl()->setVisible(false);

I receive a null-pointer-exception....

TerrainSceneNode doesnt seem to be set???
Guest

Post by Guest »

the device is set elsewhere.

and i have a loop, too.

i dont think that there is the peoblem...
Guest

Post by Guest »

i added a simple mesh to the scene...and there is no problem with it.
only the terrain is not displayed.
Guest

Post by Guest »

Im so far, that i know, that this code doesn't save mesh data to "Terrain", because i get a nulll pointer exception, if i want to use the mesh data with another function e.g. to attach it to the TerrainSceneNode...

Code: Select all

TerrainMesh = smgr->addTerrainMesh("terrain", 
										driver->createImageFromFile("media/terrainmap.jpg"),
										driver->createImageFromFile("media/heightmap.png"),
										dimension2d< f32 >(300.0f, 300.0f),
										500.0f,
										dimension2d< s32 >(512, 512));
	
    mesh = smgr->getMesh("terrain");
										

	TerrainSceneNode = smgr->addAnimatedMeshSceneNode( mesh );

	TerrainSceneNode->setMaterialFlag(video::EMF_LIGHTING, false); <--- here i get the exception :cry: 

please help!
mm765
Posts: 172
Joined: Fri May 28, 2004 10:12 am

Post by mm765 »

why dont you use
TerrainSceneNode = smgr->addAnimatedMeshSceneNode( TerrainMesh );
?
edit: and the defaultvertexblocksize is probably far too big. try 32 or 64.
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Just a quick question........ can Irrlicht read ".png" image files??
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Endar wrote:Just a quick question........ can Irrlicht read ".png" image files??
No.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Endar
Posts: 145
Joined: Mon Jun 14, 2004 7:59 am

Post by Endar »

Aaaahh, so, trying to load a png file when irrlicht can't read them, this could possibly lead to problems.....maybe problems such as above???
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
Hobi
Posts: 14
Joined: Sun Jul 25, 2004 9:32 am

Post by Hobi »

At first: Thank you very much for your help!!!
my terrain is displayed now. It was the file format!!
But now i have another problem. My terrain looks very strange.

its repeating itself in a first row, and then there are more copys of it (3x3) which have only peeks on it. Also the texture seems to be rasterized, and is not scaled to the size of my terrain(although the image is the same size). It is much bigger.

And what does the parameter with the default vertex size do? i couldn't find anything exactly in the api. I found out that here is only working (64, 64).[/img]
Hobi
Posts: 14
Joined: Sun Jul 25, 2004 9:32 am

Post by Hobi »

OHH!!!
i fixed the problem :lol: :lol: :lol:

i had to convert my heightmap to a color image, so that it fits to the texture image!

thanks to everyone again!! :D
Guest

Post by Guest »

How does one go about "positioning" textures/terrains like this? Say that I load this one terrain as "A" and I want it surrounded by water terrains "B" how would I position this.

BBB
BAB
BBB

?
Post Reply