OpenGL ES 1.1 is the 3D graphics API used by the iPhone and while it is extremely powerful it can often be very intimidating to the beginner. One of the main issues is that while there is a great deal of documentation and tutorials for OpenGL like the “Red Book” and other sources online there seem to be very few available resources for Open GL ES. This session will introduce the concepts of developing with OpenGL ES 1.1 and demonstrate them via sample code.
4. Setting position
via GLfloat
GLfloat vertex[3];
vertex[0] = 20.0 //x
vertex[1] = 23.0 //y
vertex[2] = 15.75 //z
5. Vertex Array
• A block of vertex data (vertex
coordinates, texture coordinates, etc) for
some or all objects.
• size determined by number of vertices
submitted x 3 for 3d objects (or 2 for 2d
objects)
• vertex array of 6 triangles =
6 x 3 x 3 = 54
6. Data structure to
hold vertex
typedef struct {
GLfloat x;
GLfloat y;
GLfloat z
} vertex3D;
11. Triangles
A triangle is the same as an array of 9 GLfloats
typedef struct
{
Vertex 3D v1;
Vertex 3D v2;
Vertex 3D v3
} Triangle3D;
12. Triangles Terminology
• front face - face the viewer sees of an
object
• winding - order in which vertices are drawn
matters for mechanics of which direction
an object faces
• backface - side that is not drawn
• backface culling - process to determine
which triangles are visible ot the user
13. Viewports
• Portion of viewable space that can be seen
by viewer
• Perspective Viewport- Converging lines and
items change size based on distance
• Orthogonal Viewport - No converging lines
and changes in size to communicate
distance
17. Lights
• You can have up to 8 lights
• must be enabled using
• glEnable(GL_LIGHT0);
• Specify properties of light
18. Components
of Light
• Ambient - No clear source.
• Diffuse - even directional light on side of
object that faces light
• specular - highlight or hotspot
25. Color
• Defined as the color of light that an object
reflects.
• OpenGL allows us to specify color for each
component of light(specular, diffuse &
ambient) to material.
26. Color on
Material
GLfloat ambientAndDiffuse[] = {0.0, 0.1, 0.9, 1.0};
glMaterialfv(GL_FRONT_AND_BACK,
GL_AMBIENT_AND_DIFFUSE, ambientAndDiffuse);
//OpenGL ES only supports applying material to
FRONT_AND_BACK
27. Colors on different
components of light
GLfloat ambient[] = {0.0, 0.1, 0.9, 1.0};
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
GLfloat diffuse[] = {0.0, 0.1, 0.9, 1.0};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
28. Shininess on
Specular
GLfloat specular[] = {0.3, 0.3, 0.3, 1.0};
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR,
specular);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 25.0);
//tighter hotspot with shininess at 25 than default
50.
29. Emission
//giving and object a glow
GLfloat emission[] = {0.0, 0.4, 0.0, 1.0};
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION,
emission);
33. Thank you
• A special thanks to Jeff Lamarche who’s
series on Open GL ES from the ground up
served as a major resources for this
presentation and who’s openGL template I
used in several examples. I highly
recommend that you check out the series
at:
• http://iphonedevelopment.blogspot.com/2009/05/
opengl-es-from-ground-up-table-of.html