Skydome::Skydome() { VertexBuffer buff; int nb_segments=64; int i,j; const float R = 1./(float)(nb_segments-1); for(i = 0; i<nb_segments; i++) { for(j = 0; j<nb_segments; j++) { float x = cos(2*M_PI*j*R)*sin(M_PI*i*R); float y = sin(-M_PI_2+M_PI*i*R); float z = sin(2*M_PI*j*R)*sin(M_PI*i*R); buff.addVertex(Vertex3D(glm::vec3(x,y,z), glm::vec3(-x,-y,-z), glm::vec2(0,0), sf::Color(255,255,255,255))); } } for(i=0; i<nb_segments; i++){ for(j=0; j<nb_segments; j++){ //buff.getVertex(i*nb_segments+j).normal = glm::normalize(buff.getVertex(i*nb_segments+j).normal); buff.addTriangle(sf::Vector3i((i*nb_segments+j), (i*nb_segments+j+1), ((i+1)*nb_segments+j))); buff.addTriangle(sf::Vector3i((i*nb_segments+j+1), ((i+1)*nb_segments+j+1), ((i+1)*nb_segments+j))); } } loadFromMemory(buff); }
void* Font::loadFromFile(const std::string& filename) { FILE* fp = fopen(filename.c_str(), "r"); if (!fp) return false; fseek(fp, 0, SEEK_END); unsigned int buffer_size = ftell(fp); unsigned char* buffer = (unsigned char*)malloc(buffer_size); if (!buffer) { fclose(fp); return false; } rewind(fp); fread(buffer, 1, buffer_size, fp); fclose(fp); bool ret = loadFromMemory(buffer, buffer_size); ttf* result = (ttf*)malloc(sizeof(ttf)); result->buffer = buffer; result->magic = 0x4C464E54; result->bufsize = buffer_size; //free(buffer); return result; }
void Importer::addSceneData(const Url& sceneUrl, std::vector<char>& sceneContent) { LOGD("Process: '%s'", sceneUrl.string().c_str()); // Don't load imports twice if (m_importedScenes.find(sceneUrl) != m_importedScenes.end()) { return; } std::string sceneString; if (isZipArchiveUrl(sceneUrl)) { // We're loading a scene from a zip archive! // First, create an archive from the data. auto zipArchive = std::make_shared<ZipArchive>(); zipArchive->loadFromMemory(sceneContent); // Find the "base" scene file in the archive entries. for (const auto& entry : zipArchive->entries()) { auto ext = Url::getPathExtension(entry.path); // The "base" scene file must have extension "yaml" or "yml" and be // at the root directory of the archive (i.e. no '/' in path). if ((ext == "yaml" || ext == "yml") && entry.path.find('/') == std::string::npos) { // Found the base, now extract the contents to the scene string. sceneString.resize(entry.uncompressedSize); zipArchive->decompressEntry(&entry, &sceneString[0]); break; } } // Add the archive to the scene. m_scene->addZipArchive(sceneUrl, zipArchive); } else { sceneString = std::string(sceneContent.data(), sceneContent.size()); } addSceneString(sceneUrl, sceneString); }
Image::Image(UInt32 width, UInt32 height, Format format, const UInt8* pixels) : m_format((Format)0) , m_width(0) , m_height(0) , m_pixels(nullptr) { loadFromMemory(width, height, format, pixels); }
Image::Image(const Image& other) : m_format((Format)0) , m_width(0) , m_height(0) , m_pixels(nullptr) { loadFromMemory(other.m_width, other.m_height, other.m_format, other.m_pixels); }
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); }
LLValue *put(DValue *v) override { LLValue *address = getAddressOf(v); LLType *abiTy = getAbiType(v->getType()); assert(abiTy && "Why are we rewriting a non-rewritten type?"); return loadFromMemory(address, abiTy, ".X86_64_C_struct_rewrite_putResult"); }
//! [0] Dialog::Dialog(QWidget *parent) : QDialog(parent), sharedMemory("QSharedMemoryExample") { ui.setupUi(this); connect(ui.loadFromFileButton, SIGNAL(clicked()), SLOT(loadFromFile())); connect(ui.loadFromSharedMemoryButton, SIGNAL(clicked()), SLOT(loadFromMemory())); setWindowTitle(tr("SharedMemory Example")); }
Texture::Texture(std::string const & str, LoadMethod lm) { if (lm == File) { if (!loadFromFile(str)) { throw std::runtime_error("Failed to construct texture."); } } else if (lm == Memory) { if (!loadFromMemory(str)) { throw std::runtime_error("Failed to construct texture."); } } }
bool FragmentShader::loadFromFile(const AnyString& filePath) { String data; if (IO::errNone != IO::File::LoadFromFile(data, filePath)) { # if defined(DEBUG) && !defined(NDEBUG) std::cerr << "Failed to load shader \"" << filePath << "\" !" << std::endl; # endif return false; } return loadFromMemory(data); }
void ScreenSpaceImage::loadTexture() { std::unique_ptr<ghoul::opengl::Texture> texture = nullptr; if (!_downloadImage) texture = std::move(loadFromDisk()); else texture = std::move(loadFromMemory()); if (texture) { // LDEBUG("Loaded texture from '" << absPath(_texturePath) << "'"); texture->uploadTexture(); // Textures of planets looks much smoother with AnisotropicMipMap rather than linear texture->setFilter(ghoul::opengl::Texture::FilterMode::Linear); _texture = std::move(texture); } }
bool Image::loadFromFile(const char* filename) { int width, height, format; UInt8* pixels = stbi_load(filename, &width, &height, &format, 0); if (!pixels) { std::cerr << stbi_failure_reason() << std::endl; return false; } loadFromMemory(width, height, (Format)format, pixels); stbi_image_free(pixels); if (m_pixels) return true; return false; }
bool Texture2DLoader::loadFromStream(IResource * outResource, IStream * stream) { assert(outResource != nullptr); if(stream == nullptr) { TRACE_WARNING("Stream pointer not valid!"); return false; } uint32 size = (uint32)stream->getSize(); char * buffer = (char*)malloc(size); stream->read((void*)buffer, sizeof(char), size); bool result = loadFromMemory(outResource, size, buffer); free(buffer); return result; }
bool ScriptManager::loadFromFile(const std::string& file, ScriptType type) { std::ifstream ifs(file.c_str()); if (!ifs) return false; ifs.seekg(0, std::ios::end); size_t len = size_t(ifs.tellg()); ifs.seekg(0, std::ios::beg); std::vector<char> data(len); ifs.read(&data[0], len); // Remove extraneous nullbytes auto it = std::remove(data.begin(), data.end(), '\0'); if (it != data.end()) data.erase(it, data.end()); return loadFromMemory(file, &data[0], data.size(), type); }
bool WiiSave::loadFromFile(const std::string& filename) { FILE* f = fopen(filename.c_str(), "rb"); Uint8* data; int length; if (!f) { std::cerr << "Couldn't open file \"" << filename << "\" please check that it exists." << std::endl; return false; } fseek(f, 0, SEEK_END); length = ftell(f); fseek(f, 0, SEEK_SET); data = new Uint8[length]; fread(data, 1, length, f); return loadFromMemory(data, length); }
bool GifDecoder::load(const char* fileName) { init(); FILE* fp = fopen(fileName, "rb"); if (NULL == fp) { return false; } fseek(fp, 0, SEEK_END); int32_t fileSize = ftell(fp); uint8_t* data = new uint8_t[fileSize]; rewind(fp); fread(data, fileSize, 1, fp); fclose(fp); bool result = loadFromMemory(data, fileSize); delete[] data; return result; }
unsigned char* Font::loadFromFile(const std::string& filename) { FILE* fp = fopen(filename.c_str(), "rb"); if (!fp) return false; fseek(fp, 0, SEEK_END); unsigned int buffer_size = ftell(fp); unsigned char* buffer = (unsigned char*)malloc(buffer_size); if (!buffer) { fclose(fp); return false; } rewind(fp); fread(buffer, 1, buffer_size, fp); fclose(fp); bool ret = loadFromMemory(buffer, buffer_size); //free(buffer); return buffer; }
rb::Value rbTexture::initialize(rb::Value self, const std::vector<rb::Value>& args) { rbTexture* object = self.to<rbTexture*>(); switch( args.size() ) { case 0: break; case 1: if(args[0].getType() == rb::ValueType::Array) loadFromMemory(self, args); else loadFromFile(self, args); break; case 2: object->create(args[0].to<unsigned int>(), args[1].to<unsigned int>()); break; default: rb::expectedNumArgs( args.size(), "0, 1 or 3" ); break; } return self; }
void Image::loadFromFile(std::string fileName, ImageCodec *codec) { std::ifstream in(fileName, std::ifstream::binary); if (in.is_open() == false) { // TODO: Error handling. return; } std::vector<uint8_t> data; in.seekg(std::ios_base::end); data.reserve((unsigned int)in.tellg()); in.seekg(std::ios_base::beg); data.assign(std::istreambuf_iterator<char>(in), std::istreambuf_iterator<char>()); in.close(); return loadFromMemory(data, codec); }
bool Font::loadFromMemory(const std::vector<unsigned char>& buffer) { if (buffer.size() == 0) return false; return loadFromMemory(&buffer[0], buffer.size()); }
Font::Font(const std::vector<unsigned char>& buffer) { loadFromMemory(buffer); }
Font::Font(const unsigned char* buffer, unsigned int buffer_size) { loadFromMemory(buffer, buffer_size); }
LLValue* get(Type* dty, DValue* v) { LLValue* address = storeToMemory(v->getRVal(), 0, ".X86_64_C_struct_rewrite_dump"); LLType* type = DtoType(dty); return loadFromMemory(address, type, ".X86_64_C_struct_rewrite_getResult"); }
bool Texture1D::loadFromFile(const std::string& filename, I32 filter, I32 wrapMode, bool mipmap) { UI32 image, texSize; // Load Image ILDEBUG(ilGenImages(1, &image)); ILDEBUG(ilBindImage(image)); bool success = ILDEBUG(ilLoadImage(filename.c_str())); if(success) { m_name = filename; UI32 texWidth = ILDEBUG(ilGetInteger(IL_IMAGE_WIDTH)); UI32 texHeight = ILDEBUG(ilGetInteger(IL_IMAGE_HEIGHT)); texSize = texWidth * texHeight; ILDEBUG(ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE)); UI8 *textureData = ILDEBUG(ilGetData()); I32 minFilter; if (filter == ODIN_LINEAR && mipmap) { minFilter = ODIN_LINEAR_MIPMAP_LINEAR; } else if (filter == ODIN_NEAREST && mipmap) { minFilter = ODIN_NEAREST_MIPMAP_LINEAR; } success = loadFromMemory(texSize, ODIN_RGBA, ODIN_RGBA, ODIN_UNSIGNED_BYTE, minFilter, filter, wrapMode, textureData, mipmap); UI32 bytesPerPixel = ILDEBUG(ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL)); std::string imageFormat; UI32 imgFormat = ILDEBUG(ilGetInteger(IL_IMAGE_FORMAT)); switch(imgFormat) { case IL_COLOR_INDEX : imageFormat = "IL_COLOR_INDEX"; break; case IL_ALPHA : imageFormat = "IL_ALPHA"; break; case IL_RGB : imageFormat = "IL_RGB"; break; case IL_RGBA : imageFormat = "IL_RGBA"; break; case IL_BGR : imageFormat = "IL_BGR"; break; case IL_BGRA : imageFormat = "IL_BGRA"; break; case IL_LUMINANCE : imageFormat = "IL_LUMINANCE"; break; case IL_LUMINANCE_ALPHA : imageFormat = "IL_LUMINANCE_ALPHA"; break; } std::string imageType; UI32 imgType = ILDEBUG(ilGetInteger(IL_IMAGE_TYPE)); switch(imgType) { case IL_BYTE : imageType = "IL_BYTE"; break; case IL_UNSIGNED_BYTE : imageType = "IL_UNSIGNED_BYTE"; break; case IL_SHORT : imageType = "IL_SHORT"; break; case IL_UNSIGNED_SHORT : imageType = "IL_UNSIGNED_SHORT"; break; case IL_INT : imageType = "IL_INT"; break; case IL_UNSIGNED_INT : imageType = "IL_UNSIGNED_INT"; break; case IL_FLOAT : imageType = "IL_FLOAT"; break; case IL_DOUBLE : imageType = "IL_DOUBLE"; break; case IL_HALF : imageType = "IL_HALF"; break; } LOG_INFO("DEVIL: Image texture successfully loaded: %s\n" "Width: %d, Height: %d, Bytes per Pixel: %d\n" "Format: %s, Data type: %s" , filename.c_str(), texWidth, texHeight, bytesPerPixel, imageFormat.c_str(), imageType.c_str()); } else { m_name = "Default"; LOG_ERROR("DEVIL: Could not load image: %s. Switching to default texture", filename.c_str()); texSize = 1; UI8 data[] = {255,255,255,255}; success = loadFromMemory(texSize, ODIN_RGBA, ODIN_RGBA, ODIN_UNSIGNED_BYTE, ODIN_NEAREST, ODIN_NEAREST, ODIN_CLAMP_TO_EDGE, data, false); } ILDEBUG(ilDeleteImages(1, &image)); return success; }
void Image::loadFromMemory(const char* rawData, int width, int height, GLenum format, GLenum type) noexcept { loadFromMemory(rawData, Size<int>(width, height), format, type); }
LLValue *get(Type *dty, LLValue *v) override { LLValue *address = DtoAllocaDump(v, dty, ".X86_64_C_struct_rewrite_dump"); LLType *type = DtoType(dty); return loadFromMemory(address, type, ".X86_64_C_struct_rewrite_getResult"); }
Image& Image::operator=(const Image& other) { loadFromMemory(other.m_width, other.m_height, other.m_format, other.m_pixels); return *this; }
BYTE Processor::loadFromMemory() { return loadFromMemory( (REGISTERS[REG_H] << 8) + REGISTERS[REG_L]); }
SoundBuffer& operator =(const SoundBuffer& right) { loadFromMemory(right.getSamples(), right.getSampleCount(), right.getChannelCount(), right.getSampleRate()); return *this; }
/* create from wav file (riff header + pcm) */ Sound::Sound(const char * data, int length): own(NULL){ loadFromMemory(data, length); }