stbi_load() 不返回任何内容,但不返回 null
stbi_load() returns nothing, but it doesnt return null
我正在尝试使用stb_image,当我使用stbi_load时,什么都没有返回。我正在使用Visual Studio 2017,我的图像位于C:/Users/michael/Documents/Visual Studio 2017/Projects/OpenGL Testing/OpenGL Testing/textures/test.png
。
这是我的代码:
#include "texture.h"
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
Texture::Texture(const std::string& filename,unsigned int unit)
{
//Load the textures
int width, height, numComponents;
;
std::cout << filename << std::endl;
unsigned char* data = stbi_load(filename.c_str(),&width,&height,&numComponents,4);
std::cout << data << std::endl;
//Check for errors
if (data = NULL) {
std::cerr << "Failed to load texture: " + filename;
}
//Generate and bind the textures
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D,texture);
//Set texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//Send texture to GPU
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
stbi_image_free(data);
}
void Texture::Bind(unsigned int unit)
{
assert(unit >= 0 && unit <= 31);
glActiveTexture(GL_TEXTURE0 + unit);
glBindTexture(GL_TEXTURE_2D, texture);
}
Texture::~Texture()
{
glDeleteTextures(1, &texture);
}
if (data = NULL)
^ perhaps you meant '=='?
不要用 NULL 覆盖data
的任何内容。
你可能想要的尤达条件。
相关文章:
- 如何在映射中返回null
- 为什么返回 NULL 不会破坏函数?
- fopen 在 gdb 中返回 NULL
- 为什么要从main()返回NULL?
- 为什么TinyXML2的XMLDocument::FirstChild()函数在尝试解析这个有效的XML文件时返回NULL?
- Box2D World.GetBodyList() 返回 NULL,但 World 显然正在更新对象
- boost::p ython:PyErr_Fetch始终返回 NULL 回溯
- 如何在 Visual C++ 中从返回类型为 map 的函数返回 null?
- 如何在C++中返回Null作为引用
- 从模板化函数返回Null对象
- GDALOpen 在 GEOTiff 文件上返回 null
- PyThreadState_GET() 从 PyImport_GetModuleDict() 中返回 NULL
- (位图)LoadImage() 返回 NULL,GetLastError() 返回 0
- 在构造函数处将类对象强制转换为接口始终返回 NULL
- 如何为迭代器返回"null"值?
- 具有 4 个指针的节点的递归插入函数返回 null
- winAPI FindResource 仅在 DLL 中返回 NULL
- 使用 dlopen/dlsym 打开C++共享库 - dlsym 返回 NULL
- SetWindowsHookEx 在挂接到其他线程时返回 NULL
- 尚未归shared_ptr所有的实例的 shared_from_this() 总是返回 null?