如何解决无法始终为具有 #pragma 或项目警告级别的标头禁用 Visual Studio 2019 警告
我在 OpenGL 中使用 SDL2/GLAD 和 stb_image.h,但我的问题与事实无关。我正在编辑所有配置下的属性,但我没有使用预编译头。
我想将我的警告级别提高到 /W4 甚至 /Wall。然而,/Wall 给了我多达 1273 个错误,大部分来自数学库 glm
。因此,我将外部包含包含在 #pragma
push/pop 指令中,但它似乎什么也没做。使用 #pragma warning(disable : n)
特别禁用警告也没有任何作用。
当我开始写这个问题时,无论我如何或在哪里放置#pragma 指令(围绕标题、在标题内、围绕函数、围绕调用),或者我是否将项目警告级别设置为从 /W0 到 / W4,大约 80 个错误会偷偷通过:一个来自 SDL2,其余来自 stb_image.h
。但是,在测试过程中,我的错误列表会随机在大约 7 个错误之间跳转,从 stb_image.h
回到 70+。
我正在努力寻找 Visual Studio 如何处理错误的一致性。我只想关闭来自外部头文件和库的错误,所以我只能看到我编写的代码中的错误。我做错了什么?
#pragma warning(push,0)
#include <glad/glad.h>
#include <SDL.h>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image/stb_image.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#pragma warning(pop)
#include <iostream>
#include <vector>
#include <fstream>
// ...
Image LoadTexture(const std::string& path,GLenum format) {
int width,height,channels;
unsigned char* data = stbi_load(path.c_str(),&width,&height,&channels,STBI_default);
gluint texture;
glGenTextures(1,&texture);
glBindTexture(GL_TEXTURE_2D,texture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
if (data) {
glTexImage2D(GL_TEXTURE_2D,format,width,GL_UNSIGNED_BYTE,data);
glGenerateMipmap(GL_TEXTURE_2D);
}
else {
std::cerr << "Failed to load texture " << path << std::endl;
texture = -1; // error
}
stbi_image_free(data);
return { texture,channels };
}
// ...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。