我有一个贴图上贴有纹理的广告牌。OpenGL广告牌插值问题
这基本上是一些透明的文字。
广告牌从相机的角度向前和向后漂浮。
随着广告牌移开(并且看起来更小),在实际纹理上存在笔划边界的文本边缘周围会出现闪烁效果。
我认为这是因为插值是需要的,因为通常为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);
纹理是blurryness的512×512
实施例当使用MIN滤波器: Blurry billboard http://i43.tinypic.com/2h2qe6u.jpg
当只使用GL_NEAREST用于min过滤器更锐利但令人讨厌的双线性和闪烁如上所述动画缩小时: GL_NEAREST http://i42.tinypic.com/28a5kdf.jpg
你能显示一些截图? – Thomas 2010-04-04 17:31:43
另外,您需要在上传纹理之前设置这些参数(使用'glTexImage2d'左右)。这样,当您调用'glTexImage2d'时将生成mipmap。没有其他的代码,我看不出你在做什么。 – Thomas 2010-04-04 17:34:28
简单'ole GL_LINEAR会发生什么? – genpfault 2010-04-05 01:15:25