I have followed the tutorial on creating custom scene nodes and have made a few basic models, but as I started to add more of my own meshes there appear to be weird graphical glitches that appear for a frame occasionally, originating from the center of my node and (seemingly) stretching to infinity.
I managed to catch some in a screenshot:
Heres is my code:
#define ROAD_WIDTH 100 // actually 1/2 road width
class CRoadMesh : public scene::ISceneNode {
core::aabbox3d<f32> Box;
video::S3DVertex Vertices[4];
video::SMaterial Material;
public:
CRoadMesh(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id) : scene::ISceneNode(parent, mgr, id)
{
Material.Wireframe = false;
Material.Lighting = true;
Vertices[0] = video::S3DVertex(0 - ROAD_WIDTH, 1, 0 - ROAD_WIDTH, 0,1,0, video::SColor(255,255,255,255),0,0);
Vertices[1] = video::S3DVertex(ROAD_WIDTH, 1, 0 - ROAD_WIDTH, 0,1,0, video::SColor(255,255,255,255),1,0);
Vertices[2] = video::S3DVertex(0 - ROAD_WIDTH, 1, ROAD_WIDTH, 0,1,0, video::SColor(255,255,255,255),0,1);
Vertices[3] = video::S3DVertex(ROAD_WIDTH, 1, ROAD_WIDTH, 0,1,0, video::SColor(255,255,255,255),1,1);
Box.reset(Vertices[0].Pos);
for (s32 i=1; i<4; ++i)
Box.addInternalPoint(Vertices.Pos);
}
// tints the model red
void SetHighlight(bool HighlightOn)
{
for (int i=0; i<4; i++)
Vertices.Color = video::SColor(255, 255, HighlightOn ? 0 : 255, HighlightOn ? 0 : 255);
}
virtual void OnPreRender(){
if (IsVisible)
SceneManager->registerNodeForRendering(this);
ISceneNode::OnPreRender();
}
virtual void render()
{
u16 indices[] = { 0,2,1, 3,1,2 };
video::IVideoDriver* driver = SceneManager->getVideoDriver();
driver->setMaterial(Material);
driver->setTransform(video::TS_WORLD, AbsoluteTransformation);
driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 6);
}
virtual const core::aabbox3d<f32>& getBoundingBox() const { return Box; }
virtual s32 getMaterialCount() { return 1; }
virtual video::SMaterial& getMaterial(s32 i) { return Material; }
};
Custom scene node glitches
Re: Custom scene node glitches
I think that's the problem:
The last parameter should be 2 instead of 6 I think.Mercior wrote: driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 6);