src/Model.hpp
/**
 * Loads a texture from a file.
 *
 * @param path The texture file name
 * @param directory Path to the directory containing the texture file
 * @param gamma Whether to perform gamma correction on the loaded texture (TODO)
 * @return The assigned OpenGL texture ID
 */
Loads a texture from a file.
@param path The texture file name
@param directory Path to the directory containing the texture file
@param gamma Whether to perform gamma correction on the loaded texture (TODO)
@return The assigned OpenGL texture ID
Loads a texture from a file . @param path The texture file name @param directory Path to the directory containing the texture file @param gamma Whether to perform gamma correction on the loaded texture ( TODO ) @return The assigned OpenGL texture ID
uint32_t textureFromFile(const char *path, const std::string &directory, bool gamma = false) {
  std::string filename = std::string(path);
  filename = directory + '/' + filename;
  uint32_t textureId;
  glGenTextures(1, &textureId);
  int32_t width, height, nbComponents;
  uint8_t *data = stbi_load(filename.c_str(), &width, &height, &nbComponents, 0);
  if (data) {
    GLenum format;
    switch (nbComponents) {
      case 1:
        format = GL_RED;
        break;
      case 3:
        format = GL_RGB;
        break;
      case 4:
        format = GL_RGBA;
        break;
      default:
        std::cout
            << "WARNING: Attempted to load a texture with an unsupported number of components ("
            << nbComponents << "), falling back to RGB." << std::endl;
        format = GL_RGB;
        break;
    }
    glBindTexture(GL_TEXTURE_2D, textureId);
    glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
    glGenerateMipmap(GL_TEXTURE_2D);
    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_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  } else {
    std::cout << "ERROR: Failed to load texture at path: " << path << std::endl;
  }
  stbi_image_free(data);
  return textureId;
}
uint32_t textureFromFile ( const char * path , const std :: string & directory , bool gamma = false ) { std :: string filename = std :: string ( path ) ; filename = directory + ' ' + filename ; uint32_t textureId ; glGenTextures ( 1 , & textureId ) ; int32_t width , height , nbComponents ; uint8_t * data = stbi_load ( filename . c_str ( ) , & width , & height , & nbComponents , 0 ) ; if ( data ) { GLenum format ; switch ( nbComponents ) { case 1 : format = GL_RED ; break ; case 3 : format = GL_RGB ; break ; case 4 : format = GL_RGBA ; break ; default : std :: cout << " " << nbComponents << " " << std :: endl ; format = GL_RGB ; break ; } glBindTexture ( GL_TEXTURE_2D , textureId ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , format , width , height , 0 , format , GL_UNSIGNED_BYTE , data ) ; glGenerateMipmap ( GL_TEXTURE_2D ) ; 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_MIPMAP_LINEAR ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ; } else { std :: cout << " " << path << std :: endl ; } stbi_image_free ( data ) ; return textureId ; }
Loads a texture from a file.
Loads a texture from a file .
// The texture resource is no longer needed at this point