Параметры загрузки изображений SOIL - PullRequest
0 голосов
/ 18 декабря 2018

Я использую эту функцию SOIL для загрузки файлов текстур в OpenGL.Однако я хотел бы получить доступ к:

  • Высота и ширина загруженного изображения.
  • Bpp (значение в пикселях на байты) изображения (8, 24 и т. Д.).
  • Указатель данных.

Данная функция не возвращает ни одной из этих характеристик.Я хотел бы получить некоторую помощь о том, как найти их с помощью этой или любой другой аналогичной функции 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 голосов
/ 19 декабря 2018

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

С этой информацией вы можете создать текстуру OpenGL с 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
);
...