Custom Scene Node - Nothing rendering?

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.
Post Reply
frost_bite
Posts: 28
Joined: Wed Dec 03, 2008 11:42 pm

Custom Scene Node - Nothing rendering?

Post by frost_bite »

I have a custom scene node that is supposed to render a triangle. However, when the render function is called nothing is drawn. I have probably messed something simple up, but I can't figure out what.

What could I be doing wrong in the following code?

Thanks beforehand to anyone who helps me =)

[Header]

Code: Select all

class ICustomSceneNode: public ISceneNode {
public:
	ICustomSceneNode(
        ISceneManager* sceneManager,
        ISceneNode* parent = NULL,
        s32 id = -1
    );

	virtual ~ICustomSceneNode();
	virtual void OnRegisterSceneNode();
	virtual void OnAnimate(u32 timeMs);
	virtual void render();
	virtual const aabbox3df& getBoundingBox() const;
	virtual u32 getMaterialCount();
	virtual SMaterial& getMaterial(u32 i);
private:
	IVideoDriver* VideoDriver;
	ISceneManager* SceneManager;
};
[Source]

Code: Select all

ICustumSceneNode::ICustumSceneNode(
    ISceneManager* sceneManager,
    ISceneNode* parent,
    s32 id
    ) : ISceneNode(parent ? parent : sceneManager->getRootSceneNode(), sceneManager, id), SceneManager(sceneManager) {
	VideoDriver = SceneManager->getVideoDriver();
}

ICustumSceneNode::~ICustumSceneNode() {}

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

void ICustumSceneNode::OnAnimate(u32 timeMs) {
	if (IsVisible) { }
	ISceneNode::OnAnimate(timeMs);
}

void ICustumSceneNode::render() {
    Driver->setTransform(ETS_WORLD, AbsoluteTransformation);

    S3DVertex vertices[3] = {
        S3DVertex(vector3df(0.0f, 0.0f, 0.0f), vector3df(0.0f, 1.0f, 0.0f), SColor(255, 255, 255, 255), vector2df(0.0f, 0.0f)),
        S3DVertex(vector3df(1000.0f, 0.0f, 0.0f), vector3df(0.0f, 1.0f, 0.0f), SColor(255, 255, 255, 255), vector2df(0.0f, 0.0f)),
        S3DVertex(vector3df(1000.0f, 0.0f, 1000.0f), vector3df(0.0f, 1.0f, 0.0f), SColor(255, 255, 255, 255), vector2df(0.0f, 0.0f)),
    };

    u16 indeces[3] = {0, 1, 2};

    Driver->drawIndexedTriangleList(
            &vertices[0],
            3,
            &indeces[0],
            1
        );
}
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

It's quite possible that you've fallen victim to backface culling. Basically, backface culling checks if your points are being drawn in a clockwise or counter-clockwise manner. If they are being drawn in the opposite order than what is expected (I think counter-clockwise is the "front face" in Irrlicht - I don't remember at the moment) and backface culling is enabled, the renderer doesn't draw the triangles.

This is usually a good thing since it doesn't draw the "backs" or "insides" of a model, which usually improves performance, but if your indices are in the wrong order your triangles won't draw.

Try setting the material flag EMF_BACK_FACE_CULLING to false and see if your triangle magically shows up. If it does, all you have to do is reorder your indices.
Last edited by slavik262 on Thu Feb 25, 2010 4:25 pm, edited 1 time in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Maybe you should try to compile your code. Will show up approx. 193 errors. But that's only an approximation
Just a few: You lack several method implementations. The class name is different to the implementation's name. Some method signatres are wrong and won't properly overload.
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

hybrid wrote:Maybe you should try to compile your code. Will show up approx. 193 errors. But that's only an approximation
Just a few: You lack several method implementations. The class name is different to the implementation's name. Some method signatres are wrong and won't properly overload.
My answer was assuming he has the thing compiled and running and his post was some horrible result of typing the code into the forums instead of just doing a copy/paste.
frost_bite
Posts: 28
Joined: Wed Dec 03, 2008 11:42 pm

Post by frost_bite »

Thank you very much! Backface culling seems to have been the problem!
frost_bite
Posts: 28
Joined: Wed Dec 03, 2008 11:42 pm

Post by frost_bite »

ugh, now when I try to texture it the polygon it is displayed a dull shade of grey. I have the material type set to EMT_SOLID and have lighting disabled. The texture coordinates are correct.

Any idea what I am doing wrong?

Code: Select all

    SMaterial material;
    material.setTexture(0, Driver->getTexture("data/texture.jpg"));
    material.MaterialType = EMT_SOLID;
    material.Wireframe = false;
    material.Lighting = false;

    Driver->setMaterial(material);
    S3DVertex vertices[4] = {
        S3DVertex(
            vector3df(0, 0, 0),
            vector3df(0.0f, 1.0f, 0.0f),
            SColor(255, 255, 255, 255),
            vector2df(0.0f, 0.0f)
        ),
        S3DVertex(
            vector3df(10, 0, 0),
            vector3df(0.0f, 1.0f, 0.0f),
            SColor(255, 255, 255, 255),
            vector2df(1.0f, 0.0f)
        ),
        S3DVertex(
            vector3df(10, 0, 10),
            vector3df(0.0f, 1.0f, 0.0f),
            SColor(255, 255, 255, 255),
            vector2df(1.0f, 1.0f)
        ),
        S3DVertex(
            vector3df(0, 0, 10),
            vector3df(0.0f, 1.0f, 0.0f),
            SColor(255, 255, 255, 255),
            vector2df(0.0f, 10.0f)
        ),
    };

    u16 indeces[6] = {2, 1, 0, 0, 3, 2};

    Driver->drawIndexedTriangleList(
        &vertices[0],
        4,
        &indeces[0],
        2
    );
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

Not off the top of my head, but your last texture coordinate is (0, 10), not (0, 1).
frost_bite
Posts: 28
Joined: Wed Dec 03, 2008 11:42 pm

Post by frost_bite »

If I set the material type to "EMT_TRANSPARENT_ALPHA_CHANNEL" it disappears and if I set it to "EMT_TRANSPARENT_ALPHA_CHANNEL_REF" it half appears. :roll:

This is what it looks like (the background is red to help contrast the issue):
Image
Post Reply