Feature Request: more flexible 2d drawing function

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
hiker
Posts: 58
Joined: Thu May 31, 2007 5:12 am

Feature Request: more flexible 2d drawing function

Post by hiker »

Hi,

for SuperTuxKart (which we are currently porting to irrlicht) we need more flexible 2d drawing functions - it could be low level (draw an arbitrary 2d triangle with colours for each vertex and/or texture), or higher level (draw an arbitrary convex polygon, again with colours for each vertex and/or a texture).

Example: we need filled regular polygons - the existing function to draw a 2D polygon does not allow filling (and other examples).

I have written a new draw2DPolygon function for OpenGL, and am happy to supply this. It takes arrays of vertices, colours, and/or a texture and texture coordinates. Interface (atm):

Code: Select all

                //! Draws a filled convex 2d polyon.
                /** This method can be used to draw (approximated) circles
                etc., but also any convex 2d polygon.
                \param vertices The vertices of the polygon.
                \param colors The color for each vertex. If less colors are
                specified than there are vertices, color[0] is used!
                So to fill a polygon with one colour, you only have to
                specify a 1-element array. If NULL, no colour values
                are set.
                \param texture A texture to apply to the polygon (optional).
                \param coordinates Texture coordinates for the polygon (only
                used if a texture is specified). 
                \param useAlphaChannelOfTexture True if alpha channels
                of the texture should be used. */
                virtual void draw2DPolygon(const core::array<core::vector2df> &vertices,
                           const core::array<video::SColor> *colors=NULL,
                           const video::ITexture *texture=NULL,
                           const core::array<core::vector2di> *coordinates=NULL,
                           bool useAlphaChannelOfTexture=false) {};

Example usage (not complete):

Code: Select all

        core::array<core::vector2df> vertices;
        // Create a regular polygon with the given center, and put
        // the vertices into the vertex array.
        createRegularPolygon(count, (float)radius, center, &vertices);

        video::SColor color = kp->getColor();  // get the colour of the kart
        core::array<video::SColor> colors;
        // All vertices are the same color, so the color array
        // needs only to have one element.
        colors.push_back(color);
        irr_driver->getVideoDriver()->draw2DPolygon(vertices, &colors);

But I have no idea about directX or any of the other drivers. Or would you prefer a more low level approach of only drawing an arbitrary 2D triangle - it's obviously easy (at least for my applications) to map a polygon into a set of triangles; or use a 3-element polygon for a triangle :) If we agree on an interface, I can probably do the OpenGL implementation.

Having this function in the video driver allows to reuse functions such as setRenderStates2DModel (which are private).

We would really like to get a feature like the above into the next release, since we need it for our next SuperTuxKart release (the first one to use irrlicht).

Feedback welcome!
Joerg
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

I've added a 2d variant of the drawVertexPrimitiveList method instead. You can use it almost as the 3d version. Simply pass the vertex and index pointers of a meshbuffer (or some general array) to this method, together with the interpretation values. You must use a z coord of 0, and you can set the texture to use via setMaterial in advance.
Some caveats of this method: Most settings of setMaterial are not honored, basically it's just used to set the texture. And the software drivers don't support this method. However, it will be used for things like VBO GUIs and the non-fixed function pipeline drivers (such as DirectX10/11 and OpenGL 3.2/ES 2.0). I hope this allows for the necessary functionality.
hiker
Posts: 58
Joined: Thu May 31, 2007 5:12 am

Post by hiker »

hybrid wrote:I've added a 2d variant of the drawVertexPrimitiveList method instead.
Thanks a lot - sounds good, I'll try this function. It should do all we need.

Cheers,
Joerg

PS: Sorry for the long delay in answering, I didn't get a notification about this answer, even though I have notification enabled in my profile.
Virion
Competition winner
Posts: 2148
Joined: Mon Dec 18, 2006 5:04 am

Post by Virion »

hiker wrote:
hybrid wrote:I've added a 2d variant of the drawVertexPrimitiveList method instead.
Thanks a lot - sounds good, I'll try this function. It should do all we need.

Cheers,
Joerg

PS: Sorry for the long delay in answering, I didn't get a notification about this answer, even though I have notification enabled in my profile.
afaik the notification system doesn't work
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

That's why we always ask for submission of tickets on the Bug or Feature Request Trackers: http://sourceforge.net/tracker/?group_id=74339
If you log in to SF before submitting a ticket you will get a notice for all updates made to the ticket.
Post Reply