OpenGL ES Native Development Environment Xcode project establishment on iOS platform

Source: Internet
Author: User

The following build process is based on the hardware and software environment:

Launch: 8 GB memory 2012 gb ssd for Mac Book Air

Operating System: OS x 10.9.1

Development tools: Xcode 5


1. Create an empty iOS project in Xcode


Click Next. The project information filling window appears. Enter the information as instructed on the diagram. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.bkjia.com/uploadfile/Collfiles/20131225/2013122509342127.jpg" alt = "\">

Click Next and select the disk location of the Project Storage. There is a git version library under it. We recommend that you leave it blank. The version control function of xcode of this version is a little complicated. If you are familiar with it, you can check it.


Click the Create button to Create a project with the following directory structure in the target location:


AppDelegate. h and AppDelegate. m are application proxy classes. In the future, we will load the view controllers and views of OpenGL ES in this class.


So far, an empty project to be used has been established. Next, we will create classes related to OpenGL ES. Pay attention to the differences with the above engineering structure to clearly understand the files required by OpenGL ES.

I need to explain to the white brothers of iOS ,. h is the header file of the objective-c class. It has the same extension as c and c ++ but has different declarations ;. m is the implementation file of objective-c.

Objective-c white brother and white brother familiar with c ++ can refer to "c ++ University tutorial, separation of declaration and implementation has a good description. This is not the content of the language, but it is indeed well known based on object programming. The objective-c native does this. The so-called "conventions over configuration" means that good conventions are worth observing and remembering.


2. Create and present the GLESViewController class of OpenGL ES View Controller and the GLESView class of OpenGL ES View Controller class

Find the demo group in the xcode project navigator and create a GLES group under it. This part is The EGL part, the real OpenGL ES part, and then the group is created to be rewritten in C ++ later.

Create a GLESViewController controller class under the GLES group, inherit from UIViewController, and create a GSESView class.


The project navigator structure after the preceding groups and classes are created is as follows:


The View Controller and view of OpenGL ES have been established, which is in line with the habit of iOS development. We will not consider the OpenGL ES section first, and combine the two to present them in the empty project above.

Agile development is better at this point. After each task is done, you can test it and run the program as soon as possible to verify the availability of the added functions, in order to avoid bringing the problem to the subsequent steps and increase the difficulty of troubleshooting, this is also the main method of continuous integration. Make sure that the problem is divided into small blocks to implement one piece, and then integrated and tested, confirm that there is no problem, and proceed to the next step.

Just like building a house, before concrete is built, it is necessary to fully inspect cement, sand, gravel, and steel bars. After passing the qualification, the construction can be performed downward. Otherwise, the construction is correct and the concrete is released, after pouring out of the house, if the house collapsed, I really don't know which part of the house had a problem. It was a problem with the construction ratio, or the cement or gravel indicators were not enough. Do you know? I don't know each other.

Here we use xib to build the view, so we need to replace the initialization method initWithFrame with initWithCoder. The Code is as follows:

-(Id) initWithCoder :( NSCoder *) aDecoder {self = [super initWithCoder: aDecoder]; if (self) {// subsequent initialization operations here} return self ;}

In addition, you need to change the type of File's Owner in GLESViewController. xib to GLESViewController class, and the type of View to GLESView.

Add an attribute to the header file of the GLESViewController class to reference the View Controller view based on the GLESView type. You do not need to reproduce the conversion during use, and the controller controls its lifecycle:

// Weak reference the view held by UIViewController @ property (nonatomic, weak) IBOutlet GLESView * glesView;

Add an attribute to the header file of the GLESView class. The conversion does not need to be reproduced during use, and the view controls its lifecycle:

// Weak reference the Layer object held by the current view class @ property (nonatomic, weak) CAEAGLLayer * glesLayer;

The following method is used to overload the UIView:

+ (Class)layerClass {        return [CAEAGLLayer class];}

-(Void) layoutSubviews {// clear the background color glClearColor (0.0f, 1.0f, 0.0f, 1); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // set the glViewport (0, 0, self. frame. size. width, self. frame. size. height); // prepare the vertex and Texture buffer, light, and conversion matrix, and draw the image to the worker buffer. // display the worker buffer content [_ glesContext presentRenderbuffer: GL_RENDERBUFFER];}

To call the built-in view of the View Controller when the application starts, you need to modify the following code in the application proxy class:

# Import "AppDelegate. h "# import" GLESViewController. h "@ implementation AppDelegate-(BOOL) application :( UIApplication *) application metadata :( NSDictionary *) launchOptions {// create a GLESViewController instance GLESViewController * controller = [[GLESViewController alloc] initWithNibName: @ "GLESViewController" bundle: nil]; self. window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]; // set the GLESViewController instance created above as the Root View Controller of the window to display the initial content self. window. rootViewController = controller; self. window. backgroundColor = [UIColor whiteColor]; [self. window makeKeyAndVisible]; return YES;} @ end

Remember to add two frameworks: OpenGLES. framework and QuartzCore. framework, which correspond to the functions of GLES and EGL respectively.


It's no wonder that the descriptions written in Lao Luo's blog are directly followed by a rough feeling. I am still dizzy when this step is built and adjusted step by step, I wonder whether the above Code can be run after it is created.

Here, we only have a record to streamline the reconstruction work and do not confuse ourselves. Therefore, we will write such a building process in a step-by-step manner. When we are free, we will repeat it as above, let's see where the problem is wrong and fix it again.























Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.