Esempio n. 1
0
void PolygonNode::calcFillVertexes(const VertexDataPtr& pVertexData, Pixel32 color)
{
    if (getNumDifferentPts(m_Pts) < 3) {
        return;
    }
    // Remove duplicate points
    vector<glm::vec2> pts;
    vector<unsigned int> holeIndexes;
    pts.reserve(m_Pts.size());

    if (glm::distance2(m_Pts[0], m_Pts[m_Pts.size()-1]) > 0.1) {
        pts.push_back(m_Pts[0]);
    }
    for (unsigned i = 1; i < m_Pts.size(); ++i) {
        if (glm::distance2(m_Pts[i], m_Pts[i-1]) > 0.1) {
            pts.push_back(m_Pts[i]);
        }
    }

    if (m_Holes.size() > 0) {
        for (unsigned int i = 0; i < m_Holes.size(); i++) { //loop over collection
            holeIndexes.push_back(pts.size());
            for (unsigned int j = 0; j < m_Holes[i].size(); j++) { //loop over vector
                pts.push_back(m_Holes[i][j]);
            }
        }
    }
    if (color.getA() > 0) {
        glm::vec2 minCoord = pts[0];
        glm::vec2 maxCoord = pts[0];
        for (unsigned i = 1; i < pts.size(); ++i) {
            if (pts[i].x < minCoord.x) {
                minCoord.x = pts[i].x;
            }
            if (pts[i].x > maxCoord.x) {
                maxCoord.x = pts[i].x;
            }
            if (pts[i].y < minCoord.y) {
                minCoord.y = pts[i].y;
            }
            if (pts[i].y > maxCoord.y) {
                maxCoord.y = pts[i].y;
            }
        }
        vector<unsigned int> triIndexes;
        triangulatePolygon(triIndexes, pts, holeIndexes);

        for (unsigned i = 0; i < pts.size(); ++i) {
            glm::vec2 texCoord = calcFillTexCoord(pts[i], minCoord, maxCoord);
            pVertexData->appendPos(pts[i], texCoord, color);
        }
        for (unsigned i = 0; i < triIndexes.size(); i+=3) {
            pVertexData->appendTriIndexes(triIndexes[i], triIndexes[i+1], 
                    triIndexes[i+2]);
        }
    }
}
Esempio n. 2
0
void GLShaderParamTemplate<Pixel32>::uniformSet(unsigned location, const Pixel32& val)
{
    glproc::Uniform4f(location, val.getR()/255.f, val.getG()/255.f, val.getB()/255.f,
            val.getA()/255.f);
}