Exemplo n.º 1
0
NP::Texture
SDL2Renderer::text(const NP::Font &font, const char *text, int rgb)
{
    if (strlen(text) == 0) {
        return NP::Texture(new GLTextureData(nullptr, 10, 10));
    }

    SDLFontData *data = static_cast<SDLFontData *>(font.get());

    int r = (Uint8)((rgb >> 16) & 0xff);
    int g = (Uint8)((rgb >> 8) & 0xff);
    int b = (Uint8)((rgb) & 0xff);

    union {
        Uint32 value;
        SDL_Color color;
    } fg;

    fg.value = SDL_MapRGB(m_pixelformat, r, g, b);

    SDL_Surface *surface = TTF_RenderUTF8_Blended(data->m_font, text, fg.color);
    NP::Texture result = GLRenderer::load((unsigned char *)surface->pixels,
                                          surface->w, surface->h);
    SDL_FreeSurface(surface);

    return result;
}
Exemplo n.º 2
0
void
SDL2Renderer::metrics(const NP::Font &font, const char *text, int *width, int *height)
{
    SDLFontData *data = static_cast<SDLFontData *>(font.get());

    TTF_SizeUTF8(data->m_font, text, width, height);
}
Exemplo n.º 3
0
void
SDLSTBRenderer::metrics(const NP::Font &font, const char *text, int *width, int *height)
{
    EmscriptenFontData *data = static_cast<EmscriptenFontData *>(font.get());

    Blob *blob = Config::readBlob(data->filename);
    StbLoader_RGBA *rgba = StbLoader::render_font(blob->data, blob->len,
            StbLoader_Color(0.f, 0.f, 0.f, 1.f), data->size, text);
    *width = rgba->w;
    *height = rgba->h;
    delete rgba;
    delete blob;
}
Exemplo n.º 4
0
NP::Texture
SDLSTBRenderer::text(const NP::Font &font, const char *text, int rgb)
{
    if (strlen(text) == 0) {
        return NP::Texture(new GLTextureData(nullptr, 10, 10));
    }

    EmscriptenFontData *data = static_cast<EmscriptenFontData *>(font.get());

    float r = 1.f * (Uint8)((rgb >> 16) & 0xff) / 255.f;
    float g = 1.f * (Uint8)((rgb >> 8) & 0xff) / 255.f;
    float b = 1.f * (Uint8)((rgb) & 0xff) / 255.f;

    Blob *blob = Config::readBlob(data->filename);
    StbLoader_RGBA *rgba = StbLoader::render_font(blob->data, blob->len,
            StbLoader_Color(r, g, b, 1.f), data->size, text);
    NP::Texture result = GLRenderer::load((unsigned char *)rgba->data, rgba->w, rgba->h);
    delete rgba;
    delete blob;
    return result;
}