iOS enables graphical programming with three APIs (UIKIT, Core graphics, OpenGL es, and Glkit)

Source: Internet
Author: User
Tags uikit

These APIs contain drawing operations that are drawn in a graphical environment. A graphical environment contains the drawing parameters and all the device-specific information required for drawing, including the screen graphics environment, the offscreen bitmap environment, and the PDF graphics environment, which are used to draw graphics and images on the screen surface, a bitmap, or a PDF file. Drawing in a screen graphics environment is limited to drawing in an instance of a UIView class or its subclasses, and drawing directly on the screen, rendering in a offscreen bitmap or PDF graphics environment is not displayed directly on the screen.

First, UIKIT API

Uikit is a set of objective-c APIs that provide objective-c encapsulation of line graphics, quartz images, and color operations, and provide animations for 2D drawing, image processing, and user interface levels.

Uikit includes classes such as Uibezierpath (drawing lines, angles, ellipses, and other graphics), UIImage (display images), uicolor (color manipulation), Uifont and UIScreen (providing fonts and screen information), and bitmap graphics environments, The ability to draw and manipulate on a PDF graphics environment, as well as support for standard views, and support for printing functions.

In Uikit, the UIView class itself automatically creates a graphical environment (corresponding to the Cgcontext type of the core graphics layer) as the current graphical drawing environment when drawing. You can call the Uigraphicsgetcurrentcontext function when drawing to get the current graphical environment.

Second, Core Graphics and quartz 2D API

The Core graphics is a set of c-based APIs that support the drawing of vector graphics, lines, shapes, patterns, paths, tonsure, bitmap images, and PDF content.

Quartz 2D is the 2D rendering rendering engine in the core graphics. Quartz is resource-and device-independent, providing path rendering, anti-aliased rendering, tonsure fill patterns, images, transparent drawing and transparent layers, shading and shading, color management, coordinate transformations, fonts, offscreen rendering, PDF document creation, display, and analysis functions.

The Quartz 2D can be used with all graphics and animation technologies (such as core Animation, OpenGL ES, and UIKit).

The quartz is drawn using the paint mode.

The graphical environment used in Quartz is also represented by a class cgcontext.

A graphical environment can be used as a drawing target in quartz. When drawing with quartz, all device-specific features are included in the specific type of graphics environment you use, so you can draw the same image to different devices by providing different image environments for the same picture manipulation function, so you do the device independence of the image drawing.

The Quartz provides several graphical environments for applications such as:

1) Bitmap graphics environment, used to create a bitmap.

Use the function cgbitmapcontextcreate to create.

2) PDF graphic Environment, used to create a PDF file.

The Quartz 2D API provides two functions to create a PDF graphical environment:

Cgpdfcontextcreatewithurl, a core Foundation URL with a location as the PDF output to create a PDF graphics environment.

Cgpdfcontextcreate, use this function when you want the PDF to output to a data consumer.

3) window graphics environment, used to draw on a window.

4) Layer Environment (Cglayer), which is a offscreen drawing target associated with another graphical environment, uses a layer environment to optimize the performance of the drawing layer to the graphical environment in which it was created. The layer environment provides better offscreen rendering performance than the bitmap graphics environment.

The main classes offered by Quartz include:

Cgcontext: Represents a graphical environment;

Cgpath: Use vector graphics to create paths, and be able to fill and stroke;

Cgimage: Used to represent bitmaps;

Cglayer: Used to represent a drawing layer that can be used for repeated drawing and offscreen drawing;

Cgpattern: Used to denote pattern, used for repeating drawing;

Cgshading and cggradient: used to draw tonsure;

Cgcolor and cgcolorspace; used for color and color space management;

Cgfont, used to draw text;

Cgpdfcontentstream, Cgpdfscanner, Cgpdfpage, Cgpdfobject,cgpdfstream, cgpdfstring, etc. are used to create, parse, and display PDF files.

Third, OpenGL es and Glkit

OpenGL ES is a multi-functional open-standard c-based graphics library for embedded systems for visualizing 3D data. OpenGL is designed to transform a set of graphical calls to the underlying graphics hardware (GPU), which is performed graphically by the GPU for complex graphics operations and operations, enabling high-performance, frame-rate utilization of the 2D and 3D rendering capabilities provided by the GPU.

The OpenGL ES specification itself does not define the drawing surface and drawing window, so iOS must provide and create a opengles rendering environment to use it, create and configure Framebuffer to store drawing command results, and create and configure one or more render targets.

Use the Eaglcontext class provided by EAGL in iOS to implement and provide a rendering environment to maintain the hardware state that Opengles uses. Eagl is an objective-c API that provides interfaces that enable OpenGL ES to integrate with core animation and Uikit.

You must first initialize a Eaglcontext object before invoking any of the opengles features.

Each thread in an iOS app has a current context that uses or alters the state in this context when it calls the Opengles function.

Eaglcontext class method Setcurrentcontext: Used to set the current context of the current thread. The Eaglcontext class method CurrentContext returns the current context of the current thread. Before you can switch the two contexts of the same thread, you must call the Glflush function to ensure that previously committed commands are committed to the graphics hardware.

OpenGL ES can be used in different ways to render OpenGL ES content to different destinations: Glkit and Caeagllayer.

To create a full-screen view or to integrate OpenGL ES content with the Uikit view, you can use Glkit. When using Glkit, Glkit provides a class Glkview class itself that implements the rendering target and creates and maintains a framebuffer.

To make OpenGL ES content part of a core animation layer, you can use Caeagllayer as a rendering target, and you need to create additional framebuffer and implement and control the entire drawing process yourself.

Glkit is a set of objective-c classes that provide an object-oriented interface to use OpenGL ES to simplify the development of OpenGL ES applications. Glkit supports four key areas for 3D application development:

1) The Glkview and Glkviewcontroller classes provide a standard opengles view and associated rendering loops. Glkview can be used as a rendering target for opengles content, Glkviewcontroller provides control and animation of content rendering. View management and maintenance of a framebuffer, the application can only be painted in framebuffer.

2) Glktextureloader provides a way for applications to automatically load texture images into opengles image environments from various image formats supported by iOS, and to be able to perform appropriate conversions and support synchronous and asynchronous loading modes.

3) A mathematical database that provides OpenGL ES 1.1 functions such as vectors, matrices, four-tuple implementations, and matrix stack operations.

4) The Effect effect class provides a standard implementation of the common shading effect. Ability to configure effects and related vertex data, and then create and load the appropriate shader. Glkit includes three configurable shading effects classes: Glkbaseeffect implements the key lighting and material patterns in the OpenGL ES 1.1 specification, Glkskyboxeffect provides an implementation of the Skybox effect, Glkreflectionmapeffect includes reflection mapping support on a glkbaseeffect basis.

Use Glkview and opengles to draw the process:

1) Create a Glkview object

Glkview objects can be programmed or created and configured using Interface Builder.

When you use programming, you first create a context and then call the Initwithframe:context: method.

When using Interface Builder mode, after loading a glkview from storyboard, create a context and set it as the context property of the view.

The use of Glkit in iOS requires creating a graphics environment with OpenGL ES 2.0 or more context.

The Glkit view automatically creates and configures all of its Opengles framebuffer objects and renderbuffers, and you can control the properties of these objects by modifying the view's drawable properties.

2) Draw OpenGL content (publish Draw command)

Using the Glkit view to draw OpenGL content requires three sub-steps: Prepare the Opengles base, publish the Draw command, render the display to the core Animation. The Glkit class itself has implemented the first and third steps, and the user simply implements the second step by invoking the appropriate Opengles draw command in the view's method DrawRect or the view's proxy object Glkview:drawinrect: To draw the content.

The Glkviewcontroller class maintains a animation rendering loop (containing two methods, update and display) for continuous animation of complex scenes.

The alternating rate of the animation rendering cycle is indicated by the Glkviewcontroller property Framespersecond, and it is modified using the Preferredframespersecond property.

Iv. other graphic programming related APIs

1) Core Animation

Core Animation is a set of objective-c APIs that implements a high-performance composite engine and provides an easy-to-use programming interface that adds smooth motion and dynamic feedback to the user's UI.

Core Animation is the basis for Uikit to implement animations and transformations, and is also responsible for the composite functionality of the view. With core animation, you can create custom animations and fine-grained animation controls, creating complex layered 2D views that support animations and transformations.

Core animation is not part of the drawing system, but it is the infrastructure for displaying content in hardware compositing and manipulation. The core of this infrastructure is the Layer object, which is used to manage and manipulate the display content. Each view in iOS corresponds to a Layer object of core animation, and as with views, layers are organized into layer relationships trees. A layer captures the view content as a bitmap that is easily manipulated by the image hardware. Used in the middle of most applications as a management view, but you can also create separate layers into a layer tree to show what the view does not support.

The content of OpenGL ES can also be integrated with core animation content.

Http://blog.sina.com.cn/s/blog_1308b909c0102vzvf.html

iOS enables graphical programming with three APIs (UIKIT, Core graphics, OpenGL es, and Glkit)

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.