Irrbox does not render texture

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Irrbox does not render texture

Post by white tiger »

i have an irrbox class is supposed to draw a box and it worked correctly in previous versions. now i have upgraded to 1.5 the irrbox does not render the texture anymore. It ONLY render the vertex colours, not the texture. here is the interface:

Code: Select all

class IrrBox : public scene::ISceneNode, public newton::IrrNewt_Base
{

protected:

   core::aabbox3d<f32> Box;
   video::S3DVertex Vertices[24];
   video::SMaterial Material;

public:

   IrrBox (scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, float x, float y, float z);
   ~IrrBox() {}

   virtual void render();
   virtual const core::aabbox3d<f32>& getBoundingBox() const { return Box; }

    virtual void OnRegisterSceneNode();
    virtual s32 getMaterialCount() { return 1; }
    virtual video::SMaterial& getMaterial(s32 i) { return Material; }

};
here the implementation

Code: Select all

IrrBox::IrrBox (
    scene::ISceneNode* parent,
    scene::ISceneManager* mgr,
    s32 id,
    float x,
    float y,
    float z)
	:scene::ISceneNode(parent, mgr, id)
{

    Material.Wireframe = false;
    Material.Lighting = false;

	x *= 0.5f;
	z *= 0.5f;
	y *= 0.5f;

	core::vector3df loc = core::vector3df(x, 0.0f, 0.0f);
	video::SColor color(255,255,255,255);

    // top
    Vertices[0] = video::S3DVertex(loc.X - x, - y, - z, 0,1,0, color,0,0);
    Vertices[1] = video::S3DVertex(loc.X + x, - y, - z, 0,1,0, color,1,0);
    Vertices[2] = video::S3DVertex(loc.X - x, - y, + z, 0,1,0, color,0,1);
    Vertices[3] = video::S3DVertex(loc.X + x, - y, + z, 0,1,0, color,1,1);

    // bottom
    Vertices[4] = video::S3DVertex(loc.X - x, + y, - z, 0,1,0, color,0,0);
    Vertices[5] = video::S3DVertex(loc.X + x, + y, - z, 0,1,0, color,1,0);
    Vertices[6] = video::S3DVertex(loc.X - x, + y, + z, 0,1,0, color,0,1);
    Vertices[7] = video::S3DVertex(loc.X + x, + y, + z, 0,1,0, color,1,1);

    // < l
    Vertices[8]  = video::S3DVertex(loc.X + x, - y, - z, 0,1,0, color,0,0);
    Vertices[9]  = video::S3DVertex(loc.X + x, + y, - z, 0,1,0, color,1,0);
    Vertices[10] = video::S3DVertex(loc.X + x, - y, + z, 0,1,0, color,0,1);
    Vertices[11] = video::S3DVertex(loc.X + x, + y, + z, 0,1,0, color,1,1);

    // > r
    Vertices[12] = video::S3DVertex(loc.X - x, - y, - z,      0,1,0,  color,0,0);
    Vertices[13] = video::S3DVertex(loc.X - x, + y, - z,      0,1,0,  color,1,0);
    Vertices[14] = video::S3DVertex(loc.X - x, - y, + z,      0,1,0,  color,0,1);
    Vertices[15] = video::S3DVertex(loc.X - x, + y, + z,      0,1,0,  color,1,1);

    // ^ u
    Vertices[16] = video::S3DVertex(loc.X - x, - y, + z,      0,1,0,  color,0,0);
    Vertices[17] = video::S3DVertex(loc.X - x, + y, + z,      0,1,0,  color,1,0);
    Vertices[18] = video::S3DVertex(loc.X + x, - y, + z,      0,1,0,  color,0,1);
    Vertices[19] = video::S3DVertex(loc.X + x, + y, + z,      0,1,0,  color,1,1);

    // v d
    Vertices[20] = video::S3DVertex(loc.X - x, - y, - z,      0,1,0,  color,0,0);
    Vertices[21] = video::S3DVertex(loc.X - x, + y, - z,      0,1,0,  color,1,0);
    Vertices[22] = video::S3DVertex(loc.X + x, - y, - z,      0,1,0,  color,0,1);
    Vertices[23] = video::S3DVertex(loc.X + x, + y, - z,      0,1,0,  color,1,1);

    Box.reset(Vertices[0].Pos);
	for (s32 i=1; i<24; ++i)  {
        Box.addInternalPoint(Vertices[i].Pos);
	}
}

void IrrBox::OnRegisterSceneNode() {
	if (IsVisible)
                    SceneManager->registerNodeForRendering(this);
      ISceneNode::OnRegisterSceneNode();
}

void IrrBox::render()
{
    u16 indices[] = { 0,1,2, 3,2,1, 4,6,5, 7,5,6, 8,9,10, 11,10,9, 12,14,13, 15,13,14, 16,18,17, 19,17,18, 20,21,22, 23,22,21 };

    video::IVideoDriver* driver = SceneManager->getVideoDriver();
    driver->setMaterial(Material);
    driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
    driver->drawIndexedTriangleList(&Vertices[0], 24, &indices[0], 12); // 12 ind
}
here how i use it

Code: Select all

spine0_Bone = (IAnimatedMeshSceneNode*)new IrrBox(smgr->getRootSceneNode(), smgr, 666, spineSize.X, spineSize.Y, spineSize.Z);
	if(texture != NULL)
	{
		spine0_Bone->setMaterialTexture(0, texture);
		spine0_Bone->setMaterialFlag(video::EMF_LIGHTING, false);
	}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

This wouldn'T work with Irrlicht 1.4 either, because the method signatures changed. Please read the upgrade_guide.txt for all such changes (you usually need to do this if you have custom scene nodes). In your case make the methods use u32 (MaterialCount and index in getMaterial) and make getMaterialCount a const method.
Post Reply