// note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA
请注意,Awesomeface.png具有透明度,因此具有alpha通道,因此请确保告诉OpenGL数据类型为GL_RGBA
png格式比jpg格式通道数量多,openGL中参数不同
int width, height, nrChannels; unsigned char *data = stbi_load("../include/pic/awesomeface.png", &width, &height, &nrChannels, 0); //unsigned char *data = stbi_load("../include/pic/awesomefaceJpg.jpg", &width, &height, &nrChannels, 0); if (data) { // note that the awesomeface.png has transparency and thus an alpha channel, so make sure to tell OpenGL the data type is of GL_RGBA GLenum format; if (nrChannels == 1) format = GL_RED; else if (nrChannels == 3) format = GL_RGB; else if (nrChannels == 4) format = GL_RGBA; //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data); glGenerateMipmap(GL_TEXTURE_2D); }
标签:通道,openGL,format,height,RGBA,nrChannels,GL,data,图片 From: https://www.cnblogs.com/jessicaland/p/16918514.html