2012-05-02 120 views
0

使用OpenGL和使用GxBase我加载我的纹理。高效的OpenGL纹理加载gxbase

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

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

回答

0

我从来没有用过GxBase,但我只希望维持一个地图映射文件名纹理IDS(字符串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]; 
} 
+0

你的代码片段为或引导我教程的机会吗?谢谢 – HungryCoder