简体   繁体   English

如何在UIView中绘制opengl

[英]how to draw opengl es in a UIView

I want to draw my opengl es animation in a customed UIView, how can I do it. 我想在自定义的UIView中绘制我的opengl es动画,我该怎么做。 I find that I need to override the drawRect method. 我发现我需要重写drawRect方法。 Which is in the below. 在下面。

#import "myView.h"

@implementation myView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    // Initialization code
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end

I have draw a View using interface builder, how can I link to that view and draw(call) my class of opengl animation. 我已经使用界面构建器绘制了一个View,如何链接到该视图并绘制(调用)我的opengl动画类。 Can anyone please write a little bit specific. 任何人都可以写点具体信息吗? I'm a beginner. 我是初学者。 Thanks. 谢谢。

As the other poster said, you don't use drawRect to implement OpenGL in a view. 就像其他海报所说的那样,您不使用drawRect在视图中实现OpenGL。 You attach an OpenGL layer to the view. 您将OpenGL图层附加到视图。

EAGLView is one way. EAGLView是一种方法。 If you're willing to limit your app to iOS 5 or later, you might want to look at GLKit. 如果您希望将应用程序限制为iOS 5或更高版本,则可能需要查看GLKit。 That does a lot of the setup for you. 那为您做了很多设置。

Beware, though. 不过要当心。 OpenGL is in no way, shape, or form a beginner's API. OpenGL绝不构成或构成初学者的API。 It's big, complex, and tricky to use. 它庞大,复杂且难以使用。 There is a HUGE learning curve. 学习曲线很大。 I've been programming for about 30 years, and it just about made my head explode when I first started studying it. 我已经进行了30年的编程,刚开始学习它时,我的头就爆了。

One possibility you have is making your view manage an CAEAGLLayer (vs. a normal CALayer ). 一种可能是使视图管理CAEAGLLayer (相对于常规CALayer )。 Then the CAEAGLLayer would render your GL drawing code. 然后, CAEAGLLayer将呈现您的GL绘图代码。

Instead of tryng to subclass yourself UIView , I suggest you to take a look at the EAGLView class provided by Apple in some of the SDK samples. 建议您不要尝试将自己的UIView子类化,而建议您看一下Apple在某些SDK示例中提供的EAGLView类。 Have a look at this sample from Apple showing how EAGLView is defined and how it can be used. 看看Apple的这个示例,它显示了EAGLView的定义方式以及使用方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM