OpenGLES From the Ground Up, Part 1: Basic Concepts
OpenGL Data Types:
- OpenGL is a cross-platform API, and the size of data types can vary depending on the programming language being used as well as the underlying processor (64bit, 32bit,16bit).
- OpenGL maintains in own custom data types. When passing data to the OpenGL you need thru the OpenGL Data types.
Here are OpenGL ES Data types:-
GLenum: An unsigned integer used for GL-specific enumerations. Most commonly used to tell OpenGL the type of data stored in an array passed by pointer to indicate that the array is made up GLfloats.
GLboolean: Used to hold a single Boolean value. OpenGLES also declares its own true and false values (GL_TRUE and GL_FALSE) to avoid platform and language differences. You can also pass YES or NO it won't heart you but it is good to following the GL defined values.
GLbitfield: These are four-byte integers used to pack multiple Boolean values (up to 32) into single variables using bitwise operators.
GLbyte: A Signed, one-byte integer capable of holding a value from -128 to 127
GLShort: A Signed, two-byte integer capable of holding a value between -32,768 to 32,767
GLint: A Signed four-byte integer capable of holding a value between -2,147,483,648 and 2,147,483,647
GLsizei: A signed, four-byte integer used to represent the size of data, similar to size_t in C.
GLubyte: An unsigned, two-byte integer capable of holding a value between 0 and 255
GLushort: A unsigned, two-byte integer capable of holding a value between 0 and 65,535
GLuint: An unsigned, fout-byte integer capable of holding value between 0 and 4,294,967,295
GLfloat:
GLclampf:
GLvoid:
GLfixed:
GLclampx:
The Point or Vertex:
- The atomic unit in 3D graphics is called the point or vertex.
- These represent a single spot in three dimensional space and are used to build more complex objects.
Definition of Polygon: In geometry polygon is a plane figure that is bounded by a closed path or circuit, composed of finite sequence of straight line segments.
- Polygons are prepared out of these points and objects prepared out of these polygons.
- Open GL ES only supports the use of three sided polygon (Aka triangle)
- Select an arbitrary point in space and call it the Origin.
- You can then designate any point in space referencing the origin
- Core Graphics, which is another framework for doing graphics on iPhone uses a slightly different coordinate system in that the y axis decreases as it goes up from the origin, and increases as it goes down.
- Since any object's location in three-dimensional space can be represented by three values, an object's position is generally represented in OpenGL by the use of three GLfloat variables.
GLfloat vertex [3];
vertex [0] = 10.0; - > x-position
vertex [1] = 23.75; - > y-position
vertex [2] = -12.532; - > z-position
- In OpenGL ES, you generally submit all the vertices that make up some or all the objects in your scene as a vertex array.
- A vertex array is simply an array of values that contains the vertex data for some or all of the objects in the world.
- we can define a data structure to hold a single vertex, like this
typedef struct {
GLfloat x;
GLfloat y;
GLfloat z;
} Vertex3D;
By doing this, our code becomes much more readable:
Vertex3D vertex;
vertex.x = 10.0;
vertex.y = 13.75;
vertex.z = -12.532;
- Distance between two points in three-dimensional space with this simple inline function:
We can implement this formula to calculate the straight-line distance between any two points in three-dimensional space with this simple inline function:
static inline GLfloat Vertex3DCalculateDistanceBetweenVertices (Vertex3D first, Vertex3D second)
{
GLfloat deltaX = second.x - first.x;
GLfloat deltaY = second.y - first.y;
GLfloat deltaZ = second.z - first.z;
return sqrtf(deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ );
};
{
GLfloat deltaX = second.x - first.x;
GLfloat deltaY = second.y - first.y;
GLfloat deltaZ = second.z - first.z;
return sqrtf(deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ );
};
-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------
Triangles:
Since OpenGL ES only support Triangles, we can also create a data structure to group three vertices into single triangle object.
typedef struct {
Vertex3D v1;
Vertex3D v2;
Vertex3D v3;
}Triangle3D;
Winding: which just means that the order in which the vertices are drawn matters.
Front Face: Unlike the objects in the real world which is having two sides. The objects in the OpenGL have one side, which is considered the front face, which is facing the viewer.
Blackface: The side which is not visible and the side which isn’t drawn are called a blackface.
- OpenGL determines which front face and which is the back face by looking at the drawing order of the vertices.


No comments:
Post a Comment