GLPaint 示例:如何以编程方式创建视图?
我需要在图像上绘制一些内容,例如 GLPaint 示例,但我需要创建 EAGL 表面,以编程方式渲染 OpenGL。
示例中是在 MainWindow.xib 中实例化的
如果我尝试使用以下内容以编程方式创建视图:
self.drawingView = [[PaintingView alloc] initWithCoder:nil];
drawingView.frame = CGRectMake(0, 0, 320, 380);
[self.view addSubview:drawingView];
我收到此错误:
failed to make complete framebuffer object 8cd6
也许与 init 有关的内容?有什么提示吗?谢谢。
I need to draw something on an image, like in the GLPaint sample from Apple, but I need to create the EAGL surface where render the OpenGL programmatically.
In the sample is instatiated in the MainWindow.xib
If I try to create the view programmatically with something like:
self.drawingView = [[PaintingView alloc] initWithCoder:nil];
drawingView.frame = CGRectMake(0, 0, 320, 380);
[self.view addSubview:drawingView];
I got this error:
failed to make complete framebuffer object 8cd6
Maybe something related to the init? Any hints? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速浏览一下源代码,Apple 已将 PaintingView 的所有重要初始化内容放在
initWithCoder:
中,从第 77 行到第 168 行。这是 NSCoding 协议的一部分,用于存档和取消存档文件中的对象。如果您调用initWithCoder:nil
,很可能 initWithCoder 的 UIView 实现无法获取它需要的一些相关值。据猜测,它的大小可能开始为零,这对于帧缓冲区对象来说不是有效的大小。我建议您将
initWithCoder:(NSCoder *)coder
替换为initWithFrame:(CGRect)frame
,在第 86 行的 super 上调用相同的方法。为了获得更好的实现,实现 initWithFrame: 和 initWithCoder:,让两者为if((self = [super initWithXXX:argument]))
块中包含的所有内容调用公共部分。From a quick glance inside the source, Apple have put all of the significant initialisation stuff for PaintingView inside
initWithCoder:
, from lines 77 to 168. That's part of the NSCoding protocol, which is used for archiving and unarchiving objects from files. If you callinitWithCoder:nil
, quite probably the UIView implementation of initWithCoder isn't able to get some relevant value that it needs. At a guess, it probably starts being size zero, which isn't a valid size for a framebuffer object.I'd suggest you replace
initWithCoder:(NSCoder *)coder
withinitWithFrame:(CGRect)frame
, calling the same on super at line 86. For an even better implementation, implement both initWithFrame: and initWithCoder:, having the two call a common section for everything enclosed in theif((self = [super initWithXXX:argument]))
block.