iOS OpenGL 层和 UIScrollView
我正在 iPad 上创建一个绘图应用程序,用户可以在其中绘图并滚动绘图。 (想象一个 4000 像素宽、视口宽度为 1024 的画布)目前,我使用 OpenGL 进行绘图,宽度为 1024,效果很好。当我将 UIView 的帧大小更改为 4000 时,我得到“无法制作完整的帧缓冲区对象 8cd6”。当我将其宽度缩小到 2000 时,我最终得到了“古怪”的结果。我知道我可以正确操作框架,因为框架宽度为 500 会产生正确的结果。
我还考虑保留宽度 1024 并移动 OpenGL 层的相机,但这如何与我设置的 UIScrollView 一起使用?所以我不确定现在该做什么。有什么建议吗?
预先
感谢该代码主要基于 Apple 此处
I'm creating a drawing app on the iPad where the user can draw and scroll through the drawing. (Think of a canvas 4000 pixels wide with a view port width of 1024) At the moment, I'm using OpenGL for the drawing, and with a width of 1024, it works great. When I change the frame size of the UIView to 4000, I get "failed to make complete framebuffer object 8cd6". When I reduced it to a width of 2000, I ended up getting "wacky" results. I know I can manipulate the frame correctly, as having a frame width of 500 creates the correct result.
I was also thinking of leaving the width 1024 and moving the camera of the OpenGL layer, but how would that work with the UIScrollView that I setup? So I'm unsure on what to do at the moment. Any advice?
Thanks in advance
P.S. The code is largely based of GLPaint sample Apple provides here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你最好采用你在最后建议的方案——保持 OpenGL 视图静态并位于滚动视图之外,并移动其内容以匹配滚动视图的移动。
假设您使用的是
GLKView
,请实现您的glkView:drawInRect:
,以便它获得contentOffset
(并且可能还获得bounds
) 属性来自滚动视图并适当绘制。例如(假装您正在使用 GLES 1.0 只是因为矩阵操作方法众所周知):然后将您自己作为滚动视图的委托连接并执行:
确保每当滚动视图滚动时 GL 都会重绘。
I think you'd be best off with the scheme you suggest towards the end — keeping the OpenGL view static and outside of the scroll view, and moving its contents so as to match the movement of the scroll view.
Assuming you're using a
GLKView
, implement yourglkView:drawInRect:
so that it gets thecontentOffset
(and, probably, thebounds
) properties from your scroll view and draws appropriately. E.g. (pretending you're using GLES 1.0 just because the matrix manipulation methods are so well known):Then connect yourself as a delegate to the scrollview and just perform:
To ensure the GL redraws whenever the scroll view is scrolled.
我强烈建议您使用 OpenGL 相机进行缩放平移,而不是尝试在 UIScrollView 中使用它。设置起来会需要更多工作,但恕我直言,这最终是可行的方法。
I would strongly recommend to do your zooming in panning with your OpenGL camera instead of trying to use it in a UIScrollView. It will be a little more work to set up, but ultimately the way to go IMHO.