draw2DFilledPolygon and draw2DPolygon
I use them to draw polygons in gui elements.
Currently it works only with opengl driver ( I don't know directX ).
Suggestions and a directX version would be appreciated.
Just add next code to IVideoDriver.h, CNullDriver.h, COpenGLDriver.h
Code: Select all
...
//! Draws a filled 2d polyon.
/** This method can be used to draw a generic filled polygon.
It uses the color stored in S3DVertex to hue the polygon
\param vertices: Array of S3DVertex that stores the polygon vertices.
\param verticesCount: The number of vertices to draw.
*/
virtual void draw2DFilledPolygon(const S3DVertex* vertices, int verticesCount ) = 0;
//! Draws a non filled generic 2d polyon.
/** This method can be used to draw a generic non filled 2D polygon.
It uses the passed color to hue the polygon.
S3DVertex.Color is ignored.
\param vertices: Array of S3DVertex that stores the polygon vertices.
\param verticesCount: The number of vertices to draw.
*/
virtual void draw2DPolygon(const S3DVertex* vertices, int verticesCount ) = 0;
...
Just add next code to CNullDriver.cpp
Code: Select all
void CNullDriver::draw2DFilledPolygon(const S3DVertex* vertices, int count )
{
PrimitivesDrawn += 1;
}
void CNullDriver::draw2DPolygon(const S3DVertex* vertices, int count )
{
PrimitivesDrawn += 1;
}
Code: Select all
void COpenGLDriver::draw2DFilledPolygon(const S3DVertex* vertices, int count )
{
setRenderStates2DMode(true, false, false);
setTexture(0,0);
core::dimension2d<s32> currentRendertargetSize = getCurrentRenderTargetSize();
const s32 xPlus = -(currentRendertargetSize.Width>>1);
const f32 xFact = 1.0f / (currentRendertargetSize.Width>>1);
const s32 yPlus =
currentRendertargetSize.Height-(currentRendertargetSize.Height>>1);
const f32 yFact = 1.0f / (currentRendertargetSize.Height>>1);
glBegin(GL_POLYGON);
for( int i = 0; i < count; i++ )
{
glColor4ub( vertices[i].Color.getRed(), vertices[i].Color.getGreen(), vertices[i].Color.getBlue(), vertices[i].Color.getAlpha() );
glVertex2f(
(f32)( vertices[i].Pos.X + xPlus) * xFact,
(f32)(yPlus - vertices[i].Pos.Y) * yFact
);
}
glEnd();
}
void COpenGLDriver::draw2DPolygon(const S3DVertex* vertices, int count )
{
setRenderStates2DMode(true, false, false);
setTexture(0,0);
core::dimension2d<s32> currentRendertargetSize = getCurrentRenderTargetSize();
const s32 xPlus = -(currentRendertargetSize.Width>>1);
const f32 xFact = 1.0f / (currentRendertargetSize.Width>>1);
const s32 yPlus =
currentRendertargetSize.Height-(currentRendertargetSize.Height>>1);
const f32 yFact = 1.0f / (currentRendertargetSize.Height>>1);
glBegin(GL_LINE_LOOP);
for( int i = 0; i < count; i++ )
{
glColor4ub( vertices[i].Color.getRed(), vertices[i].Color.getGreen(), vertices[i].Color.getBlue(), vertices[i].Color.getAlpha() );
glVertex2f(
(f32)( vertices[i].Pos.X + xPlus) * xFact,
(f32)(yPlus - vertices[i].Pos.Y) * yFact
);
}
glEnd();
}
PS: USE IT AT YOUR OWN RISK!