[fixed]Problem with filling a polygon

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

[fixed]Problem with filling a polygon

Post by teto »

Hello,

I'm just beginning with irrlicht and I may be wrong in reporting this as a bug ( maybe it's my fault ).

I have a convex polygon that doesn't appear at all ( or get filled) when using drawVertexPrimitives with EPT_polygon ( renderer opengl ). With EPT_LINE_LOOP i can clearly see the summits.

And when I told myself to try with triangle fans, my program crashes.

Here is some code betwenn begin and endscene.

Code: Select all

video::S3DVertex vertices[6];
    //vertices[0].TCoords = core::vector2df(1.0f, 1.0f);
    vertices[0].Pos = core::vector3df(0.f,0.f,-40);
    vertices[1].Pos = core::vector3df(0,20,0.1);
    vertices[2].Pos = core::vector3df(3,25,0.1);
    vertices[3].Pos = core::vector3df(100,25,0.1);
    vertices[4].Pos = core::vector3df(100,5,0.1);
    vertices[5].Pos = core::vector3df(97,0,0.1);

    short int index[7];
    for(unsigned int i=0; i<6; i++)
    {
        index[i]=i;
        vertices[i].Color = video::SColor(255, 255, 255, 255);
    }
    index[6] = 0;


    driver->draw2DVertexPrimitiveList  ( vertices,
      6,//6 vertices
      index,//const void *  indexList,
      7,//u32  primCount, unsure about this parameter
      EVT_STANDARD,
        scene::EPT_POLYGON // bug with EPT_TRIANGLE_FAN
     );
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, you need to send in a proper primCount, which means the number of primitives you send. For lines, this is the number of line segments. The triangles primitives require the count of triangles you want to render, for polygons it should probably be 1. However, this always depends on your index setup (maybe without for polygons).
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Post by teto »

Still not working :'(

I have checked the irrlicht code and draw2DVertexPrimitiveList calls RenderArray which calls:

Code: Select all

		case scene::EPT_TRIANGLES:
			glDrawElements(GL_TRIANGLES, primitiveCount*3, indexSize, indexList);
			break;
		case scene::EPT_QUADS:
			glDrawElements(GL_QUADS, primitiveCount*4, indexSize, indexList);
			break;
		case scene::EPT_POLYGON:
			glDrawElements(GL_POLYGON, primitiveCount, indexSize, indexList);
			break;
Here we can see I have to set primCount to 6 in case of the polygon otherwise opengl won't be able to know the size of my indices table ( aka indexList, indexSize tells wether I am using GL_UNSIGNED_INT or GL_UNSIGNED_SHORT ).

any idea ?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ah yes, that looks correct. Did you try with the FPS cam and backface culling off to make sure that your polygon is not culled away?
teto
Posts: 159
Joined: Thu Dec 03, 2009 9:37 pm
Location: /home
Contact:

Post by teto »

Ok this was something I had thought but forgot. I've reordered in counter-clockwise order my indices and it works but just to make sure:
how to disable backface culling ? ( couldn't find it )

btw I thank you for your help. This forum is one among many advantages that incited me to choose irrlicht over other engines and I'm - for the moment - very happy of this choice ^^


EDIT: I would like to ask also how to make my drawn primitives transparent. I have correctly set the vertices alpha value but even though it isn't transparent. Should I enable transparency somewhere ?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Please go through the examples, they explain most of this stuff. You have to change the material type to vertex alpha. The backface culling switch is in SMaterial.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

By looking at Teto's code I learnt something about draw2DVertexPrimitiveList.

@hybrid
My other post about draw2DVertexPrimitiveList was premature! lol.

I realized (by looking at the implementation), that when drawing with draw2DvertexPrimitiveList, we can first call setMaterial, to set a texture.

The vertex primitive list will be filled with that texture/material will it?

The Vertices can hold a color, if using S3DVertex or S2DVertex, so it will also use those colors to fill? Like a gradient?
Or does it just color the boundary lines with the vertex colors?

One extra question.
Why does S2DVertex have a color represented by u16, whereas S3DVertex uses SColor?
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
Post Reply