Bas*_*ane 4 opengl-es objective-c uiscrollview ios
我正在iPad上创建一个绘图应用程序,用户可以在其中绘制和滚动绘图.(想象一个4000像素宽的画布,视口宽度为1024)目前,我正在使用OpenGL进行绘图,宽度为1024,效果很好.当我将UIView的帧大小更改为4000时,我得到"未能完成帧缓冲对象8cd6".当我把它缩小到2000的宽度时,我最终得到了"古怪"的结果.我知道我可以正确操作框架,因为框架宽度为500会产生正确的结果.
我还在考虑离开宽度1024并移动OpenGL图层的相机,但是如何使用我设置的UIScrollView呢?所以我不确定此刻该做什么.有什么建议?
提前致谢
PS代码主要是基于GLPaint样品的苹果提供了这里
我认为你最好使用你建议的方案 - 保持OpenGL视图静态和滚动视图之外,并移动其内容以匹配滚动视图的移动.
假设您正在使用a GLKView,请实现您的,glkView:drawInRect:以便从滚动视图中获取contentOffset(并且可能是bounds)属性,并进行适当的绘制.例如(因为矩阵操作方法众所周知,假装你正在使用GLES 1.0):
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// displayArea will be the area the scroll view is
// currently displaying; taking just the bounds would
// likely be fine too
CGRect displayArea;
displayArea.origin = scrollView.contentOffset;
displayArea.size = scrollView.bounds.size;
// assuming (0, 0) in the GL view is in the centre,
// we'll adjust things so that it's in the corner ala
// UIKit
CGPoint centre = CGPointMake(
displayArea.origin.x + displayArea.size.width*0.5f,
displayArea.origin.y + displayArea.size.height*0.5f);
glPushMatrix();
// apply the scroll as per the scroll view
// so that its centre is aligned with our centre
glTranslatef(-centre.x, -centre.y, -1);
/* rest of drawing here */
glPopMatrix();
}
Run Code Online (Sandbox Code Playgroud)
然后将自己作为代理连接到scrollview,然后执行:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[glView setNeedsDisplay];
}
Run Code Online (Sandbox Code Playgroud)
滚动滚动视图时确保GL重绘.
| 归档时间: |
|
| 查看次数: |
2947 次 |
| 最近记录: |