所以我的问题是我尝试在启动时加载多个纹理,然后存储所有 ID,以便我可以绑定它们以使用它们。现在我知道 ID 被正确存储,因为我可以调试它并在分配和使用中看到 ID 是相同的。只是对于每个绑定,它使用我加载的最后一个纹理。这是我的代码:
GLuint TextureLoader::LoadTexture (const char* fileName,Material& material,int width,int height) {
GLuint textureImage;
FILE* textureFile;
textureFile = fopen(fileName, "rb");
unsigned char* imageData;
if (textureFile == NULL) {
return 0;
}
imageData = (unsigned char*)malloc(width * height * 3);
char header[54];
fread(header,1,54,textureFile);
fread(imageData, width * height * 3, 1, textureFile);
fclose(textureFile);
for (int i = 0; i < width * height; ++i) {
int nextIndex = i * 3;
unsigned char a = imageData[nextIndex];
unsigned char b …Run Code Online (Sandbox Code Playgroud)