代码仓库
1.加载一张PNG的图片
上一章我们已经成功的显示了一张JPG格式的图片,其颜色格式为RGB。这次我们添加一张PNG格式的图片,颜色格式为RGBA。图片如下所示:
加载的方式与之前是完全相同的,只不过格式稍加改变,将GL_RGB改为GL_RGBA,代码参见:
GLuint texture_logo;
glGenTextures(1, &texture_logo);
glBindTexture(GL_TEXTURE_2D, texture_logo);
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Load Image
int logo_width, logo_height, logo_channels;
stbi_set_flip_vertically_on_load(true);
unsigned char* logo_data =