SOIL图像加载库参数

SOIL image loading library Parameters

我正在使用这个 SOIL 函数在 OpenGL 中加载纹理文件。但是我想访问:

给定的函数没有return任何这些特征。我想要一些关于如何使用这个或任何其他类似的 SOIL 函数找到这些的帮助。这是我使用的功能。

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;
}

SOIL_load_image() 将填充其 width/height/channels 参数:

/**
    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
    );

根据这些信息,您可以使用 SOIL_create_OGL_texture():

创建 OpenGL 纹理
/**
    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
);