2012-04-21 173 views
0

我使用cpp/marmalade为ios制作游戏,但有时纹理渲染已损坏。 这里是源纹理文件:渲染时,OpenGL ES有时会损坏纹理。为什么会发生?

http://files.moonmana.com/forums/source-rune.png

一个currupted组织的实例:

enter image description here

我加载纹理此代码:

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; 
} 

回答

3

你的纹理没有被损坏,但频道似乎被翻转。难道是因为你正在将图像转换为ABGR_8888,然后将其上传为GL_RGBA?

+0

谢谢,好主意,我会检查它 – 2012-04-22 18:13:25