问题描述
我是OpenGL ES的新手,我正在尝试使用GLKit。我的目标是开发一个非常简单的应用程序,以获得对OpenGL的良好感觉。
I'm new to OpenGL ES and I'm experimenting with GLKit. My goal is to develop a very simple app just to get a good feel of OpenGL.
我从Apple的示例代码(OpenGL ES游戏)开始,我实现了基本的手势控制:平移,缩放,旋转(轨迹球算法)。
I started with Apple's sample code (OpenGL ES game) and I implemented basic gesture controls: panning, zooming, rotating (trackball algorithm).
现在这样做了,我想玩不同的投影矩阵,我开始设计一个用户界面做到这一点:
Now that this is done, I wanted to play with the different projection matrices and I started to design a user interface to do just that:
唯一的问题当GLKViewController中的顶视图不是GLKView时,它不起作用。
The only problem is that it doesn't work when the top view in a GLKViewController isn't a GLKView.
是否可以将GLKView作为子视图并仍然保持冷静GLKViewController的功能?
Is it possible to have a GLKView as a subview and still retain the cool features of GLKViewController?
谢谢。
推荐答案
好的我找到答案。
图片中的OpenGL View Controller re必须是普通的UIViewController。对此视图控制器进行子类化,并在viewDidLoad中,以编程方式创建OpenGL视图控制器:
The "OpenGL View Controller" in the picture must be a normal UIViewController. Subclass this view controller and in the viewDidLoad, create programmatically your OpenGL View Controller:
- (void)viewDidLoad
{
[super viewDidLoad];
_openGLViewController = [[FZIOpenGLViewController alloc] initWithNibName:@"FZIOpenGLView" bundle:nil];
_openGLViewController.view.frame = _openGLView.frame;
[self.view addSubview:_openGLViewController.view];
}
在此代码中,_openGLView是一个表示GLKit View的IBOutlet 图片中。它基本上只是为了获得正确的尺寸。
In this code, _openGLView is an IBOutlet representing "GLKit View" in the picture. It's basically just there to get the right dimensions.
_openGLViewController是你的GLKViewController子类,它处理所有OpenGL。 .xib文件FZIOpenGLView.xib只是一个带有相应文件所有者的GLKView(FZIOpenGLViewController)。
_openGLViewController is your GLKViewController subclass that handles everything OpenGL. The .xib file FZIOpenGLView.xib is just a GLKView with the appropriate File Owner (FZIOpenGLViewController).
它的工作原理:
这篇关于嵌套的GLKView和GLKViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!