In the following article we would like to introduce you to the basic concepts of OpenGL (important for 3D configurators). The answers to the following questions will be the focus of this article:

  • Why/When should use OpenGL?
  • How should you configure an iOS application to use the OpenGL technology together with GLKit.
opengl glkit e

What is OpenGL?

OpenGL, short for OpenGraphics Library, is a cross- language and -platform API for displaying 2D and 3D computer graphics. Here we will specifically discuss the ES (embedded system) version used on mobile devices (iOS and Android). OpenGL`s main competitor is D3D (or Direct3D), a Windows technology that is part of the well-known DirectX API.

Erhöhen Sie Ihr Verkaufsvolumen.

Mit unseren 3D-Konfiguratoren erreichen Sie mehr kommerziellen Erfolg auf Website..

Simply put, OpenGL is a way to program the GPU and it is the heart of almost everything we see on a computer / smartphone / tablet today. EvenUIKit relies on OpenGL. OpenGL is the technology behind graphic rendering.

In Apple`s technology stack there are different frameworks to do different things. You should use CoreGraphics and CoreImage to edit images and filters, CoreAnimation to animate views, SceneKit to manage 3D objects. So why and when should you use OpenGL? In short, if you want to access the powerful features of your device`s graphics card (GPU). By the way, OpenGL is currently the only way to display a 3D object in a native iOS application.

By the way, if someone has told you that OpenGL is the most suitable and powerful tool for creating video games, that`s only part of the truth. Certainly OpenGL supports all modern games (except those running on MSFT D3D), but hardly any of them (except for large studios) are rewritten from scratch. And if you`re interested in such topics, you might want to try other frameworks (whether 2D or 3D) that have a higher level of abstraction.

OpenGL ES.

So, let`s focus on OpenGL ES. Most of the things we`ll cover will also apply to OpenGL, some of which are specific to the embedded version. From now on, when we talk about OpenGL, we mean the ES version. Let us briefly discuss some important points that are at the heart of OpenGL:

  • State machine: OpenGL is a state machine, which means that when you set an option or bind a buffer, that option or buffer is used until you “disable” it. As an example glEnable enables OpenGL`s depth testing and as such it remains until it is explicitly disabled.

Erhöhen Sie Ihr Verkaufsvolumen.

Mit unseren 3D-Konfiguratoren erreichen Sie mehr kommerziellen Erfolg auf Website..

  • Coordinate system: The OpenGL coordinate system differs from that of UIKit in that it originates in the center of the screen. With a too simple explanation I would say that when mapping a 3D space its x = 0, y = 0, z = 0 coordinates are in the center of the screen of your device. Without applying matrix transformations to the view, the coordinates of the plane of (-1, -1) the lower left corner of the screen move to (1, 1) the upper right corner of the screen.
  • Vertices: Vertices represent the data associated with the 3D objects that OpenGL is to display on the screen. Vertex data mist be loaded into the GPU for the Vertex shader to process it. Vertices are usually defined by their position (in a 3D space), color, normals, and any associated textures.
  • Working with primitives: Finally, you need to tell OpenGL how to interpret the data stream you have entered into the shaders by specifying how the primitives, i.e. points, lines and triangles, are to be drawn.

OpenGL ES v. 1 vs. 2.

Starting with iOS 3.0, Apple supports OpenGL ES 2 and has strongly encouraged developers to upgrade to the lastest version of the graphics library. The main difference between v.1 and v.2 is the so-called programmable pipeline. Basically, OpenGL ES 2 provides and requires the definition of own shaders (specific programs running on the GPU and not on the CPU).

While in v.1 you can pass anything but raw data to the GPU, in v.2 you have to define your own shaders. This means: more performance, more work for the developer. OpenGL ES v.2 indeed requires you to write:

  • a vertex shader that applies calculations (transformations) once for each verte through the pipeline,
  • a fragment shader that applies color or texture data to the fragment, i.e. after the primitive has been t´rasterized.

Since this was one of the main reasons why developers didn`t move towards v.2, Apple introduced a new framework with iOS 5, GLKit.

Erhöhen Sie Ihr Verkaufsvolumen.

Mit unseren 3D-Konfiguratoren erreichen Sie mehr kommerziellen Erfolg auf Website..

GLKit.

So much for theory. If, for example, you would like to learn WebGL, we recommend that you work through our WebGL tutorial series. At this point, it`s enough to say that GLKit offers some ways to take care of some of the harder bits and repetitive OpenGL things. Apart from some useful mathematical tools for dealing with matrices, quaternions, affine and homogeneous trasnformations, and similar other frightening elements. GLKit has introduced GLKBaseEffect, a class that eliminates all the complexity of shaders. We will discuss this in more detail in a future article.