c++imageopenglsoil

SOIL image loading library Parameters


I am using this SOIL function to load texture files in OpenGL. However i would like to access:

The given function does not return any of this characteristics. I would like some help on how to find these using this or any other similar SOIL function. This is the function i use.

GLuint loadSOIL(const char* imagePath) {
    cout << "Reading image: " << imagePath << endl;

    GLuint texture = 0;

    //Load Image File Directly into an OpenGL Texture
    texture = SOIL_load_OGL_texture
    (
        imagePath,
        SOIL_LOAD_RGB,
        SOIL_CREATE_NEW_ID,
        SOIL_FLAG_TEXTURE_REPEATS
    );

    // error check
    if (texture == 0) {
        cout << "SOIL loading error: " << SOIL_last_result() << endl;
    }

    return texture;
}

Solution

  • SOIL_load_image() will populate its width/height/channels parameters:

    /**
        Loads an image from disk into an array of unsigned chars.
        Note that *channels return the original channel count of the
        image.  If force_channels was other than SOIL_LOAD_AUTO,
        the resulting image has force_channels, but *channels may be
        different (if the original image had a different channel
        count).
        \return 0 if failed, otherwise returns 1
    **/
    unsigned char*
        SOIL_load_image
        (
            const char *filename,
            int *width, int *height, int *channels,
            int force_channels
        );
    

    With that information you can create an OpenGL texture with SOIL_create_OGL_texture():

    /**
        Creates a 2D OpenGL texture from raw image data.  Note that the raw data is
        _NOT_ freed after the upload (so the user can load various versions).
        \param data the raw data to be uploaded as an OpenGL texture
        \param width the width of the image in pixels
        \param height the height of the image in pixels
        \param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA
        \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture)
        \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT
        \return 0-failed, otherwise returns the OpenGL texture handle
    **/
    unsigned int
        SOIL_create_OGL_texture
        (
            const unsigned char *const data,
            int width, int height, int channels,
            unsigned int reuse_texture_ID,
            unsigned int flags
    );