bool ScriptManager::loadFromStream(const std::string& name, sf::InputStream& stream, ScriptType type) { auto len = size_t(stream.getSize()); std::vector<char> data(len); stream.read(&data[0], len); return loadFromMemory(name, &data[0], len, type); }
bool Texture::loadTGA(sf::InputStream& stream) { uint8_t header[12] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; uint8_t bpp = 32; uint8_t id = 8; uint16_t width; uint16_t height; stream.read(header, 12); stream.read(&width, 2); stream.read(&height, 2); stream.read(&bpp, 1); stream.read(&id, 1); uint8_t bytesPP = bpp / 8; if (bytesPP<1 || bytesPP>4) return false; gli::format format = static_cast<gli::format>(bytesPP - 1); auto dim = gli::texture2D::dim_type(width, height); m_tex = gli::texture2D(format,dim); stream.read(m_tex.data(), width*height * 4); glGenTextures(1, &m_id); glBindTexture(GL_TEXTURE_2D, m_id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, m_tex.data()); return true; }