Esempio n. 1
0
bool StGLFontEntry::renderGlyph(StGLContext&    theCtx,
                                const bool      theToDrawUndef,
                                const stUtf32_t theUChar,
                                const stUtf32_t theUCharNext,
                                StGLTile&       theGlyph,
                                StGLVec2&       thePen) {
    std::map<stUtf32_t, size_t>::const_iterator aTileIter = myGlyphMap->find(theUChar);
    size_t aTileId;
    if(aTileIter != myGlyphMap->end()) {
        aTileId = aTileIter->second;
    } else if(renderGlyph(theCtx, theUChar, false)) {
        aTileId = myLastTileId;
        (*myGlyphMap)[theUChar] = aTileId;
    } else if(!theToDrawUndef) {
        return false;
    } else {
        aTileIter = myGlyphMap->find(0);
        if(aTileIter != myGlyphMap->end()) {
            aTileId = aTileIter->second;
        } else if(renderGlyph(theCtx, theUChar, true)) {
            aTileId = myLastTileId;
            (*myGlyphMap)[theUChar] = aTileId;
        } else {
            thePen.x() += myFont->getAdvanceX(theUChar, theUCharNext);
            return false;
        }
    }

    const StGLTile& aTile = myTiles[aTileId];
    StGLRect aRect(thePen.y() + aTile.px.top(),  thePen.y() + aTile.px.bottom(),
                   thePen.x() + aTile.px.left(), thePen.x() + aTile.px.right());
    theGlyph.px      = aRect;
    theGlyph.uv      = aTile.uv;
    theGlyph.texture = aTile.texture;

    thePen.x() += myFont->getAdvanceX(theUChar, theUCharNext);
    return true;
}
Esempio n. 2
0
void StGLImageProgram::setTextureSizePx(StGLContext&    theCtx,
                                        const StGLVec2& theVec2) {
    theCtx.core20fwd->glUniform2fv(uniTexSizePxLoc, 1, theVec2);
    theCtx.core20fwd->glUniform2f(uniTexelSizePxLoc, 1.0f / theVec2.x(), 1.0f / theVec2.y());
}
Esempio n. 3
0
void StGeometryTest::resizeGrid(const StRectI_t& winRectPx) {
    StGLContext& aCtx = getContext();

    // grid
    size_t linesCountV = 16 + 1;
    size_t cellSizePx  = 10;
    size_t linesCountH = 16 + 1;

    if(winRectPx.width() > winRectPx.height()) {
        cellSizePx = winRectPx.width() / (linesCountV - 1);
        linesCountH = (winRectPx.height() / cellSizePx) + 1;
    } else {
        cellSizePx = winRectPx.height() / (linesCountH - 1);
        linesCountV = (winRectPx.width() / cellSizePx) + 1;
    }

    myCellSize.x() = 2.0f * GLfloat(cellSizePx) / GLfloat(winRectPx.width());
    myCellSize.y() = 2.0f * GLfloat(cellSizePx) / GLfloat(winRectPx.height());

    size_t vertixesCount = (linesCountH + linesCountV) * 2;
    StArray<StGLVec4> vertArray(vertixesCount);

    // insert black gap to make quads
    StGLVec2 blackGap(GLfloat(winRectPx.width()  - cellSizePx * (linesCountV - 1)) / GLfloat(winRectPx.width()),
                      GLfloat(winRectPx.height() - cellSizePx * (linesCountH - 1)) / GLfloat(winRectPx.height()));

    StGLVec2 bottomLeft = StGLVec2(-1.0f) + blackGap;
    StGLVec2 fat = StGLVec2( 2.0f) - blackGap * 2.0f;

    // horizontal lines
    for(size_t lineId = 0; lineId < linesCountH; ++lineId) {
        GLfloat anY = bottomLeft.y() + fat.y() * (GLfloat(lineId) / GLfloat(linesCountH - 1));
        vertArray[2 * lineId]     = StGLVec4(-1.0f, anY, 0.0f, 1.0f);
        vertArray[2 * lineId + 1] = StGLVec4( 1.0f, anY, 0.0f, 1.0f);
    }

    // vertical lines
    for(size_t lineId = 0; lineId < linesCountV; ++lineId) {
        GLfloat anX = bottomLeft.x() + fat.x() * (GLfloat(lineId) / GLfloat(linesCountV - 1));
        vertArray[2 * linesCountH + 2 * lineId]     = StGLVec4(anX, -1.0f, 0.0f, 1.0f);
        vertArray[2 * linesCountH + 2 * lineId + 1] = StGLVec4(anX,  1.0f, 0.0f, 1.0f);
    }

    myGrid.changeVBO(ST_VBO_VERTEX)->init(aCtx, vertArray);

    // white color
    StArray<StGLVec4> lColorsArray(vertixesCount, StGLVec4(1.0f));
    myGrid.changeVBO(ST_VBO_COLORS)->init(aCtx, lColorsArray);

    // bottom left circle
    myCircles[0].create(StGLVec3(bottomLeft + myCellSize),
                        myCellSize.x(), myCellSize.y(), 64);
    // bottom right circle
    myCircles[1].create(StGLVec3(bottomLeft + myCellSize * StGLVec2(GLfloat(linesCountV - 2), 1.0f)),
                        myCellSize.x(), myCellSize.y(), 64);
    // top left circle
    myCircles[2].create(StGLVec3(bottomLeft + myCellSize * StGLVec2(1.0f, GLfloat(linesCountH - 2))),
                        myCellSize.x(), myCellSize.y(), 64);
    // top right circle
    myCircles[3].create(StGLVec3(bottomLeft + myCellSize * StGLVec2(GLfloat(linesCountV - 2), GLfloat(linesCountH - 2))),
                        myCellSize.x(), myCellSize.y(), 64);
    // center circle
    GLfloat minSize = 0.5f * (((linesCountV < linesCountH) ? linesCountV : linesCountH) - 1);
    myCircles[4].create(StGLVec3(0.0f),
                        myCellSize.x() * minSize, myCellSize.y() * minSize, 64);
    // white color
    for(size_t aCircleId = 0; aCircleId < 5; ++aCircleId) {
        myCircles[aCircleId].computeMesh();
        myCircles[aCircleId].initColorsArray(StGLVec4(1.0f));
        myCircles[aCircleId].initVBOs(aCtx);
    }
}