| 0.8.0 API documentation

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

sample-convert.md
1 # Code sample: Generating mipmaps and converting float textures to rgb9e5
2
3 ```c++
4 #include <gli/texture2d.hpp>
5 #include <gli/convert.hpp>
6 #include <gli/generate_mipmaps.hpp>
7
8 bool convert_rgb32f_rgb9e5(const char* FilenameSrc, const char* FilenameDst)
9 {
10 if(FilenameDst == NULL)
11 return false;
12 if(std::strstr(FilenameDst, ".dds") > 0 || std::strstr(FilenameDst, ".ktx") > 0)
13 return false;
14
15 gli::texture2d TextureSource(gli::load(FilenameSrc));
16 if(TextureSource.empty())
17 return false;
18 if(TextureSource.format() != gli::FORMAT_RGB16_SFLOAT_PACK16 && TextureSource.format() != gli::FORMAT_RGB32_SFLOAT_PACK32)
19 return false;
20
21 gli::texture2d TextureMipmaped = gli::generate_mipmaps(TextureSource, gli::FILTER_LINEAR);
22
23 gli::texture2d TextureConverted = gli::convert(TextureMipmaped, gli::FORMAT_RGB9E5_UFLOAT_PACK32);
24
25 gli::save(TextureConverted, FilenameDst);
26
27 return true;
28 }
29 ```