Game Development Reference
In-Depth Information
Figure 7-18. All the primitives OpenGL ES can render
Let's go through all of these primitives really quickly:
Point : With a point, each vertex is its own primitive.
Line : A line is made up of two vertices. As with triangles, we can just have
2 × n vertices to define n lines.
Line strip : All the vertices are interpreted as belonging to one long line.
Line loop : This is similar to a line strip, with the difference being that OpenGL ES
will automatically draw an additional line from the last vertex to the first vertex.
Triangle : This we already know. Each triangle is made up of three vertices.
Triangle strip : Instead of specifying three vertices, we just specify number of
triangles + 1 vertices. OpenGL ES will then construct the first triangle from
vertices (v1,v2,v3), the next triangle from vertices (v2,v3,v4), and so on.
Triangle fan : This has one base vertex (v1) that is shared by all triangles. The first
triangle will be (v1,v2,v3), the next triangle (v1,v3,v4), and so on.
Triangle strips and fans are a little bit less flexible than pure triangle lists. But they can give a little
performance boost, as fewer vertices have to be multiplied by the projection and model-view
matrices. We'll stick to triangle lists in all our code, though, as they are easier to use and can be
made to achieve similar performance by using indices.
Points and lines are a little bit strange in OpenGL ES. When we use a pixel-perfect orthographic
projection—for example, our screen resolution is 320×480 pixels and our glOrthof() call uses
those exact values—we still don't get pixel-perfect rendering in all cases. The positions of the
point and line vertices have to be offset by 0.375f due to something called the diamond exit
rule . Keep that in mind if you want to render pixel-perfect points and lines. We already saw that
something similar applies to triangles. However, given that we usually draw rectangles in 2D, we
don't run into that problem.
Given that all you have to do to render primitives other than GL10.GL_TRIANGLES is use one of the
other constants in Figure 7-17 , we'll spare you an example program. We'll stick to triangle lists
for the most part, especially when doing 2D graphics programming.
Let's now dive into one more thing OpenGL ES offers us: the almighty model-view matrix!
Search WWH ::




Custom Search