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) {};
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