Opengl es OpenGL在渲染时有时会损坏纹理。为什么会发生?
我用cpp/marmalade为ios制作了一个游戏,但有时纹理会被破坏。 以下是源纹理文件: currupted纹理的示例: 我正在用以下代码加载纹理:Opengl es OpenGL在渲染时有时会损坏纹理。为什么会发生?,opengl-es,png,rendering,textures,corruption,Opengl Es,Png,Rendering,Textures,Corruption,我用cpp/marmalade为ios制作了一个游戏,但有时纹理会被破坏。 以下是源纹理文件: currupted纹理的示例: 我正在用以下代码加载纹理: VGTexture2D* VGTextureLoader::loadImage(std::string imagefile) { CIwImage img; img.LoadFromFile(imagefile.c_str()); // Convert to an OpenGL ES native format CIwImag
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;
}
你的纹理没有被破坏,但是通道看起来确实被翻转了。可能是因为您正在将图像转换为ABGR_8888,然后将其作为GL_RGBA上载?您的纹理没有被损坏,但通道确实似乎被翻转。可能是因为您正在将图像转换为ABGR_8888,然后将其上载为GL_RGBA