【问题标题】:efficient OpenGL texture loading gxbase高效的 OpenGL 纹理加载 gxbase
【发布时间】:2012-05-02 23:40:01
【问题描述】:

使用 OpenGL 和 GxBase 我正在加载我的纹理。

if (Image.Load("ball.jpg"))
{
    Image.FlipY();
    glBindTexture(GL_TEXTURE_2D, MyTexture[0]);
    Image.gluBuild2DMipmaps();
}

如何确保不会两次加载相同的纹理?

【问题讨论】:

    标签: opengl loading textures


    【解决方案1】:

    我从未使用过 GxBase,但我只是维护一个将文件名映射到纹理 ID(字符串到 GLuints)的映射

    当你去加载一个新的时,首先查看地图,如果它在那里,返回纹理 id 而不是再次加载它。否则加载它,然后保存生成的纹理id

    尝试类似:

    std::map<std::string,GLuint> textures;
    ...
    
    // Inside your method to load textures:
    
    if (textures.count(textureName) == 0)
    {
        // load texture
        textures[textureName] = // the GLuint texture id
    }
    else
    {
        return textures[textureName];
    }
    

    【讨论】:

    • 您是否有机会获得该代码的 sn-ps 或指导我学习该教程?谢谢
    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 2013-11-27
    • 2017-06-11
    • 2010-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    相关资源
    最近更新 更多