gpt4 book ai didi

ios - 如何在 IOS 5 上更改图层的分辨率

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:24:31 26 4
gpt4 key购买 nike

我正在 ios 5 上开发一个 opengl es 2.0 应用程序。我绘制一个纹理作为背景。当我旋转设备时,我需要旋转图层并更改图层的尺寸。问题是我可以更改图层的边界,但图层分辨率是相同的。我的意思是,如果我有一个边界为 1024*768 的图层,并且我将新图层边界定义为 768*1024,图层大小会发生变化,但是当我将 768*1024 纹理绘制为背景时,图像会变形。

我使用函数 canvasView.bounds = newCanvasRect;canvasView.frame = newCanvasRect; 来更改图层大小(其中 canvasView 是图层,newCanvasRect 是新边界).

有什么想法吗?

最佳答案

每次设备旋转新的高度和宽度时,您都必须销毁并重建帧缓冲区。使用 layoutsubviews 触发所有这些,当方向改变时调用:

- (void)layoutSubviews {
NSLog(@"layoutSubviews");
[EAGLContext setCurrentContext:_context];
[self destroyFramebuffer];
[self createFramebuffer];
}


- (void)destroyFramebuffer {
NSLog(@"destroy buffer");

glDeleteFramebuffers(1, &viewFramebuffer);
viewFramebuffer = 0;
glDeleteRenderbuffers(1, &viewRenderbuffer);
viewRenderbuffer = 0;
glDeleteRenderbuffers(1, &depthRenderbuffer);
depthRenderbuffer = 0;
}


- (BOOL)createFramebuffer {
NSLog(@"creating buffer");

glGenFramebuffers(1, &viewFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, viewFramebuffer);

glGenRenderbuffers(1, &viewRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);

// setup the renderbuffer to the context
[[EAGLContext currentContext] renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer *)self.layer];
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, viewRenderbuffer);

// Allocate color buffer backing based on the current layer size (get the current layer size)
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth);
glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight);

NSLog(@"backing width: %d height: %d",backingWidth, backingHeight);

// set up the depth buffer
glGenRenderbuffers(1, &depthRenderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, backingWidth, backingHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);

[self setupView];

return YES;
}

然后使用 backingWidth 和 backingHeight 重新创建投影矩阵。

关于ios - 如何在 IOS 5 上更改图层的分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12052983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com