【问题标题】:OpenGL ES sometimes corrupt textures when rendering. Why it can happen?OpenGL ES 在渲染时有时会损坏纹理。为什么会发生?
【发布时间】:2012-04-21 15:47:20
【问题描述】:

我正在使用 cpp/marmalade 为 ios 制作游戏,但有时纹理呈现损坏。 这是源纹理文件:

弯曲纹理示例:

我正在使用此代码加载纹理:

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

【问题讨论】:

    标签: opengl-es png rendering textures corruption


    【解决方案1】:

    你的纹理没有被破坏,但通道似乎被翻转了。可能是因为您将图像转换为 ABGR_8888,然后将其上传为 GL_RGBA?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多