Page 1 of 1

TerrainMesh Problem

Posted: Sat Jul 24, 2004 6:46 pm
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.
:?: :?:

Posted: Sat Jul 24, 2004 7:03 pm
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

Posted: Sat Jul 24, 2004 7:11 pm
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

Posted: Sat Jul 24, 2004 7:13 pm
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???

Posted: Sat Jul 24, 2004 7:13 pm
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???

Posted: Sat Jul 24, 2004 7:15 pm
by Guest
the device is set elsewhere.

and i have a loop, too.

i dont think that there is the peoblem...

Posted: Sat Jul 24, 2004 7:20 pm
by Guest
i added a simple mesh to the scene...and there is no problem with it.
only the terrain is not displayed.

Posted: Sat Jul 24, 2004 11:51 pm
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!

Posted: Sun Jul 25, 2004 1:29 am
by mm765
why dont you use
TerrainSceneNode = smgr->addAnimatedMeshSceneNode( TerrainMesh );
?
edit: and the defaultvertexblocksize is probably far too big. try 32 or 64.

Posted: Sun Jul 25, 2004 8:03 am
by Endar
Just a quick question........ can Irrlicht read ".png" image files??

Posted: Sun Jul 25, 2004 8:59 am
by bal
Endar wrote:Just a quick question........ can Irrlicht read ".png" image files??
No.

Posted: Sun Jul 25, 2004 9:21 am
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???

Posted: Sun Jul 25, 2004 11:04 am
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]

Posted: Sun Jul 25, 2004 11:43 am
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

Posted: Fri Jul 30, 2004 9:04 am
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

?