Well i created a project, based on the example 3 custom scene here follow the code, just put on a folder, on the samples of irrlicht to be able to see the media path and compile all
i am using Ming with codeblocks, but on visual studio the problem is the same, the vertex only render on the white back ground, and all is redered in front of him, thanks in advance
Code: Select all
/** Example 003 Custom SceneNode */
#include <irrlicht.h>
#include "driverChoice.h"
#include "ILineNode.h"
using namespace irr;
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
class CSampleSceneNode : public scene::ISceneNode
{
/*
First, we declare some member variables:
The bounding box, 4 vertices, and the material of the tetrahedron.
*/
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[4];
video::SMaterial Material;
public:
/*
The parameters of the constructor specify the parent of the scene node,
a pointer to the scene manager, and an id of the scene node.
In the constructor we call the parent class' constructor,
set some properties of the material, and create the 4 vertices of
the tetrahedron.
*/
CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
: scene::ISceneNode(parent, mgr, id)
{
Material.Wireframe = false;
Material.Lighting = false;
Vertices[0] = video::S3DVertex(0,0,10, 1,1,0,
video::SColor(255,0,255,255), 0, 1);
Vertices[1] = video::S3DVertex(10,0,-10, 1,0,0,
video::SColor(255,255,0,255), 1, 1);
Vertices[2] = video::S3DVertex(0,20,0, 0,1,1,
video::SColor(255,255,255,0), 1, 0);
Vertices[3] = video::S3DVertex(-10,0,-10, 0,0,1,
video::SColor(255,0,255,0), 0, 0);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<3; ++i)
Box.addInternalPoint(Vertices[i].Pos);
}
virtual void OnRegisterSceneNode()
{
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
/*
In the render() method most of the interesting stuff happens: The
Scene node renders itself. We override this method and draw the
tetrahedron.
*/
virtual void render()
{
/* Indices into the 'Vertices' array. A triangle needs 3 vertices
so you have to pass the 3 corresponding indices for each triangle to
tell which of the vertices should be used for it. */
u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 };
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
driver->drawVertexPrimitiveList(&Vertices[0], 3, &indices[0], 3, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
// driver->draw3DLine(core::vector3df(0,0,0), core::vector3df(0,0,0), irr::video::SColor(0xFF, 0xFF, 0xFF, 0xFF) );
}
/*
And finally we create three small additional methods.
irr::scene::ISceneNode::getBoundingBox() returns the bounding box of
this scene node, irr::scene::ISceneNode::getMaterialCount() returns the
amount of materials in this scene node (our tetrahedron only has one
material), and irr::scene::ISceneNode::getMaterial() returns the
material at an index. Because we have only one material, we can
return that and assume that no one ever calls getMaterial() with an index
greater than 0.
*/
virtual const core::aabbox3d<f32>& getBoundingBox() const
{
return Box;
}
virtual u32 getMaterialCount() const
{
return 1;
}
virtual video::SMaterial& getMaterial(u32 i)
{
return Material;
}
};
ILineNode* lineNode;
/*
That's it. The Scene node is done. Now we start the engine,
create the scene node and a camera, and look at the result.
*/
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
// create device
IrrlichtDevice *device = createDevice(driverType,
core::dimension2d<u32>(960, 540), 32, false);
if (device == 0)
return 1; // could not create selected driver.
// set window caption, get some pointers, create a camera
device->setWindowCaption(L"Custom Scene Node - Irrlicht Engine Demo");
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
// smgr->addCameraSceneNode(0, core::vector3df(0,-40,0), core::vector3df(0,0,0));
//
SKeyMap keyMap[4];
keyMap[0].Action = EKA_MOVE_FORWARD;
keyMap[0].KeyCode = KEY_KEY_W;
keyMap[1].Action = EKA_MOVE_BACKWARD;
keyMap[1].KeyCode = KEY_KEY_S;
keyMap[2].Action = EKA_STRAFE_LEFT;
keyMap[2].KeyCode = KEY_KEY_A;
keyMap[3].Action = EKA_STRAFE_RIGHT;
keyMap[3].KeyCode = KEY_KEY_D;
// add a first person shooter style user controlled camera
irr::scene::ICameraSceneNode * cameraNode = smgr->addCameraSceneNodeFPS( NULL, 20.0f, 0.02f, -1, keyMap, 4);
cameraNode->setPosition(vector3df(0,-10, -30));
IAnimatedMesh* hillPlaneMesh = smgr->addHillPlaneMesh( "GROUND",
core::dimension2d<f32>(10,10),
core::dimension2d<u32>(200,200), 0, 0,
core::dimension2d<f32>(0,0),
core::dimension2d<f32>(10,10));
ISceneNode* planeNode = smgr->addAnimatedMeshSceneNode(hillPlaneMesh);
planeNode->setMaterialTexture(0, driver->getTexture("../../media/stones.jpg"));
planeNode->setMaterialFlag(video::EMF_LIGHTING, false);
planeNode->setPosition(core::vector3df(0, -50, 0));
// Linenode
lineNode = new ILineNode(core::vector3df(0, 0, 0), 250, 150, core::vector3df(0,1,0), smgr->getRootSceneNode(), smgr);
//
SMaterial NM;
// NM.EmissiveColor = SColor(0x10, 0, 0xCC,0);
// NM.ColorMaterial = SColor(0x0A, 0, 0xCC,0);
NM.Lighting = false;
NM.Thickness = 3.0f;
NM.FrontfaceCulling = false;
NM.BackfaceCulling = false;
//// NM.Wireframe = true;
NM.setFlag(EMF_LIGHTING, false);
NM.setFlag(EMF_NORMALIZE_NORMALS, true);
// NM.setFlag(video::EMF_BLEND_OPERATION, true);
// NM.setFlag(irr::video::EMF_BLEND_OPERATION, true);
// NM.ColorMaterial = 100;
//
// iMat = irr::video::EMT_ONETEXTURE_BLEND; // video::EMT_TRANSPARENT_VERTEX_ALPHA;
//
// NM.MaterialType = irr::video::EMT_ONETEXTURE_BLEND; // (irr::video::E_MATERIAL_TYPE)iMat;
// NM.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_SRC_ALPHA, video::EBF_ONE_MINUS_SRC_ALPHA, video::EMFN_MODULATE_1X, video::EAS_TEXTURE | video::EAS_VERTEX_COLOR);
//// NM.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_SRC_ALPHA, video::EAS_VERTEX_COLOR);
NM.MaterialTypeParam = irr::video::pack_textureBlendFunc(irr::video::EBF_SRC_ALPHA, irr::video::EBF_ONE_MINUS_SRC_ALPHA, irr::video::EMFN_MODULATE_1X, irr::video::EAS_VERTEX_COLOR);
// NM.setMaterialTexture(0, device->getVideoDriver()->getTexture("../../media/smoke.bmp"));
// NM.MaterialType = irr::video::EMT_TRANSPARENT_ADD_COLOR; // EMT_TRANSPARENT_VERTEX_ALPHA;
NM.MaterialType = irr::video::EMT_TRANSPARENT_VERTEX_ALPHA;
// NM.ZBuffer = irr::video::ECFN_ALWAYS;
NM.AmbientColor.setAlpha(57);
NM.DiffuseColor.setAlpha(57);
NM.SpecularColor.setAlpha(57);
NM.EmissiveColor.setAlpha(57);
// NM.AmbientColor = irr::video::SColor(0, 0x4F, 0xFC, 0);
// NM.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
// NM.setFlag(EMF_BACK_FACE_CULLING, false);
// NM.setMaterialTexture(0, driver->getTexture("../../media/fire.bmp"));
// NM.setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
// ps->setMaterialFlag(video::EMF_LIGHTING, false);
// setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
lineNode->setMaterial(NM);
lineNode->setColor(SColor(57, 0x4F, 0xFC, 0));
// meshMnp->setVertexColorAlpha(lineNode->getMesh(), 80);
////lineNode->SVertexColorSetAlphaManipulator(127);
// lineNode->setMaterialFlag(video::EMF_LIGHTING, false);
// lineNode->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
lineNode->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
// lineNode->setMaterialFlag( irr::video::EMF_FRONT_FACE_CULLING, false);
// lineNode->setMaterialFlag( irr::video::EMF_BACK_FACE_CULLING, false);
// lineNode->setMaterialFlag(video::EMT_TRANSPARENT_VERTEX_ALPHA, true);
/*
Create our scene node. I don't check the result of calling new, as it
should throw an exception rather than returning 0 on failure. Because
the new node will create itself with a reference count of 1, and then
will have another reference added by its parent scene node when it is
added to the scene, I need to drop my reference to it. Best practice is
to drop it only *after* I have finished using it, regardless of what
the reference count of the object is after creation.
*/
CSampleSceneNode *myNode =
new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);
/*
To animate something in this boring scene consisting only of one
tetrahedron, and to show that you now can use your scene node like any
other scene node in the engine, we add an animator to the scene node,
which rotates the node a little bit.
irr::scene::ISceneManager::createRotationAnimator() could return 0, so
should be checked.
*/
scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(0.8f, 0, 0.8f));
scene::ISceneNodeAnimator* aanim = smgr->createRotationAnimator(core::vector3df(0, 0.3f, 0));
if(anim)
{
myNode->addAnimator(anim);
// lineNode->addAnimator(aanim);
/*
I'm done referring to anim, so must
irr::IReferenceCounted::drop() this reference now because it
was produced by a createFoo() function. As I shouldn't refer to
it again, ensure that I can't by setting to 0.
*/
anim->drop();
aanim->drop();
anim = 0;
aanim = 0;
}
/*
I'm done with my CSampleSceneNode object, and so must drop my reference.
This won't delete the object, yet, because it is still attached to the
scene graph, which prevents the deletion until the graph is deleted or the
custom scene node is removed from it.
*/
myNode->drop();
myNode = 0; // As I shouldn't refer to it again, ensure that I can't
// add sydneys
IAnimatedMesh* mesh = smgr->getMesh( "../../media/sydney.md2");
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
if (node)
{
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMD2Animation(scene::EMAT_STAND);
node->setMaterialTexture( 0, driver->getTexture( "../../media/sydney.bmp") );
}
node->setPosition(vector3df(0, 0, 0) );
/*
Now draw everything and finish.
*/
u32 frames=0;
while(device->run())
{
lineNode->setColor(SColor(127, 0, 0xC0, 0));
// lineNode->setPosition( vector3df(0, 50, 0) );
lineNode->setPosition( vector3df(0, 25, -20) );
//driver->beginScene(irr::video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0,100,100,100));
driver->beginScene( true, true, video::SColor(255,0xFF,0xFF,0xFF));
smgr->drawAll();
driver->endScene();
if (++frames==100) // don't update more often, setWindowCaption can be expensive
{
core::stringw str = L"Irrlicht Engine [";
str += driver->getName();
str += L"] FPS: ";
str += (s32)driver->getFPS();
device->setWindowCaption(str.c_str());
frames=0;
}
}
device->drop();
return 0;
}
Code: Select all
//----------------------------------------------------->
// Copyright 2007 Marcelo Nunes de Sá Vasconcellos
//----------------------------------------------------->
#include "ILineNode.h"
//
ILineNode::ILineNode(core::vector3df center, f32 lheight, f32 lwidth, core::vector3df normal, ISceneNode* parent, ISceneManager* smgr, s32 id):ISceneNode(parent,smgr,id)
{
//
Driver = SceneManager->getVideoDriver();
// Set the color
this->lAlpha = 32;
this->lColor = video::SColor(this->lAlpha, 0, 0xC0, 0);
// Inclui ao parente este node
if(Parent) Parent->addChild(this);
//
updateAbsolutePosition();
createLine(center, lheight, lwidth, normal);
// AutomaticCullingState = EAC_OFF; // _FRUSTUM_BOX;
AutomaticCullingState = irr::scene::EAC_OFF; // _FRUSTUM_BOX; // EAC_BOX
//
// smgr->addMeshSceneNode( this->mesh, smgr->getRootSceneNode() );
smgr->registerNodeForRendering(this);
}
//
void ILineNode::OnRegisterSceneNode()
{
if(IsVisible) SceneManager->registerNodeForRendering(this);
ISceneNode::OnRegisterSceneNode();
}
//
void ILineNode::render()
{
// Prep to render
Driver->setMaterial(Material);
Driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
u16 indices[] = {
0,1,2
,1,2,0
,2,0,1
};
// ,0,1,2
// render
Driver->drawVertexPrimitiveList(&lstVertices[0], lstVertices.size(), &indices[0], 3, irr::video::EVT_STANDARD, irr::scene::EPT_TRIANGLE_FAN, video::EIT_16BIT); // scene::EPT_TRIANGLES
//
// this->mesh->setPosition();
}
//
const core::aabbox3d<f32>& ILineNode::getBoundingBox() const
{
return Box;
}
//
u32 ILineNode::getMaterialCount()
{
return 1;
}
//
// video::SMaterial& ILineNode::getMaterial(u32 i)
// {
// return this->Material;
// }
// Set material alpha
void ILineNode::setMaterialAlpha(u32 iAlpha)
{
this->lAlpha = iAlpha;
// Set the color
this->lColor = video::SColor(this->lAlpha, 0x4F, 0xFC, 0);
}
//
void ILineNode::setMaterial(video::SMaterial newMaterial)
{
this->Material = newMaterial;
}
//
void ILineNode::setColor(video::SColor iColor)
{
// Change color
this->lColor = iColor;
}
//
void ILineNode::createLine(core::vector3df center, f32 lheigth, f32 lwidth, core::vector3df normal)
{
// must optimize.... horrible
u16 indices[] = {
0,1,2
,1,2,0
,2,0,1
};
//
normal.normalize();
//
lstIndices.clear();
lstVertices.clear();
///////////////////////////////////////////////////////
// Mesh buffer
//
scene::SMeshBuffer* buffer = new scene::SMeshBuffer;
//
buffer->Vertices.reallocate(3);
buffer->Indices.set_used((3*3));
//
for (u32 i = 0; i < (3*3); ++i)
{
buffer->Indices[i] = indices[i];
};
//
Box.reset(center);
//
video::S3DVertex Vertices[3];
// sets the color..
// video::SColor color = video::SColor(0x0A, 0, 0xE6, 0);
// Construct the vertices
Vertices[0] = video::S3DVertex(center.X, center.Y, center.Z, 1,1,0, video::SColor(255,0,255,255), 0, 1);
Vertices[0].Color = this->lColor;
Vertices[1].Color.setAlpha(this->lAlpha);
lstVertices.push_back(Vertices[0]);
buffer->Vertices.push_back(Vertices[0]);
lstIndices.push_back(lstVertices.size());
//
Vertices[1] = video::S3DVertex(center.X, center.Y - lheigth, center.Z, 1,1,0, video::SColor(255,0,255,255), 0, 1);
Vertices[1].Color = this->lColor;
Vertices[1].Color.setAlpha(this->lAlpha);
lstVertices.push_back(Vertices[1]);
buffer->Vertices.push_back(Vertices[1]);
lstIndices.push_back(lstVertices.size());
//
Vertices[2] = video::S3DVertex(center.X, center.Y - lheigth, center.Z + lwidth, 1,1,0, video::SColor(255,0,255,255), 0, 1);
Vertices[2].Color = this->lColor;
Vertices[2].Color.setAlpha(this->lAlpha);
lstVertices.push_back(Vertices[2]);
buffer->Vertices.push_back(Vertices[2]);
lstIndices.push_back(lstVertices.size());
// Recalculate bounding box
// buffer->BoundingBox.reset(0, 0, 0);
buffer->BoundingBox.reset(center);
//
for (s32 i=0; i<3; ++i)
{
buffer->BoundingBox.addInternalPoint(buffer->Vertices[i].Pos);
Box.addInternalPoint(Vertices[i].Pos);
}
//
buffer->Material = this->Material;
//
this->mesh = new scene::SMesh;
this->mesh->addMeshBuffer(buffer);
this->mesh->recalculateBoundingBox();
//
buffer->drop();
//
LHeigth = lheigth;
Center = center;
Normal = normal;
}