Introduction to Computer Graphics with OpenGL ES First Edition Junghyun Han pdf download
Introduction to Computer Graphics with OpenGL ES First Edition Junghyun Han pdf download
https://textbookfull.com/product/introduction-to-computer-
graphics-with-opengl-es-first-edition-junghyun-han/
https://textbookfull.com/product/computer-graphics-programming-
in-opengl-with-java-gordon/
https://textbookfull.com/product/computer-graphics-through-
opengl-third-edition-guha/
https://textbookfull.com/product/computer-graphics-through-
opengl-from-theory-to-experiments-sumanta-guha/
https://textbookfull.com/product/computer-graphics-programming-
in-opengl-with-java-2nd-edition-v-scott-gordon/
Computer Graphics Programming in OpenGL Using C++,
Third Edition Gordon Phd
https://textbookfull.com/product/computer-graphics-programming-
in-opengl-using-c-third-edition-gordon-phd/
https://textbookfull.com/product/introduction-to-mechanism-
design-with-computer-applications-first-edition-b-dyer/
https://textbookfull.com/product/introduction-to-computer-
graphics-a-practical-learning-approach-1st-edition-fabio-
ganovelli/
https://textbookfull.com/product/learn-opengl-learn-modern-
opengl-graphics-programming-in-a-step-by-step-fashion-1st-
edition-joey-de-vries/
https://textbookfull.com/product/computer-graphics-with-open-
gl-4th-edition-donald-d-hearn/
Introduction to
Computer Graphics
with OpenGL ES
Introduction to
Computer Graphics
with OpenGL ES
JungHyun Han
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
This book contains information obtained from authentic and highly regarded sources. Reasonable
efforts have been made to publish reliable data and information, but the author and publisher cannot
assume responsibility for the validity of all materials or the consequences of their use. The authors and
publishers have attempted to trace the copyright holders of all material reproduced in this publication
and apologize to copyright holders if permission to publish in this form has not been obtained. If any
copyright material has not been acknowledged please write and let us know so we may rectify in any
future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or
hereafter invented, including photocopying, microfilming, and recording, or in any information
storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access
www.copyright.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc.
(CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization
that provides licenses and registration for a variety of users. For organizations that have been granted
a photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and
are used only for identification and explanation without intent to infringe.
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
Dedication
Preface xiii
2 Mathematics: Basics 7
2.1 Matrices and Vectors . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Coordinate System and Basis . . . . . . . . . . . . . . . . . . 9
2.3 Dot Product . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.4 Cross Product . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.5 Line, Ray, and Linear Interpolation . . . . . . . . . . . . . . 13
3 Modeling 17
3.1 Polygon Mesh . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1.1 Polygon Mesh Creation∗ . . . . . . . . . . . . . . . . . 19
3.1.2 Polygon Mesh Representation . . . . . . . . . . . . . . 23
3.2 Surface Normals . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.2.1 Triangle Normals . . . . . . . . . . . . . . . . . . . . . 24
3.2.2 Vertex Normals . . . . . . . . . . . . . . . . . . . . . . 25
3.3 Polygon Mesh Export and Import . . . . . . . . . . . . . . . 26
vii
viii Contents
5 Vertex Processing 53
5.1 World Transform Revisited . . . . . . . . . . . . . . . . . . . 54
5.2 View Transform . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.2.1 Camera Space . . . . . . . . . . . . . . . . . . . . . . 57
5.2.2 View Matrix for Space Change . . . . . . . . . . . . . 58
5.3 Right-hand System versus Left-hand System . . . . . . . . . 60
5.4 Projection Transform . . . . . . . . . . . . . . . . . . . . . . 62
5.4.1 View Frustum . . . . . . . . . . . . . . . . . . . . . . . 62
5.4.2 Projection Matrix and Clip Space . . . . . . . . . . . 63
5.4.3 Derivation of Projection Matrix∗ . . . . . . . . . . . . 67
7 Rasterizer 87
7.1 Clipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.2 Perspective Division . . . . . . . . . . . . . . . . . . . . . . . 88
7.3 Back-face Culling . . . . . . . . . . . . . . . . . . . . . . . . 89
7.3.1 Concept . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.3.2 Implementation . . . . . . . . . . . . . . . . . . . . . . 90
7.4 Viewport Transform . . . . . . . . . . . . . . . . . . . . . . . 92
7.5 Scan Conversion . . . . . . . . . . . . . . . . . . . . . . . . . 94
9 Lighting 127
9.1 Phong Lighting Model . . . . . . . . . . . . . . . . . . . . . . 127
9.1.1 Diffuse Reflection . . . . . . . . . . . . . . . . . . . . . 128
9.1.2 Specular Reflection . . . . . . . . . . . . . . . . . . . . 130
9.1.3 Ambient Reflection . . . . . . . . . . . . . . . . . . . . 132
9.1.4 Emissive Light . . . . . . . . . . . . . . . . . . . . . . 132
9.2 Shaders for Phong Lighting . . . . . . . . . . . . . . . . . . . 133
References 319
Index 321
Preface
OpenGL ES is the standard graphics API for mobile and embedded sys-
tems. Virtually every pixel on a smartphone’s screen is generated by OpenGL
ES. However, there exists no textbook on OpenGL ES which has a balance be-
tween theory and practicality. This book is written to answer that need and
presents the must-know in real-time graphics with OpenGL ES. This book
suits the advanced undergraduate and beginner graduate courses in computer
graphics.
Another primary group of readers that this book may benefit includes mo-
bile 3D app developers, who have experiences in OpenGL ES and shader
programming but lack theoretical background in 3D graphics. A few excel-
lent programming manuals on OpenGL ES can be found in bookstores, but
they do not provide a sufficient level of mathematical background for devel-
opers. Assuming that the readers have a minimal understanding of vectors
and matrices, this book provides an opportunity to combine their knowledge
with the background theory of computer graphics.
This book is built upon the author’s previous work 3D Graphics for Game
Programming published in 2011. Reusing roughly half of the contents from
that book, several new topics and a considerable number of OpenGL ES and
shader programs have been added. As OpenGL ES is a subset of OpenGL,
this book is also suitable for beginner OpenGL programmers.
The organization and presentation of this book have been carefully designed
so as to enable the readers to easily understand the key aspects of real-time
graphics and OpenGL ES. Over the chapters, numerous 3D illustrations are
provided to help the readers effortlessly grasp the complicated topics. An
important organizational feature of this book is that “non-core” details are
presented in separate notes (in shaded boxes) and in optional sections (marked
by asterisks). They can be safely skipped without incurring any difficulty in
understanding the subsequent topics of the book.
If the optional parts are excluded, the entire contents of this book can be
covered in a 16-week semester for graduate classes. For undergraduate classes,
however, this feat will be difficult. According to the author’s experience,
teaching Chapters 1 through 14 is a feasible goal.
The sample programs presented in this book are available on GitHub:
https://github.com/medialab-ku/openGLESbook. The site also provides links
to the full-length lecture notes as PowerPoint files and additional materials
including video clips.
xiii
xiv Preface
Acknowledgments
JungHyun Han
Computer Science Department
Korea University
Seoul, Korea
Part I
Rendering Pipeline
Chapter 1
Introduction
1
2 Introduction to Computer Graphics with OpenGL ES
Fig. 1.2: Almost all 3D models in real-time graphics are represented in polygon
meshes.
sider a baseball game. We need players, bats, balls, etc. They are usually
represented in polygons, as shown in Fig. 1.2. Such polyhedral objects are
named the polygon meshes.
The scope of modeling is not limited to constructing 3D models but includes
creating textures. The simplest form of a texture is an image that is pasted
on an object’s surface. Fig. 1.3-(a) shows an image texture created for the
baseball player model. The texture is pasted on the surface of the player at
run time to produce the result shown in Fig. 1.3-(b).
The baseball player should be able to hit a ball, run, and slide into a base,
i.e., we need to animate the player. For this purpose, we usually specify
the skeleton or rig of the player. Fig. 1.4 shows a skeleton embedded in the
polygon model. We then define how the skeletal motion deforms the player’s
polygon mesh such that, for example, the polygons of the arm are made to
move when the arm bone is lifted. This process is often referred to as rigging.
The graphics artist creates a sequence of skeletal motions. At run time, the
skeletal motions are replayed “per frame” and the polygon mesh is animated
over frames. Fig. 1.5 shows a few snapshots of an animated player.
Rendering is the process of generating a 2D image from a 3D scene. The
image makes up a frame. Fig. 1.6 shows the results of rendering the dynamic
scene of Fig. 1.5. Realistic rendering is a complicated process, in which lighting
as well as texturing is an essential component. For example, the shadow shown
in Fig. 1.6 is a result of lighting.
The final step in the production of computer graphics, post-processing, is
optional. It uses a set of special operations to give additional effects to the
rendered images. An example is motion blur shown in Fig. 1.7. When a
camera captures a scene, the resulting image represents the scene over a short
period of time. Consequently, rapidly moving objects may result in motion
Introduction 3
Fig. 1.3: Image texturing example: (a) This texture is a collection of small
images, each of which is for a part of the baseball player’s body. The texture
may look weird at first glance, but Chapter 8 will present how such a texture
is created and used. (b) The texture is pasted on the player’s polygon mesh
at run time.
Fig. 1.4: A skeleton is composed of bones and is embedded in the polygon mesh
for animation. This figure illustrates the bones as if they were solids, but the
bones do not have explicit geometric representations. They are conceptual
entities that are usually represented as matrices. This will be detailed in
Chapter 13.
Fig. 1.5: The polygon mesh can be animated by controlling the skeleton
embedded in it.
7
8 Introduction to Computer Graphics with OpenGL ES
The result is the same as in Equation (2.4) but is represented in a row vector.
(Whereas OpenGL uses the column vectors and the vector-on-the-right repre-
sentation for matrix-vector multiplication, Direct3D uses the row vectors and
the vector-on-the-left representation.)
The identity matrix is a square matrix with ones on the main diagonal (from
the upper-left element to the lower-right element) and zeros everywhere else.
It is denoted by I. For any matrix M , M I = IM = M , as shown in the
following examples:
a11 a12 a13 100 a11 a12 a13
a21 a22 a23 0 1 0 = a21 a22 a23 (2.7)
a31 a32 a33 001 a31 a32 a33
100 a11 a12 a13 a11 a12 a13
0 1 0 a21 a22 a23 = a21 a22 a23 (2.8)
001 a31 a32 a33 a31 a32 a33
If two square matrices A and B are multiplied to return an identity matrix,
i.e., if AB = I, B is called the inverse of A and is denoted by A−1 . By
the same token, A is the inverse of B. Note that (AB)−1 = B −1 A−1 as
(AB)(B −1 A−1 ) = A(BB −1 )A−1 = AIA−1 = AA−1 = I. Similarly, (AB)T =
B T AT .
Mathematics: Basics 9
Fig. 2.1: Basis examples: (a) Standard basis. (b) A valid basis that is neither
standard nor orthonormal. (c) An orthonormal basis that is not standard.
Fig. 2.3: Dot product of two vectors reveals their relative orientation.
2 You can skip the notes in shaded boxes. No trouble will be encountered in further reading.
12 Introduction to Computer Graphics with OpenGL ES
Fig. 2.5: Standard basis and right-hand rule: The thumb of the right hand
points toward e3 when the other four fingers curl from e1 to e2 , i.e., e1 × e2 =
e3 . Similarly, e2 × e3 = e1 and e3 × e1 = e2 .
In Fig. 2.5, the relative orientations among the basis vectors, e1 , e2 , and
e3 , are described using the right-hand rule:
e1 × e2 = e3
e2 × e3 = e1 (2.12)
e3 × e1 = e2
The anti-commutativity of the cross product leads to the following:
e2 × e1 = −e3
e3 × e2 = −e1 (2.13)
e1 × e3 = −e2
Equation (2.11) also asserts that
e1 × e1 = e2 × e2 = e3 × e3 = 0 (2.14)
where 0 is the zero vector, (0, 0, 0).
When a = (ax , ay , az ) and b = (bx , by , bz ), a is rewritten in terms of the
standard basis as ax e1 + ay e2 + az e3 . Similarly, b is rewritten as bx e1 + by e2 +
bz e3 . Then, a × b is derived as follows:
a × b = (ax e1 + ay e2 + az e3 ) × (bx e1 + by e2 + bz e3 )
= ax bx (e1 × e1 ) + ax by (e1 × e2 ) + ax bz (e1 × e3 )+
ay bx (e2 × e1 ) + ay by (e2 × e2 ) + ay bz (e2 × e3 )+
az bx (e3 × e1 ) + az by (e3 × e2 ) + az bz (e3 × e3 )
(2.15)
= ax bx 0 + ax by e3 − ax bz e2
−ay bx e3 + ay by 0 + ay bz e1
+az bx e2 − az by e1 + az bz 0
= (ay bz − az by )e1 + (az bx − ax bz )e2 + (ax by − ay bx )e3
The coordinates of a × b are (ay bz − az by , az bx − ax bz , ax by − ay bx ).
Other documents randomly have
different content
the brave Swiss Bouquet led the first English army that crossed the
Ohio river, making a tri-track road to the Muskingum valley and
bringing to a triumphal close Pontiac’s bloody rebellion. The old
Iroquois trail up the Mohawk valley and across the great watershed
of New York to the Niagara river was a famous Revolutionary
highway and afterward became one of the important pioneer routes.
On the Great Trail to Detroit Lachlan McIntosh erected the first fort
built by the thirteen colonies west of the Ohio, Fort Laurens on the
Muskingum near Great Crossings, where Bouquet had thrown his
army across the river in 1764. Indeed, throughout that whole half-
century of conflict in the Central West the lines of conquest were the
lines of the earlier routes of travel. Washington, Braddock, Forbes,
Bouquet, Lewis, Shirley, Sullivan, Clark, Brodhead, Crawford, Irvine,
McIntosh, Harmar, St. Clair, Wayne, and Harrison followed these old
highways and fought their battles on and beside them. These
campaigns were not made by water but by land. Had they been
made by rivers, the courses of their routes would have been
frequently described and mapped as having an important bearing on
the history of each campaign. Because they were made by land over
routes which have never received attention from historians the real
ground-work of these campaigns has been entirely omitted. Each
would be far better understood in every way if its route were clearly
defined. A thorough understanding of our history is impossible
without a knowledge of these highways of trade and war and the
strategic points they covered and connected.
But of vaster interest is the study of the surging armies of
pioneers and the occupation of the great empire conquered by these
armies for them. To the emigrant each tawny trail was a path to a
Promised Land. They came in thousands and hundreds of thousands
over the roads of New York, Pennsylvania, and Virginia. And what
roads they were! It was impossible for those pioneer wagons to
follow the Indian paths with any exactness. Even Braddock avoided
the steeper hills and yet was compelled to lower his wagons from
some hills with blocks and tackling—many being demolished at that.
And yet to avoid the high ground was inevitably to run into bogs and
swamps which were even worse than the hills. We do not have
roads a mile wide nowadays, but this was not an unheard-of thing in
the days of the pioneer roads. It was preferable to have them a mile
wide rather than a mile deep, which would certainly have been the
case in some places if one track had been used alone. And even with
numberless side tracks, skirting in every direction around the more
dangerous localities, horses were not infrequently drowned, and
great wagons heavy with freight sometimes sank completely out of
sight. The Black Swamp Road through Ohio south of Lake Erie was
one of the most important in the West. It is recorded that on one
occasion six horses were able to draw a two-wheeled vehicle but
fifteen miles in three days. A newspaper of August 31, 1837, affirms
that “the road through the Black Swamp has been much of the
season impassable. A couple of horses were lost in a mud hole last
week. The bottom had fallen out. The driver was unaware of the
fact. His horses plunged in and ere they could be extricated were
drowned.” It is comforting to think there has been some
improvement in our country highways. Such accounts as this would
have a tendency to influence the most skeptical.
The rivers were also great highways for emigration, particularly
such streams as the Ohio which flowed west. With the building of
the great canals new and more stable methods of travel were at the
disposal of prospective travelers and there was an increase in the
great tide of home-seekers. The smaller inland rivers were not likely
so largely used by these armies of pioneers as some have thought.
For instance, in a history of one of the interior counties of Ohio
(which is divided by one of the best rivers in the West) is a twenty-
five page description of the first immigrants, and of only one does it
say: “James Oglesby was a very early settler ... and is said to have
traveled up the Muskingum and Walhounding rivers in true Indian
style in a canoe.” And, though the Ohio river was always a great
highway to the West and Southwest, it was used less perhaps in the
early days of the immigration than later. Flat and keel boats cost
money, and money was a scarce article. In summer the river was
very low, and one party of pioneers, at least, spent one-third of the
entire time of journey from Connecticut to Marietta, Ohio, in coming
down the Ohio from near Pittsburg. It took half as long to come
those two hundred miles by river as to come all the way from
Connecticut to the Ohio in a cart drawn by oxen. Moreover, even as
late as the time of the starting of a regular line of steamer packets
from Pittsburg to Cincinnati (1796) the passengers were assured in
an advertisement that, in addition to being provided a place to sleep
and something to eat, they would have each a loophole from which
to shoot! The coming of steam navigation revolutionized river travel
as later it revolutionized land travel.
Ohio, Michigan,
Wisconsin, Georgia and
Tennessee, Arkansas,
Illinois, Missouri and
Florida, North
New York, Carolina,
Kentucky, Minnesota,
Indiana, Iowa,
Pennsylvania.
Now, by our last census the states which contain the largest
population today are:
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com