小编Hew*_*itt的帖子

OpenGL 加载将最后加载的纹理绑定到所有的纹理 ID

所以我的问题是我尝试在启动时加载多个纹理,然后存储所有 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)

c++ opengl loading texture-mapping texture2d

5
推荐指数
1
解决办法
148
查看次数

标签 统计

c++ ×1

loading ×1

opengl ×1

texture-mapping ×1

texture2d ×1