includes/utils/Model.hpp
GLint TextureFromFile(const char* path, string directory)
{
     //Generate texture ID and load texture data
    string filename = string(path);
    filename = directory + '/' + filename;
    GLuint textureID;
    glGenTextures(1, &textureID);
    int width,height,channels;
    unsigned char* image = stbi_load(filename.c_str(), &width, &height, &channels, 0);

    // Assign texture to ID
    glBindTexture(GL_TEXTURE_2D, textureID);
    // 3 channels = RGB ; 4 channel = RGBA
    if (channels==3)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
    else if (channels==4)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
    glGenerateMipmap(GL_TEXTURE_2D);

    // we set how to consider UVs outside [0,1] range
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    // we set the filtering for minification and magnification
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glBindTexture(GL_TEXTURE_2D, 0);
    // we free the memory once we have created an OpenGL texture
    stbi_image_free(image);
    return textureID;
}
// we load texture from disk, and we create OpenGL Texture Unit
we load texture from disk, and we create OpenGL Texture Unit
we load texture from disk and we create OpenGL Texture Unit
GLint TextureFromFile(const char* path, string directory)
{
    string filename = string(path);
    filename = directory + '/' + filename;
    GLuint textureID;
    glGenTextures(1, &textureID);
    int width,height,channels;
    unsigned char* image = stbi_load(filename.c_str(), &width, &height, &channels, 0);
    glBindTexture(GL_TEXTURE_2D, textureID);
    if (channels==3)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
    else if (channels==4)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
    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);
    glBindTexture(GL_TEXTURE_2D, 0);
    stbi_image_free(image);
    return textureID;
}
GLint TextureFromFile ( const char * path , string directory ) { string filename = string ( path ) ; filename = directory + ' ' + filename ; GLuint textureID ; glGenTextures ( 1 , & textureID ) ; int width , height , channels ; unsigned char * image = stbi_load ( filename . c_str ( ) , & width , & height , & channels , 0 ) ; glBindTexture ( GL_TEXTURE_2D , textureID ) ; if ( channels == 3 ) glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGB , width , height , 0 , GL_RGB , GL_UNSIGNED_BYTE , image ) ; else if ( channels == 4 ) glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , width , height , 0 , GL_RGBA , GL_UNSIGNED_BYTE , image ) ; 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 ) ; glBindTexture ( GL_TEXTURE_2D , 0 ) ; stbi_image_free ( image ) ; return textureID ; }
we load texture from disk, and we create OpenGL Texture Unit
we load texture from disk and we create OpenGL Texture Unit
//Generate texture ID and load texture data // Assign texture to ID // 3 channels = RGB ; 4 channel = RGBA // we set how to consider UVs outside [0,1] range // we set the filtering for minification and magnification // we free the memory once we have created an OpenGL texture