原因:xcode 引入第三方库:stb_image.h
//这行代码报错
stbi_set_flip_vertically_on_load(true);
//这行代码报错
stbi_set_flip_vertically_on_load(true);
//加载纹理
unsigned char *data = stbi_load("textures/bg.png", &width, &height, &nrChannels, 0);
if (data)
{
//载入的图片数据生成一个纹理
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
//为当前绑定的纹理自动生成所有需要的多级渐远纹理
glGenerateMipmap(GL_TEXTURE_2D);
}
else
{
std::cout << "Failed to load texture" << std::endl;
}
stbi_image_free(data);
错误信息如下:
第一:添加 stb_image.cpp 文件
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
第二: 添加 如下图:
第三:clean
再次编译 ok