Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Macos openGL纹理加载->;奇怪的结果[mac、glfw、stb_图像]_Macos_Opengl_Textures_Glfw - Fatal编程技术网

Macos openGL纹理加载->;奇怪的结果[mac、glfw、stb_图像]

Macos openGL纹理加载->;奇怪的结果[mac、glfw、stb_图像],macos,opengl,textures,glfw,Macos,Opengl,Textures,Glfw,在opengl中加载纹理时遇到问题 我正在mac上写cpp,日子不好过。我不明白为什么我有这些丑陋的纹理。我正在使用stb_image.c加载纹理,但它似乎无法正常工作 这是我的密码: unsigned int TextureHelper::loadTexture(std::string pathToTexture){ std::cout << "Loading " << pathToTexture << std::endl; unsigned int im

在opengl中加载纹理时遇到问题

我正在mac上写cpp,日子不好过。我不明白为什么我有这些丑陋的纹理。我正在使用stb_image.c加载纹理,但它似乎无法正常工作

这是我的密码:

unsigned int TextureHelper::loadTexture(std::string pathToTexture){ 
std::cout << "Loading " << pathToTexture << std::endl;
unsigned int img;
glGenTextures(1,&img);
glBindTexture(GL_TEXTURE_2D,img);

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);

/* Load Texture with stb_image */
int width, height, n;
unsigned char * data = stbi_load(pathToTexture.c_str(), &width, &height, &n, 4);
if(!data){
    printf("Error, while loading texture: %s\n", stbi_failure_reason());
}else{
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
    stbi_image_free(data);
    std::cout << "returning " << pathToTexture << " = "  << img << "x" << width << "x" << height << "x" << n << std::endl;
    return img;
}
std::cout << "returning " << pathToTexture << " = "  << 0 << std::endl;
return 0;
在我的窗口创建解决问题之前

    glfwWindowHint(GLFW_RED_BITS, 8);
glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8);
glfwWindowHint(GLFW_ALPHA_BITS, 8);
glfwWindowHint(GLFW_DEPTH_BITS, 32);