0

I'm using the stb_image library to help load images/textures, following "The Cherno"'s OpenGL tutorial playlist. While I'm able to successfully load and render the images, I get these compiler warnings whenever I build my project. How can I resolve these warnings without disabling warnings?

Warnings:

In file included from src/Texture.cpp:3:
src/vendor/stb_image/stb_image.h: In function 'int stbi__zhuffman_decode_slowpath(stbi__zbuf*, stbi__zhuffman*)':
src/vendor/stb_image/stb_image.h:4123:10: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
    if (b >= sizeof (z->size)) return -1; // some data was corrupt somewhere!
        ~~^~~~~~~~~~~~~~~~~~~
src/vendor/stb_image/stb_image.h: In function 'void* stbi__load_gif_main(stbi__context*, int**, int*, int*, int*, int*, int)':
src/vendor/stb_image/stb_image.h:6778:11: warning: variable 'out_size' set but not used [-Wunused-but-set-variable]
       int out_size = 0;
           ^~~~~~~~
src/vendor/stb_image/stb_image.h:6779:11: warning: variable 'delays_size' set but not used [-Wunused-but-set-variable]
       int delays_size = 0;
           ^~~~~~~~~~~

stb_image.h file code was obtained from this website (None of the code was altered): https://github.com/nothings/stb/blob/master/stb_image.h

stb_image.h implementation:

#define STB_IMAGE_IMPLEMENTATION
#include "Texture.h"
#include "vendor/stb_image/stb_image.h"

Texture::Texture(const std::string &path) 
    : rendererID{0}, filePath{path}, localBuffer{nullptr}, width{0}, height{0}, bPP{0} {
        stbi_set_flip_vertically_on_load(1);
        localBuffer = stbi_load(path.c_str(), &width, &height, &bPP, 4);
        if (localBuffer == nullptr)
            std::cout << "Unable to load texture file: " << path << std::endl;

        glGenTextures(1, &rendererID);
        glBindTexture(GL_TEXTURE_2D, rendererID);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, localBuffer);

        unbind();

        if (localBuffer)
            stbi_image_free(localBuffer);
}
Texture::~Texture() {
    glDeleteTextures(1, &rendererID);
}

void Texture::bind(GLuint slot) const {
    glActiveTexture(GL_TEXTURE0 + slot);
    glBindTexture(GL_TEXTURE_CUBE_MAP, rendererID);
}
void Texture::unbind() const {
    glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
}
spaL
  • 604
  • 7
  • 21
  • Not much you can do about them unless you correct the header. I don't know the library well enough to be able to tell you if that's a good idea or not. – user4581301 Feb 04 '21 at 01:50
  • 2
    It's common practice to disable warning that originate from libraries written by others. You can disable the warnings just for a single header by wrapping the include with some `#pragmas`. See [this for GCC](https://stackoverflow.com/questions/3378560/how-to-disable-gcc-warnings-for-a-few-lines-of-code). – Yakov Galka Feb 04 '21 at 02:50

0 Answers0