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.
X_for_Extra
Posts: 69 Joined: Mon May 23, 2005 4:42 pm
Post
by X_for_Extra » Sun Jul 24, 2005 8:24 pm
Hey, I've been trying to set vertex colors on a terrain, but it goes all funky and wonky no matter what I do.
Clues?
here is my latest attempt:
Code: Select all
ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("media/h_map.bmp");
terrain->setScale(core::vector3df(15, 2.0f, 15));
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
s32 iCount = ((terrain->getMesh())->getMeshBuffer(0))->getVertexCount();
S3DVertex * verts = (S3DVertex *) ((terrain->getMesh())->getMeshBuffer(0))->getVertices();
S3DVertex tmp;
for(s32 i = 0; i < iCount; i++){
tmp = verts[i];
tmp.Color.setRed(100);
verts[i] = tmp;
}
I've tried like 100 variations on this theme, but it seems that as soon as I alter th color of a vert in the array, hijinks ensue.
Last edited by
X_for_Extra on Tue Jul 26, 2005 12:39 am, edited 1 time in total.
Should put something witty here I suppose.
X_for_Extra
Posts: 69 Joined: Mon May 23, 2005 4:42 pm
Post
by X_for_Extra » Sun Jul 24, 2005 11:25 pm
Alternately, if someone knows how to load a height map as a static octtree, I would settle for that, because I cant get the LOD-popping under control anyway.
Should put something witty here I suppose.
Spintz
Posts: 1688 Joined: Thu Nov 04, 2004 3:25 pm
Post
by Spintz » Mon Jul 25, 2005 4:08 am
Your problem is you're casting the vertices to the wrong type.
They should be casted to video::S3DVertex2TCoords
X_for_Extra
Posts: 69 Joined: Mon May 23, 2005 4:42 pm
Post
by X_for_Extra » Mon Jul 25, 2005 11:08 am
Oh, cool! And, duh, I should have known. It just didnt occur to me for some reason. Cheers.
This means I can dispense with the colormap texture and save a texture layer.
Should put something witty here I suppose.
X_for_Extra
Posts: 69 Joined: Mon May 23, 2005 4:42 pm
Post
by X_for_Extra » Tue Jul 26, 2005 12:39 am
Here is a screenshot of the result. Vertex colors and detail texture in OpenGL:
Should put something witty here I suppose.
etcaptor
Posts: 871 Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:
Post
by etcaptor » Tue Jul 26, 2005 4:39 am
How do you implement detail texture?
Site development - Rock and metal online
--- etcaptor.com ------ freenetlife.com
Guest
Post
by Guest » Tue Jul 26, 2005 9:17 am
I think the detail texture is just one of the normal texture layers?
But how did you get the shadowing? If you enable vertex lights the colors are overwritten.
Spintz
Posts: 1688 Joined: Thu Nov 04, 2004 3:25 pm
Post
by Spintz » Tue Jul 26, 2005 11:56 am
Very nice, I like to see pretty screenshots of terrain!!!
X_for_Extra
Posts: 69 Joined: Mon May 23, 2005 4:42 pm
Post
by X_for_Extra » Tue Jul 26, 2005 5:38 pm
Yes, the detail texture is just a regular texture, although it mipmaps exceptionally well. The shadows are in the color map.
Here is the code:
Code: Select all
ITerrainSceneNode* terrain = smgr->addTerrainSceneNode("media/h_map.bmp");
terrain->setScale(core::vector3df(15, 3.0f, 15));
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
terrain->setMaterialTexture(0, driver->getTexture("media/dirt.jpg"));
terrain->scaleTexture(16.0f);
IImage* colormap = driver->createImageFromFile("media/c_map.bmp");
s32 iCount = ((terrain->getMesh())->getMeshBuffer(0))->getVertexCount();
S3DVertex2TCoords * verts = (S3DVertex2TCoords *) ((terrain->getMesh())->getMeshBuffer(0))->getVertices();
S3DVertex2TCoords tmp; s32 y, x;
for(s32 i = 0; i < iCount; i++){
tmp = verts[i];
x = s32(tmp.Pos.X / 15);
y = s32(tmp.Pos.Z / 15);
tmp.Color = colormap->getPixel(x,y);
verts[i] = tmp;
}
I suppose I could apply the colormap before scaling to avoid the "/ 15" and posibly get more acurate results.
It looks good though.
Should put something witty here I suppose.