GLKit briefly
Before you learn about the GLKit framework, attach the GLKitAPI, apple’s official documentation
GLKit framework is designed to simplify application development based on OpenGL/OpenGL ES and accelerate the development of OpenGL/OpenGL ES applications
GLKit function
- Provide high-performance Math libraries: Provide common vector, quaternion, and matrix operations.
- Texture loading: Allows various textures to be loaded in the background
GLKTextureLoader
Class to load the - Common shaders are available: the following three shaders are available
- GLKBaseEffect
- GLKReflectionMapEffect
- GLKSkyboxEffect
- Provides view views and view controllers: GLKView and GLKViewController
- GLKView: provides a drawing place, inherited from UIView
- GLKViewController: used to manage and render the contents of a drawing view, inherited from UIViewController)
Render OpenGL ES content using GLKit view
The figure below is drawn from Apple’s official document Drawing with OpenGL ES and GLKit
There are three main steps to display images through GLKit
- GLKView creation and configuration
- Draw the graph using GLKView objects and store it in the frame cache
- Data is read from the frame cache and displayed on the screen
GLKit commonly used API
GLKit texture loading
GLKTextureInfo creates OpenGL texture information
The common attributes are listed in the table
attribute | instructions |
---|---|
name | The name of the texture in the OpenGL context |
target | The target of the texture binding |
height | The height of the loaded texture |
width | Load the width of the texture |
textureOrigin | Loads the origin position in the texture |
alphaState | Loads the alpha component state of the texture |
containsMipmaps | Boolean value, whether the loaded texture contains an MIP map |
GLTextureLoader simplifies loading textures from various resource files
- Initialize the
Initialization method | instructions |
---|---|
– initWithSharegroup: | Initialize a new texture to load into the object |
– initWithShareContext: | Initialize a new texture loading object |
- Load processing from a file
Loads the processing method from a file | instructions |
---|---|
+ textureWithContentsOfFile:options:errer: | Loads a 2D texture image from a file and creates new textures from the data |
– textureWithContentsOfFile:options:queue:completionHandler: | Asynchronously loads 2D texture images from files and creates new textures based on the data |
- Load processing from the URL
Load the texture method from the URL | instructions |
---|---|
– textureWithContentsOfURL:options:error: | Load a 2D texture image from the URL and create a new texture from the data |
– textureWithContentsOfURL:options:queue:completionHandler: | Asynchronously loads a 2D texture image from the URL and creates a new texture based on the data |
- Create textures from in-memory representations
Create texture methods from in-memory representation | instructions |
---|---|
+ textureWithContentsOfData:options:errer: | Load a 2D texture image from memory space and create a new texture based on the data |
– textureWithContentsOfData:options:queue:completionHandler: | Asynchronously loads 2D texture images from memory space and creates new textures from data |
- Create textures from CGImages
Create a texture method from CGImages | instructions |
---|---|
– textureWithCGImage:options:error: | Load a 2D texture image from a Quartz image and create a new texture from the data |
– textureWithCGImage:options:queue:completionHandler: | Asynchronously loads a 2D texture image from a Quartz image and creates a new texture based on the data |
- Load multidimensional create textures from the URL
Load the multidimensional create texture method from the URL | instructions |
---|---|
+ cabeMapWithContentsOfURL:options:errer: | Load a vertical map texture image from a single URL and create a new texture based on the data |
– cabeMapWithContentsOfURL:options:queue:completionHandler: | Asynchronously loads a cube map texture image from a single URL and creates a new texture based on the data |
- Create textures by loading multidimensional data from a file
File loads multidimensional data to create texture methods | instructions |
---|---|
+ cubeMapWithContentsOfFile:options:errer: | Load a cube map texture object from a single file and create a new texture from the data |
– cubeMapWithContentsOfFile:options:queue:completionHandler: | Asynchronously loads a cube map texture object from a single file and creates a new texture from the data |
+ cubeMapWithContentsOfFiles:options:errer: | Load cube map texture images from a series of files and create new textures from the data |
-cubeMapWithContentsOfFiles:options:options:queue:completionHandler: | Asynchronously loads cube map texture images from a series of files and creates new textures from the data |
GLKit OpenGL ES View rendering API
GLKView uses OpenGL ES as the default view for drawing content. The common API and properties are shown below
- Initialize the view
attribute | instructions |
---|---|
– initWithFrame:context: | Initialize the new view |
- Set the agent
attribute | instructions |
---|---|
delegate | View proxy |
- Configure the frame cache object
attribute | instructions |
---|---|
Configure the frame cache object | drawableColorFormat |
drawableDepthFormat | Deep render cache format |
drawableStencilFormat | Template render cache format |
drawableMultisample | Multisample cache format |
– Frame cache property
attribute | instructions |
---|---|
drawableHeight | Height, in pixels, of the underlying cache object |
drawableWidth | The width in pixels of the underlying cache object |
- Draws the contents of the view
attribute | instructions |
---|---|
context | Use the OpenGL ES context used to draw the view content |
drawableStencilFormat | Bind the underlying FrameBuffer object to OpenGL ES |
enableSetNeedsDisplay | Boolean value that specifies whether the view responds to messages that invalidate the view’s contents |
snapshot | Draws the view content and returns it as a new image object |
methods | instructions |
---|---|
– bindDrawable | Deep render cache format |
– display | Redraw the view content immediately |
- Delete the view FrameBuffer object
methods | instructions |
---|---|
– deleteDrawable | Deletes a drawable object associated with a view |
GLKViewDelegate is used for the GLKView object callback method
- Draw the contents of the view (proxy must be implemented !!!!)
attribute | instructions |
---|---|
– glkView:drawInRect: | Draw view content (proxy must be implemented) |
GLKViewController Is a view controller that manages the OpenGL ES rendering loop
- update
methods | instructions |
---|---|
– (void) update | Update view content |
– (void) glkViewControllerUpdate: | Update the view controller display |
- Configure frame Rate
attribute | instructions |
---|---|
preferredFramesPerSecond | The rate at which the view controller invokes the view and updates the view content |
framesPerSencond | The actual rate at which the view controller invokes the view and updates its contents |
- Configure the GLKViewDelegate proxy
attribute | instructions |
---|---|
delegate | Proxy for the view controller |
- Control frame update
ResumeOnDidBecomeActive Boolean that indicates whether the view control automatically resumes the rendering loop when the current application becomes active
attribute | instructions |
---|---|
paused | Boolean value, whether the render loop has been paused |
pausedOnWillResignActive | Boolean value, whether the view controller automatically pauses the rendering loop when the current program reactivates the active state |
resumeOnDidBecomeActive | Boolean value, which controls whether the view automatically resumes the rendering loop when the current application becomes active |
- Get updated information about the View
attribute | instructions |
---|---|
frameDisplayed | The number of frame updates sent by the view controller since its creation |
timeSinceFirstResume | The amount of time that has elapsed since the view controller first resumed sending the update event |
timeSinceLastResume | The amount of time since the last time the view controller resumed sending the update event |
timeSinceLastUpdate | The amount of time that has elapsed since the last view controller called the delegate method |
timeSinceLastDraw | The amount of time that has elapsed since the last view controller called the delegate method |
GLKViewControllerDelegate * * * * render loop callback square method
- Handles more updated events
The callback method | instructions |
---|---|
– glkViewControllerUpdate: | Called before displaying each frame, similar to the RenderScene function in OpenGL |
- Pause/resume notification
The callback method | instructions |
---|---|
– glkViewController : willPause: | Called before the render loop pauses or resumes |
GLKBaseEffect
A simple lighting/shading system for shader based OpenGL rendering
- Named Effect
attribute | instructions |
---|---|
label | Give an Effect a name |
- Configure the model view transformation
attribute | instructions |
---|---|
transform | Binding effects are applied to vertex data model views, projections, and texture transformations |
- Configure lighting effects
attribute | instructions |
---|---|
lightingType | Used to calculate the lighting strategy for each fragment,GLKLightingType |
GLKLightingType enumeration | instructions |
---|---|
GLKLightingTypePerVertex | Represents performing lighting calculations on each vertex in the triangle and then interpolating in the triangle |
GLKLightingTypePerPixel | The input representing the lighting calculation is inserted into the triangle, and the lighting calculation is performed on each fragment |
- Configure the illumination
attribute | instructions |
---|---|
lightModelTwoSided | Boolean value representing computed illumination on both sides of the primitive |
material | Calculates the material properties to use for rendering pixel lighting |
lightModelAmbientColor | Environment color, apply the effect to render all primitives. |
light0 | The first lighting property in the scene |
light1 | The second lighting property in the scene |
light2 | The third lighting property in the scene |
- Configure the texture
attribute | instructions |
---|---|
texture2d0 | The first texture property |
texture2d1 | Second texture property |
textureOrder | The order in which textures are applied to render primitives |
- Configuration atomization
attribute | instructions |
---|---|
fog | Fog property applied to the scene |
- Configuring color Information
attribute | instructions |
---|---|
colorMaterialEnable | A Boolean value that indicates whether the color vertex property is used when calculating light interaction with the material |
useConstantColor | Boolean value indicating whether constant colors are used |
constantColor | Constant color is used when no per-vertex color data is supplied |
- Prepare the rendering effect
methods | instructions |
---|---|
– prepareToDraw | Prepare the rendering effect |
Note 1: GLKit has a maximum of 3 lights and 2 textures. 2. Constant color: black