void saveScreenToFile(const char* imageName) { GLint vp[4]; glGetIntegerv(GL_VIEWPORT, vp); GLint x = vp[0], y = vp[1], w = vp[2], h = vp[3]; u8* p = new u8[w*h*4]; glReadPixels (x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, p); SOIL_save_image(imageName, SOIL_SAVE_TYPE_TGA, w, h, 4, p); delete [] p; }
bool Spritesheet::writeTextureToFile(std::string fileName) { fileName += "_ss.tga"; std::cout << "Writing texture to file." << std::endl; int saveStatus = SOIL_save_image(fileName.c_str(), SOIL_SAVE_TYPE_TGA, spritesheetWidth, spritesheetHeight, 4, spritesheet); if (saveStatus == 0) { std::cout << "SOIL failed to save image." << std::endl; return false; } else { std::cout << "SOIL saved image correctly." << std::endl; } return true; }
/* Save texture to file in TGA format */ int dlTextureSave( dlTexture *texture, const char *path ) { CALL("%p, %s", texture, path); if(!texture) { RET("%d", RETURN_FAIL); return( RETURN_FAIL ); } if(!SOIL_save_image ( path, SOIL_SAVE_TYPE_TGA, texture->width, texture->height, texture->channels, texture->data )) { RET("%d", RETURN_FAIL); return( RETURN_FAIL ); } RET("%d", RETURN_OK); return( RETURN_OK ); }
bool cImage::SaveToFile( const std::string& filepath, const EE_SAVE_TYPE& Format ) { bool Res = false; std::string fpath( FileSystem::FileRemoveFileName( filepath )); if ( !FileSystem::IsDirectory( fpath ) ) FileSystem::MakeDir( fpath ); if ( NULL != mPixels && 0 != mWidth && 0 != mHeight && 0 != mChannels ) { if ( SAVE_TYPE_JPG != Format ) { Res = 0 != ( SOIL_save_image ( filepath.c_str(), Format, (Int32)mWidth, (Int32)mHeight, mChannels, GetPixelsPtr() ) ); } else { jpge::params params; params.m_quality = JpegQuality(); Res = jpge::compress_image_to_jpeg_file( filepath.c_str(), mWidth, mHeight, mChannels, GetPixelsPtr(), params); } } return Res; }