GLuint createTexture(const char* filename, int width = 128, int height = 128)
{
GLuint texture;
char bitmap[width][height][3];
FILE* fp = fopen(filename, "rb");
assert(fp);
assert(fread(bitmap, 3*sizeof(char), width*height, fp) == width*height);
fclose(fp);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmap);
glBindTexture( GL_TEXTURE_2D,0);
return texture;
}
大家好,我想知道上面的代码是如何工作的。据说它是一种编码,可用于在 OpenGL 中对实体对象进行纹理处理(例如:)glutSolidSphere
。有人可以向我解释一下上述编码是如何工作的吗?