缩小时纹理质量差

时间:2012-01-05 22:52:45

标签: ios opengl-es

我将我的应用程序移植到iOS,虽然它具有与纹理绑定相同的gl调用,但在缩小时质量变得非常差(启用了mipmap)。这个纹理加载代码有问题吗?

编辑:我开始认为这实际上是视网膜显示问题。

NSString *path = [[NSBundle mainBundle] pathForResource:filename ofType:@"jpg"];
    NSData *texData = [[NSData alloc] initWithContentsOfFile:path];
UIImage *image = [[UIImage alloc] initWithData:texData];

if (image == nil)
    NSLog(@"Do real error checking here");

GLuint width = CGImageGetWidth(image.CGImage);
GLuint height = CGImageGetHeight(image.CGImage);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
void *imageData = malloc( height * width * 4 );
CGContextRef context = CGBitmapContextCreate( imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big );

// Flip the Y-axis
CGContextTranslateCTM (context, 0, height);
CGContextScaleCTM (context, 1.0, -1.0);

CGColorSpaceRelease( colorSpace );
CGContextClearRect( context, CGRectMake( 0, 0, width, height ) );
CGContextDrawImage( context, CGRectMake( 0, 0, width, height ), image.CGImage );

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);

CGContextRelease(context);

free(imageData);

1 个答案:

答案 0 :(得分:0)

这是视网膜显示问题。经过一些谷歌搜索,我来到这篇文章,解释了默认的scaleFactor是1,这就是为什么纹理在我的设备上看起来很糟糕。

http://developer.apple.com/library/ios/#documentation/2DDrawing/Conceptual/DrawingPrintingiOS/SupportingHiResScreens/SupportingHiResScreens.html