1

我有一个贴有纹理的广告牌四边形。

这基本上是一些具有透明度的文本。

从摄像机的角度看,广告牌前后浮动。

随着广告牌移开(并且看起来更小),在实际纹理上有笔触边框的文本边缘周围会出现闪烁效果。

我认为这是因为需要插值,因为通常为 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 用于最小过滤器时,会更锐利但令人讨厌的双线性以及在动画收缩时如上所述的闪烁:

GL_NEAREST

4

2 回答 2

1

If you were using glu, I would suggest that you try using gluBuild2DMipmaps to create the mipmaps and see how others do this.

To avoid using glu functions, I sometimes look at Mesa's OpenGL implementation to get some ideas (I generally try to keep a lot of code in my own project.. and I share a lot of it between OpenGL, D3D, and other platforms). You can try looking at the source for the Mesa implementation (MesaLib) of gluBuild2DMipmaps to see how you could get a similar effect. It appears in MesaLib's mipmap.c, and you'll probably end up jumping to the implementation of bitmapBuild2DMipmaps.

I can't guarantee that this will lead to good results, but it's an avenue to explore. For general debugging of what's happening, another thing you could try is to output your mipmap textures to files for external viewing. All this is of course after you've exhausted your options of randomly toggling flags and googling other peoples' code to see if you missed any state functions.

于 2010-05-08T20:57:35.747 回答
1

Mipmapping 由正在绘制的片段的纹素与像素的比率控制(希望我的术语在那里是正确的)。你在屏幕上画多大?

如果您在(例如)128x128 上绘制它,您将获得 mipmap 级别 2,因此是模糊的。

纹理应该以它们将在屏幕上显示的大小创建,或者尽可能接近,而不是产生太多像素并让 GPU 选择不合适的 mipmap 级别......

于 2010-05-11T20:09:55.227 回答