SOIL图像加载库参数

时间:2018-12-18 20:17:11

标签: c++ image opengl soil

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

  • 已加载图像的高度和宽度。
  • 图像(8、24等)的Bpp(每字节像素值)。
  • 数据指针。

给定的函数不返回任何此特征。我想要一些有关如何使用此或任何其他类似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;
}

1 个答案:

答案 0 :(得分:1)

SOIL_load_image()将填充其宽度/高度/通道参数:

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