我有一个贴有纹理的广告牌四边形。
这基本上是一些具有透明度的文本。
从摄像机的角度看,广告牌前后浮动。
随着广告牌移开(并且看起来更小),在实际纹理上有笔触边框的文本边缘周围会出现闪烁效果。
我认为这是因为需要插值,因为通常为 X 像素宽的图像现在仅显示为 X 的百分比,并且需要将一些像素合并在一起。我猜它是在做最近的邻居还是什么?谁能指出我正确的方向来控制opengl设置,我猜有一些方法可以通过调整处理纹理的方法来防止这种效果发生?
我认为它与以下内容有关:
GL_NEAREST_MIPMAP_NEAREST
但是当我尝试为 MIN 过滤器设置它并启用 mip 映射时,我的纹理变得非常块状和模糊......
我也试过:
GL_LINEAR_MIPMAP_LINEAR
这显然是 MIN 过滤器的三次过滤,但我的图像在显示时非常模糊。(看起来它是一个非常低分辨率的纹理)任何想法我做错了什么?
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // trilinear
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
更多代码:
// Allocated memory needed for the bitmap context
spriteData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));
// Uses the bitmap creation function provided by the Core Graphics framework.
spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
// After you create the context, you can draw the sprite image to the context.
CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), spriteImage);
// You don't need the context at this point, so you need to release it to avoid memory leaks.
CGContextRelease(spriteContext);
// Use OpenGL ES to generate a name for the texture.
glGenTextures(1, &spriteTexture[textureCount-1]);
// Bind the texture name.
glBindTexture(GL_TEXTURE_2D, spriteTexture[textureCount-1]);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// Specify a 2D texture image, providing the a pointer to the image data in memory
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);
// Release the image data
free(spriteData);
纹理为 512 x 512。
使用 MIN 滤镜时的模糊度示例:
当仅将 GL_NEAREST 用于最小过滤器时,会更锐利但令人讨厌的双线性以及在动画收缩时如上所述的闪烁: