Пример #1
0
MyImage* MyImage::LoadImage(string path) {
    GLuint texture;
    unsigned char *data;
    int width, height;

    MyImage *image = new MyImage();

    string ext;
    ext = path.substr( path.find_last_of('.') );
    
    if( ext.compare("tga") == 0 ) {
        if( ! image->InitWithFileTGA(path) ) {
            delete image;
            return NULL;
        }
        
        return image;
    }
    else if( ext.compare("png") == 0 ) {
        // not supported
        delete image;
        return NULL;
    }

    
    // else formats ...
    texture = SOIL_load_OGL_texture(path.c_str(),
                                    SOIL_LOAD_AUTO,
                                    SOIL_CREATE_NEW_ID,
                                    SOIL_FLAG_INVERT_Y,
                                    &data,
                                    &width,
                                    &height);
    if( texture == 0 ) {
        return NULL;
    }
    
    image = new MyImage( texture, data, width, height );
    return image;
}