0
我使用cpp/marmalade为ios制作游戏,但有时纹理渲染已损坏。 这里是源纹理文件:渲染时,OpenGL ES有时会损坏纹理。为什么会发生?
一个currupted组织的实例:
我加载纹理此代码:
VGTexture2D* VGTextureLoader::loadImage(std::string imagefile)
{
CIwImage img;
img.LoadFromFile(imagefile.c_str());
// Convert to an OpenGL ES native format
CIwImage nativeImg;
nativeImg.SetFormat(CIwImage::ABGR_8888);
img.ConvertToImage(&nativeImg);
// Generate texture object
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
// Upload
uint32 width = img.GetWidth();
uint32 height = img.GetHeight();
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nativeImg.GetTexels());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Create and return texture
VGTexture2D* tex = new VGTexture2D(texture, (float)width, (float)height);
return tex;
}
谢谢,好主意,我会检查它 – 2012-04-22 18:13:25