我有一個貼圖上貼有紋理的廣告牌。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