0

我正在使用 stb_image 库来帮助加载图像/纹理,遵循“The Cherno”的 OpenGL 教程播放列表。虽然我能够成功加载和渲染图像,但每当我构建我的项目时,我都会收到这些编译器警告。如何在不禁用警告的情况下解决这些警告?

警告:

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 文件代码是从这个网站获得的(代码没有被改变):https ://github.com/nothings/stb/blob/master/stb_image.h

stb_image.h 实现:

#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);
}
4

0 回答 0