【发布时间】:2013-01-04 14:34:51
【问题描述】:
我有一个 UIView,我想将它映射到我的形状的面上。所有这些都有效,但我希望它可以在 iPhone 5 上使用视网膜图形。我将我的 openGL 层的 contentScale 属性设置为 2.0,但结果还是有点模糊。所以尺寸是正确的,就好像我在视网膜显示器上使用非视网膜图形来制作图像一样。所以我要做的“唯一”事情就是告诉 iPhone 这必须是像素的两倍。我尝试了 DarthMike 建议的解决方案,不幸的是无济于事。
我在这里初始化并将其添加到我的视图中:
MyOpenGLView *view = [[MyOpenGLView alloc] initWithFrame:CGRectMake(0, dY, 230,230) context:context];
view.contentScaleFactor = 2.0;
view.layer.contentsScale = 2.0;
view.delegate = view;
view.drawableDepthFormat = GLKViewDrawableDepthFormat16;
[view setupGL];
[self.view addSubview:view];
这里我将视图渲染到上下文中并将其添加为纹理
MyViewToBeTheTexture *textureView = [[MyViewToBeTheTexture alloc]initWithFrame:CGRectMake(0, 0, 230, 230)];
self.effect.texture2d0.enabled = true;
// make space for an RGBA image of the view
GLubyte *pixelBuffer = (GLubyte *)malloc(
4 *
textureView.bounds.size.width *
textureView.bounds.size.height);
// create a suitable CoreGraphics context
CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context =
CGBitmapContextCreate(pixelBuffer,
textureView.bounds.size.width, textureView.bounds.size.height,
8, 4*textureView.bounds.size.width,
colourSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colourSpace);
// draw the view to the buffer
[textureView.layer renderInContext:context];
// upload to OpenGL
glTexImage2D(GL_TEXTURE_2D, 0,
GL_RGBA,
textureView.bounds.size.width, textureView.bounds.size.height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glGenBuffers(1, &texArray);
glBindBuffer(GL_ARRAY_BUFFER, texArray);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 0,0);
glBufferData(GL_ARRAY_BUFFER, sizeof(TexCoords), TexCoords, GL_STATIC_DRAW);
【问题讨论】:
-
什么不起作用?更好地描述问题所显示的内容将有助于人们回答您的问题。
-
对不起@DarthMike。我只是想补充一些信息。图像看起来很模糊,我添加到视图中的任何 UILabel 也很模糊......
-
这是否也适用于 iPhone 4 视网膜? (不模糊)因为 iPhone 5 的内容比例应该相同,因为屏幕在 y 中只有更多像素。
-
在 iPhone 4 (retina) 上看起来几乎一样。
-
@DarthMike 奇怪的是,当我将 GL_TEXTURE_WRAP_S 和/或 GL_TEXTURE_WRAP_T 的参数设置为 GL_REPEAT 时,它根本不显示任何内容。
标签: opengl-es retina-display iphone-5