At the moment it just fills with a color, but I'm extending it to fill with textures as well. I just need to get my rotateTexture function working (nearly done).
When I fill the polygons, it works perfectly.
When I draw the border it works perfectly.
But if I draw the border and fill the polygon then I get some white pixels near some edges.
There are never any holes when the edge is axis aligned.
But for polygons with sloping edges, some pixels are missing. Approximately 1 pixel away from the edge, and always on the right side.
I draw lines from left to right after working out the intersection points using a version of pointInPolygon test for each Y value (row) of the height of the polygon.
Damn. Where can I get a URL for free to upload some images? Then I could show them.
I can show the fill code, but do I need to? It works.
This is the boundary drawing code:
Code: Select all
//! Now draw the border.
irr::core::array<SVertex2d<irr::f32>> const & vertices = this->getVertices();
//! each vertex must be offset by the destination minus the upperleft position of bounds box.
irr::core::vector2di drawOffset(ptDest - sBoundsBox.UpperLeftCorner);
irr::core::vector2di startPoint, endPoint;
irr::u32 startIndex = this->getVertexCount() - 1; // start with the line from last vertex to first vertex
startPoint.X = irr::core::round32(vertices[startIndex].Vertex.X) + drawOffset.X;
startPoint.Y = irr::core::round32(vertices[startIndex].Vertex.Y) + drawOffset.Y;
for (irr::u32 index = 0; index < this->getVertexCount(); ++index)
{
//! Note: if only 2 vertices, it draws the line twice.
//! If only 1 vertex, does not get drawn.
endPoint.X = irr::core::round32(vertices[index].Vertex.X) + drawOffset.X;
endPoint.Y = irr::core::round32(vertices[index].Vertex.Y) + drawOffset.Y;
pVideoDriver->draw2DLine(startPoint, endPoint, this->getColor());
//! end point becomes the start point
startPoint = endPoint;
}
//! fill the polygon with it's color.
this->fill(pVideoDriver, ptDest, this->getColor(), clipRect);
It draws horizontal lines between internal edges of the polygon.
If my 2 drawing routines are correct, is there something I am not considering?