Example #1
0
bool FontContext::addFont(std::string _fontFile, std::string _name) {
    if (m_fonts.find(_name) != m_fonts.end()) {
        return true;
    }

    unsigned int dataSize;
    unsigned char* data = bytesFromResource(_fontFile.c_str(), &dataSize);
    m_font = fonsAddFont(m_fsContext, "droid-serif", data, dataSize);

    if (m_font == FONS_INVALID) {
        logMsg("[FontContext] Error loading font file %s\n", _fontFile.c_str());
        return false;
    }

    m_fonts[_name] = m_font;

    return true;
}
Example #2
0
void TextureCube::load(const std::string& _file) {
    unsigned int size;
    unsigned char* data = bytesFromResource(_file.c_str(), &size);
    unsigned char* pixels;
    int width, height, comp;

    pixels = stbi_load_from_memory(data, size, &width, &height, &comp, STBI_rgb_alpha);

    size = width * height;

    m_width = width / 4;
    m_height = height / 3;

    for (int i = 0; i < 6; ++i) {
        GLenum face = CubeMapFace[i];
        m_faces.push_back({face, {}, 0});
        m_faces.back().m_data.resize(m_width * m_height);
    }

    for (int y = 0; y < height; ++y) {
        int jFace = (y - (y % m_height)) / m_height;

        for (int iFace = 0; iFace < 4; ++iFace) {
            Face* face = nullptr;

            if (iFace == 2 && jFace == 1) { face = &m_faces[0]; } // POS_X
            if (iFace == 0 && jFace == 1) { face = &m_faces[1]; } // NEG_X
            if (iFace == 1 && jFace == 0) { face = &m_faces[2]; } // POS_Y
            if (iFace == 1 && jFace == 2) { face = &m_faces[3]; } // NEG_Y
            if (iFace == 1 && jFace == 1) { face = &m_faces[4]; } // POS_Z
            if (iFace == 3 && jFace == 1) { face = &m_faces[5]; } // NEG_Z

            if (!face) { continue; }

            int offset = (m_width * iFace + y * width) * sizeof(unsigned int);
            std::memcpy(face->m_data.data() + face->m_offset, pixels + offset, m_width * sizeof(unsigned int));
            face->m_offset += m_width;
        }
    }

    free(data);
    stbi_image_free(pixels);

}