Friday, May 13, 2011

Learning OpenGL ES 2.0 by Baby Steps

When create a openGL ES 2.0, you will get AppDelegate, xib file, shader.fsh&shader.vsh, EAGLView.h&EAGLView.m, and viewController.

Inside your AppDelegate, there should be a UIView and all the other control should be inside the viewController.

kEAGLRenderingAPIOpenGLES1 or kEAGLRenderingAPIOpenGLES1 decides whether app supports OpenGL ES 1.0 or OpenGL ES 2.0

OpenGL initialization should be in EAGLView file.

glLinkProgram links the shader.

Apple recommends set eaglLayer.opaque = true.

iPhone's refresh rate: 60/second.

ratio: 320/480. iPhone's original point is in upper left corner. OpenGL ES set original point in the middle of the screen: 160/240.

OpenGL ES can only draw Triangles. Triangles, Triangle_Strip and Triangle_Fan.

iPhone's aspect ratio: 1:1.5. So be careful about drawing square on the screen.

Make changes:
if change uniform in shader, things need to be changed:
1. Uniform index, enum in ViewController
2. drawFrame
3. loadShaders
4. in your shaders.

According to the Khronos group’s ‘The OpenGL ES Shading Language’ specification 1.0.17, the minimum number of uniform vectors a vertex shader should support is 128, and the minimum number of uniform vectors that a fragment shader should support is 16.

Attribute support is even more limited, with a minimum of 8 attributes in a vertex shader. When I say ‘a minimum of 8’, that means that the implementation of OpenGL ES is free to support more than 8, but it must support at least 8.