[SOLVED] DrawVertexPrimitiveList not working

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
ItsBritneyBitch
Posts: 18
Joined: Mon Apr 16, 2012 5:04 pm
Location: Calabasas, CA
Contact:

[SOLVED] DrawVertexPrimitiveList not working

Post by ItsBritneyBitch »

Hi everyone, here's a code snippet used to render a cube adapted from a DirectX sample, but it doesn't work with Irrlicht using either (DX or OpenGL) drivers:

Code: Select all

 
        irr::video::S3DVertex vertices[8] =
        {
                irr::video::S3DVertex(vector3df(-30.0f, 30.0f, -30.0f), vector3df(), SColor(255, 0, 0, 255), vector2df()),
                irr::video::S3DVertex(vector3df(30.0f, 30.0f, -30.0f), vector3df(), SColor(255, 0, 255, 0), vector2df()),
                irr::video::S3DVertex(vector3df(-30.0f, -30.0f, -30.0f), vector3df(), SColor(255, 255, 0, 0), vector2df()),
                irr::video::S3DVertex(vector3df(30.0f, -30.0f, -30.0f), vector3df(), SColor(255, 0, 255, 255), vector2df()),
                irr::video::S3DVertex(vector3df(-30.0f, 30.0f, 30.0f), vector3df(), SColor(255, 0, 0, 255), vector2df()),
                irr::video::S3DVertex(vector3df(30.0f, 30.0f, 30.0f), vector3df(), SColor(255, 255, 0, 0), vector2df()),
                irr::video::S3DVertex(vector3df(-30.0f, -30.0f, 30.0f), vector3df(), SColor(255, 0, 255, 0), vector2df()),
                irr::video::S3DVertex(vector3df(30.0f, -30.0f, 30.0f), vector3df(), SColor(255, 0, 255, 255), vector2df())
        };
        int indices[36] =
        {
                0, 1, 2,    // side 1
                2, 1, 3,
                4, 0, 6,    // side 2
                6, 0, 2,
                7, 5, 6,    // side 3
                6, 5, 4,
                3, 1, 7,    // side 4
                7, 1, 5,
                4, 5, 0,    // side 5
                0, 5, 1,
                3, 7, 2,    // side 6
                2, 7, 6,
        };
        driver->drawVertexPrimitiveList(&vertices[0], 8, &indices[0], 12, irr::video::EVT_STANDARD, irr::scene::EPT_TRIANGLES);
 
This shows some random triangles being rendered, but it's like it doesn't follow the index order :x
What's funny, this function never works as its supposed to, and given the poor documentation (in particular regarding the 4th parameter) this is driving me nuts.
Help anyone?
Last edited by ItsBritneyBitch on Sun Jun 24, 2012 1:54 am, edited 3 times in total.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: drawVertexPrimitiveList not working

Post by hybrid »

I guess it's the winding order, but didn't check this actually. Just make sure that all your tris are properly oriented. Since you also don't pass normals make sure that lighting is turned off.
ItsBritneyBitch
Posts: 18
Joined: Mon Apr 16, 2012 5:04 pm
Location: Calabasas, CA
Contact:

Re: drawVertexPrimitiveList not working

Post by ItsBritneyBitch »

Got it working now. I was using int as the type for the indices, which is 32 bits instead of u16, which is the format (EIT_16BIT) specified by default. I changed the index array declaration to

Code: Select all

u16 indices[36]
and it works like a charm now. I could also have changed the 7th parameter to EIT_32BIT, if I wanted to have more than 65536 indices.
hybrid wrote:I guess it's the winding order, but didn't check this actually. Just make sure that all your tris are properly oriented. Since you also don't pass normals make sure that lighting is turned off.
Thanks anyway for your reply. I was aware i was setting the normals to 0 because i wasn't particularly caring about the lighting. Regarding the winding order, it's correct, and I think Irrlicht is using the same winding order convention as DirectX (not sure if it is CW or CCW) for backface culling, because these indices where taken from a DX sample using default settings.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: [SOLVED] DrawVertexPrimitiveList not working

Post by hybrid »

Yeah, same winding order as in DirectX. I also have to check for the correct order from time to time. IIRC, it's clock-wise.
Post Reply