GLM GLI
0.8.0 0.7.0 0.6.1 0.6.0

Code samples

Loading a DDS file to OpenGL texture object:
  • #include <gli/gli.hpp>
  • GLuint CreateTextureArray(char const* Filename)
  • {
  • gli::texture2D Texture(gli::load_dds(Filename));
  • assert(!Texture.empty());
  • gli::gl GL;
  • gli::gl::format const Format = GL.translate(Texture.format());
  • GLuint TextureName = 0;
  • glGenTextures(1, &TextureName);
  • glBindTexture(GL_TEXTURE_2D_ARRAY, TextureName);
  • glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_BASE_LEVEL, 0);
  • glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAX_LEVEL, static_cast<GLint>(Texture.levels() - 1));
  • glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_R, Format.Swizzle[0]);
  • glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_G, Format.Swizzle[1]);
  • glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_B, Format.Swizzle[2]);
  • glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_SWIZZLE_A, Format.Swizzle[3]);
  • glTexStorage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Texture.levels()),
  • Format.Internal,
  • static_cast<GLsizei>(Texture.dimensions().x),
  • static_cast<GLsizei>(Texture.dimensions().y),
  • static_cast<GLsizei>(1));
  • if(gli::is_compressed(Texture.format()))
  • {
  • for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
  • {
  • glCompressedTexSubImage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Level),
  • 0, 0, 0,
  • static_cast<GLsizei>(Texture[Level].dimensions().x),
  • static_cast<GLsizei>(Texture[Level].dimensions().y),
  • static_cast<GLsizei>(1),
  • Format.External,
  • static_cast<GLsizei>(Texture[Level].size()),
  • Texture[Level].data());
  • }
  • }
  • else
  • {
  • for(std::size_t Level = 0; Level < Texture.levels(); ++Level)
  • {
  • glTexSubImage3D(GL_TEXTURE_2D_ARRAY, static_cast<GLint>(Level),
  • 0, 0, 0,
  • static_cast<GLsizei>(Texture[Level].dimensions().x),
  • static_cast<GLsizei>(Texture[Level].dimensions().y),
  • static_cast<GLsizei>(1),
  • Format.External, Format.Type,
  • Texture[Level].data());
  • }
  • }
  • return TextureName;
  • }
Create GLI texture and clear it with orange:
  • #include <gli/gli.hpp>
  • gli::texture2D CreateTextureRGBA8(gli::texture2D::dim_type const & Dim)
  • {
  • gli::texture2D Texture(gli::FORMAT_RGBA8_UNORM, Dim);
  • Texture.clear<glm::u8vec4>(glm::u8vec4(255, 127, 0, 255));
  • return Texture;
  • }
Loading and saving textures from files:
  • #include <gli/gli.hpp>
  • int test(std::string const & Filename)
  • {
  • int Error(0);
  • gli::texture2D TextureA(gli::load_dds(path(Filename.c_str())));
  • gli::save_dds(TextureA, Filename.c_str());
  • gli::texture2D TextureB(gli::load_dds(Filename.c_str()));
  • Error += TextureA == TextureB ? 0 : 1;
  • return Error;
  • }