Computer Graphics Programming in OpenGL with Java 3rd Edition V. Scott Gordon 2024 Scribd Download
Computer Graphics Programming in OpenGL with Java 3rd Edition V. Scott Gordon 2024 Scribd Download
com
https://ebookmeta.com/product/computer-graphics-programming-
in-opengl-with-java-3rd-edition-v-scott-gordon/
OR CLICK HERE
DOWLOAD NOW
https://ebookmeta.com/product/computer-graphics-programming-in-opengl-
with-c-2nd-edition-v-scott-gordon/
ebookmeta.com
https://ebookmeta.com/product/introduction-to-computer-graphics-using-
opengl-and-java-3rd-edition-karsten-lehn/
ebookmeta.com
https://ebookmeta.com/product/developing-graphics-frameworks-with-
java-and-opengl-1st-edition-lee-stemkoski/
ebookmeta.com
https://ebookmeta.com/product/engaged-learners-and-digital-citizens-
critical-outcomes-for-teaching-and-learning-1st-edition-brad-garner/
ebookmeta.com
The Spy Whisperer 1st Edition Matthew Dunn
https://ebookmeta.com/product/the-spy-whisperer-1st-edition-matthew-
dunn/
ebookmeta.com
https://ebookmeta.com/product/case-files-family-medicine-4e-4th-
edition-donald-briscoe/
ebookmeta.com
https://ebookmeta.com/product/advanced-therapeutics-in-pain-medicine-
first-edition-sahar-swidan/
ebookmeta.com
https://ebookmeta.com/product/gingerbear-christmas-howls-romance-
howliday-special-1st-edition-reina-torres-torres-reina/
ebookmeta.com
https://ebookmeta.com/product/resonating-system-what-to-perceive-so-
you-can-receive-resonation-realm-book-1-2nd-edition-rinzen-joye/
ebookmeta.com
Beaded By Midnight A curvy girl and brother s best friend
romance 1st Edition Eve London
https://ebookmeta.com/product/beaded-by-midnight-a-curvy-girl-and-
brother-s-best-friend-romance-1st-edition-eve-london/
ebookmeta.com
Computer Graphics
Programming in OpenGL
with Java
Third Edition
By purchasing or using this book and its companion files (the “Work”), you agree
that this license grants permission to use the contents contained herein, but does
not give you the right of ownership to any of the textual content in the book or
ownership to any of the information or products contained in it. This license does
not permit uploading of the Work onto the Internet or on a network (of any kind)
without the written consent of the Publisher. Duplication or dissemination of any
text, code, simulations, images, etc. contained herein is limited to and subject to
licensing terms for the respective products, and permission must be obtained from
the Publisher or the owner of the content, etc., in order to reproduce or network any
portion of the textual material (in any media) that is contained in the Work.
The author, developers, and the publisher of any accompanying content, and anyone
involved in the composition, production, and manufacturing of this work will not
be liable for damages of any kind arising out of the use of (or the inability to use)
the algorithms, source code, computer programs, or textual material contained
in this publication. This includes, but is not limited to, loss of revenue or profit,
or other incidental, physical, or consequential damages arising out of the use of
this Work.
The sole remedy in the event of a claim of any kind is expressly limited to
replacement of the book and disc and only at the discretion of the Publisher. The
use of “implied warranty” and certain “exclusions” vary from state to state, and
might not apply to the purchaser of this product.
Companion files are available for download from the publisher by writing to
info@merclearning.com.
This publication, portions of it, or any accompanying software may not be reproduced in any way,
stored in a retrieval system of any type, or transmitted by any means, media, electronic display
or mechanical display, including, but not limited to, photocopy, recording, Internet postings, or
scanning, without prior permission in writing from the publisher.
The publisher recognizes and respects all marks used by companies, manufacturers, and
developers as a means to distinguish their products. All brand names and product names mentioned
in this book are trademarks or service marks of their respective companies. Any omission or misuse
(of any kind) of service marks or trademarks, etc. is not an attempt to infringe on the property
of others.
Our titles are available for adoption, license, or bulk purchase by institutions, corporations, etc.
For additional information, please contact the Customer Service Dept. at 800-232-0223 (toll free).
Digital versions of our titles are available at: www.academiccourseware.com and other e-vendors.
All companion files are available by writing to the publisher at info@merclearning.com.
The sole obligation of Mercury Learning and Information to the purchaser is to replace
the book and/or disc, based on defective materials or faulty workmanship, but not based on the
operation or functionality of the product.
Index 505
One of the things we hope is unique about this book is that we have strived to make it
accessible to a beginner – that is, someone new to 3D graphics programming. While there
is by no means a lack of information available on the topic—quite the contrary—many
students are initially overwhelmed. This text is our attempt to write the book we wish we
had had when we were starting out, with step-by-step explanations of the basics, progress-
ing in an organized manner up through advanced topics. We considered titling the book
“shader programming made easy”; however, we don’t think that there really is any way of
making shader programming “easy.” We hope that we have come close.
This book teaches OpenGL programming in Java, using JOGL—a Java “wrapper”
for OpenGL’s native C calls [JO21]. There are several advantages to learning graphics
programming in Java rather than in C:
• It is more convenient for students at schools that conduct most of their curriculum
in Java
• Installation and setup is easier in Java than for C or C++
• Java’s I/O, window, and event handling are arguably cleaner than in C
• Java’s excellent support for object-oriented design patterns can foster good design
• JOGL includes some very nice tools, such as for loading textures, animation
loops, etc.
It is worth mentioning that there do exist other Java bindings for OpenGL. One that
has become very popular is Lightweight Java Game Library, or LWJGL [LW21]. Like
JOGL, LWJGL also offers bindings for OpenAL and OpenCL. This textbook focuses
only on JOGL.
Another thing that makes this book unique is that it has a “sister” textbook: Computer
Graphics Programming in OpenGL with C++, Second Edition. The two books are orga-
nized in lockstep, with the same chapter and section numbers and topics, figures, exer-
cises, and theoretical descriptions. Wherever possible, the code is organized similarly.
Of course, the use of Java versus C++ leads to considerable programming differences
(although all of the shader code is identical). Still, we believe that we have provided vir-
tually identical learning paths, even allowing a student to choose either option within a
single classroom.
Yet another variant of OpenGL is called “WebGL.” Based on OpenGL ES, WebGL is
designed to support the use of OpenGL in web browsers. WebGL allows an application to
use JavaScript1 to invoke OpenGL ES operations, which makes it easy to embed OpenGL
graphics into standard HTML (web) documents. Most modern web browsers support
WebGL, including Apple Safari, Google Chrome, Microsoft Edge, Microsoft Internet
Explorer, Mozilla Firefox, and Opera. Since web programming is outside the scope of
this book, we will not cover any WebGL specifics. Note however, that because WebGL
1 JavaScript is a scripting language that can be used to embed code in web pages. It has strong
similarities to Java, but also many important differences.
is based on OpenGL ES, which in turn is based on standard OpenGL, much of what is
covered in this book can be transferred directly to learning about these OpenGL variants.
The very topic of 3D graphics lends itself to impressive, even beautiful images.
Indeed, many popular textbooks on the topic are filled with breathtaking scenes, and it is
enticing to leaf through their galleries. While we acknowledge the motivational utility of
such examples, our aim is to teach, not to impress. The images in this book are simply the
outputs of the example programs, and because this is an introductory text, the resulting
scenes are unlikely to impress an expert. However, the techniques presented do constitute
the foundational elements for producing today’s stunning 3D effects.
For years our own students have repeatedly expressed an interest in simulating water.
However, water takes so many forms that writing an introductory section on the topic is
challenging. Ultimately, we decided to present water in a way that would complement
related topics in the book such as terrain, sky, etc., and so in Chapter 15 we focus on utiliz-
ing our noise maps from Chapter 14 to generate water surfaces such as are seen in lakes
and oceans.
As a result of these additions, this 3rd edition is larger than the previous edition.
Besides the new material, there are important revisions throughout the book. For
example, we fixed bugs in our Torus class in Chapter 6, and made significant improve-
ments to our noise map functions in Chapter 14. Another small, but important, modifica-
tion was to change all of our lighting computations so that they are done in world space
rather than in camera space – this makes it easier to develop applications that require
being able to move the camera around. We also expanded our Utils.java utility class to
handle the loading of compute shaders.
There are dozens of small changes in every chapter that the reader might not even
notice: fixing typos, cleaning up code inconsistencies, updating the installation instruc-
tions, making slight wording changes, sprucing up figures, updating references, etc.
Completely eliminating typos is virtually impossible in a book that covers an ever-chang-
ing technology-rich topic, but we have attempted it.
Intended Audience
This book is targeted at students of computer science. This could mean undergraduates
pursuing a BS degree, but it could also mean anyone who studies computer science. As
such, we are assuming that the reader has at least a solid background in object-oriented
programming, at the level of someone who is, say, a computer science major at the junior
or senior level.
There are also some specific things that we use in this book, but that we don’t cover,
because we assume the reader already has sufficient background. In particular:
• Java and its Abstract Window Toolkit (AWT) or Swing library, especially for
GUI-building
• Java configuration details, such as manipulating the CLASSPATH
• basic data structures and algorithms, such as linked lists, stacks and queues, etc.
• recursion
• event-driven programming concepts
• basic matrix algebra and trigonometry
• basic analytic geometry, such as for defining points, lines, vectors, planes, and circles
This is also intended mostly as a practical, hands-on guide. While there is plenty of
theoretical material included, the reader should treat this text as a sort of “workbook,” in
which you learn basic concepts by actually programming them yourself. We have pro-
vided code for all of the examples, but to really learn the concepts you will want to “play”
with those examples—extend them to build your own 3D scenes.
At the end of each chapter are a few exercises to solve. Some are very simple, involv-
ing merely making simple modifications to the provided code. The problems that are
marked “(PROJECT),” however, are expected to take some time to solve, and require writ-
ing a significant amount of code, or combining techniques from various examples. There
are also a few marked “(RESEARCH)”—those are problems that encourage independent
study because this textbook doesn’t provide sufficient detail to solve them.
OpenGL calls, whether made in C or in Java through JOGL, often involve long lists of
parameters. While writing this book, the authors debated whether or not to, in each case,
describe all of the parameters. We decided that in the early chapters we would describe
every detail. But as the topics progress, we decided to avoid getting bogged down in every
piece of minutiae in the OpenGL calls (and there are many), for fear of the reader losing
sight of the big picture. For this reason, it is essential when working through the examples
to have ready access to reference material for Java, OpenGL, and JOGL.
For this, there are a number of excellent reference sources that we recommend using
in conjunction with this book. The javadocs for Java and JOGL are absolutely essential,
and can be accessed online or downloaded. The reader should bookmark them for easy
Colymbus arcticus, Linn. Syst. Nat. vol. i. p. 221.—Lath. Ind. Ornith. vol. ii.
p. 800.—Ch. Bonaparte, Synopsis of Birds of United States, p. 420.
Colymbus arcticus, Black-throated Diver, Richards. and Swains. Fauna
Boreali-Americana, vol. ii. p. 475.
Black-throated Diver, Nuttall, Manual, vol. ii.
Mergus Albellus, Linn. Syst. Nat. vol. i. p. 209.—Lath. Ind. Ornith. vol. ii. p.
831.—Ch. Bonaparte, Synopsis of Birds of United States, p. 398.
Smew or White Nun, Mergus Albellus, Wils. Amer. Ornith. vol. viii. p. 126,
pl. 71, fig. 4. Male.
The Smew, or White Nun, Nuttall, Manual, vol. ii. p. 467.
4/ ,
12third toe 1 11/12, its claw 4 1/2/12; fourth toe 1 10/12, its claw 5/12.
Weight 1 lb. 8 oz.
Adult Female. Plate CCCXLVII. Fig. 2.
The Female is much smaller. The feathers of the hind part of the
head and neck are also elongated so as to form a crest. The bill, iris,
and feet, are coloured as in the male. All the lower parts are white,
excepting a broad band of light grey across the middle of the neck,
and a narrow portion of the sides, which are of a deeper tint. There is
a patch of brownish-black on the lore and beneath the eye; the upper
part of the head and half of the hind neck, are light reddish-brown;
the rest of the hind neck, and all the upper parts, bluish-grey, darker
behind, and in the middle of the back approaching to black. The
wings as in the male, that is black, with a large patch of white, and
two narrow transverse bands of the same; the tail dusky grey.
Length to end of tail 15 1/4 inches, to end of claws 16 1/2, to end of
wings 14 1/2; extent of wings 25. Weight 1 lb. 4 oz.
GADWALL DUCK.
I have met with this species along the whole of our Atlantic coast,
from Eastport in Maine to Texas. It is, however, more abundant in the
interior than in most of our maritime districts, and is particularly so on
the tributaries of the Ohio, Missouri, and Mississippi. In the early part
of autumn and late in spring many are found on the margins of our
great lakes. Yet the Gadwall has been represented as not plentiful in
the United States, probably on account of its being generally
dispersed, and not congregated in particular districts.
The Creoles of Louisiana name it “Violon,” on account of the
whistling sound of its wings. It arrives in the neighbourhood of New
Orleans and the mouths of the Mississippi along with the Widgeon,
and is fond of the company of the Red-head, to which it is about
equal as an article of food. The Gadwalls are usually seen in small
flocks, and during winter resort to the larger lakes and the pools in
the interior of the great marshes, adjoining the waters of the Gulf. In
that part of the country they feed on small fish, insects, and aquatic
grasses. Fewer of them are found in Massachusetts and the State of
New York than elsewhere, and this probably on account of these
districts being more elevated and less marshy than those farther
south. My friend Dr Bachman informs me that they are rather
plentiful in South Carolina, where they are considered good eating,
and where they arrive in the beginning of October, but are more
frequently met with at that season, and in early spring, than during
winter, when a single individual may sometimes be seen in a flock of
other ducks.
While we were in the Texas, in the latter part of April and the
beginning of May, we found the Gadwall quite abundant on all the
inland ponds and streams, as well as on the brackish pools and
inlets of the islands and shores of Galveston Bay. Many of them had
paired and separated from the other ducks; and I was assured that
this species breeds there, as does the Dusky Duck, the Mallard, the
Blue-winged Teal, the Widgeon, and the Shoveller, the young of all
these species being plentiful in the end of June and beginning of
July. I was satisfied as to the truth of the repeated assurances I had
received on this subject, by observing the manners of individuals of
all these species before my departure from that country. After a
continuance of rainy weather, Gadwalls are found in great numbers
on the vast prairies of Oppelousas and Attacapas, where I have
been told they continue until very late in spring, and some remain to
breed.
This species dives well on occasion, especially on being wounded.
At the appearance of danger, it rises on wing—whether from the
ground or from the water—at a single spring, in the manner of the
Mallard, and, like it also, ascends almost perpendicularly for several
yards, after which it moves off in a direct course with great celerity. I
have never seen it dive on seeing the flash of the gun; but when
approached it always swims to the opposite part of the pond, and,
when the danger increases, flies off. On being wounded, it
sometimes by diving makes its escape among the grass, where it
squats and remains concealed. It walks with ease, and prettily, often
making incursions upon the land, when the ponds are not
surrounded by trees, for the purpose of searching for food. It nibbles
the tender shoots and blades of grasses with apparent pleasure, and
will feed on beech-nuts, acorns, and seeds of all kinds of gramineæ,
as well as on tadpoles, small fishes, and leeches. After rain it alights
in the corn-fields, like the Mallard, and picks up the scattered grains
of maize. The common notes or cry of the female have a
considerable resemblance to those of the female Mallard; but the cry
of the male is weaker as in that species.
It is by no means shy in the Western Country, where I have often
found it associating with other species, which would leave the pond
before it. Near the sea, however, it is much more wary, and this no
doubt on account of the greater number of persons who there follow
shooting as a regular and profitable employment. From the following
note of my friend Dr Bachman, you may judge how easily this fine
species might be domesticated.
“In the year 1812 I saw in Dutchess County, in the State of New
York, at the house of a miller, a fine flock of ducks, to the number of
at least thirty, which, from their peculiar appearance, struck me as
differing from any I had before seen among the different varieties of
the tame Duck. On inquiry, I was informed that three years before, a
pair of these ducks had been captured in the mill pond, whether in a
trap, or by being wounded, I cannot recollect. They were kept in the
poultry-yard, and, it was said, were easily tamed. One joint of the
wing was taken off, to prevent their flying away. In the following
spring they were suffered to go into the pond, and they returned daily
to the house to be fed. They built their nest on the edge of the pond,
and reared a large brood. The young were perfectly reconciled to
domestication, and made no attempts, even at the migratory season,
to fly away, although their wings were perfect. In the following
season they produced large broods. The family of the miller used
them occasionally as food, and considered them equal in flavour to
the common duck, and more easily raised. The old males were more
beautiful than any that I have examined since; and as yet
domestication had produced no variety in their plumage.”
The migration of this species extends to the Fur Countries, where it
is said to breed. The description of a male killed on the
Saskatchewan River, on the 22d of May 1827, is given in the Fauna
Boreali-Americana; and I have a fine male procured by Dr
Townsend on the Columbia River.
Anas strepera, Linn. Syst. Nat. vol. i. p. 200.—Lath. Ind. Ornith. vol. ii. p.
859.—Ch. Bonaparte, Synopsis of Birds of United States, p. 383.
Gadwall, Anas strepera, Wils. Amer. Ornith. vol. viii. p. 120, pl. 71, fig. 1.—
Richards. and Swains. Fauna Bor.-Amer. vol. ii. p. 440.
Gadwall or Grey, Nuttall, Manual, vol. ii. p. 383.
Titian R. Peale.”
Inclosed in Mr Peale’s letter was the following note from Dr Rowan
“to the Messrs Peales.”
“On Saturday last I wrote to you of the Rail Bird breeding near this
place. I then described one that I caught last summer, which was
unlike the Rail in the fall season, and I presumed that all in the wet
ground were the same, but this day my men mowing around the
pond started up two of the usual kind. The hen flew a few rods, and
then flew back to her young in an instant, when they caught her
together with her four young, which I herewith send you. Many more
can be caught. I have seen them in our meadow every month of the
year, but they never make a great noise except when very fat on the
wild oat’s seed. From the above you will conclude that they do not
migrate to the south, but breed here. Respectfully,
Thomas Rowan.”
Rallus jamaicensis, Brisson Sup. p. 140.—Gmel. Syst. Nat. vol. ii. p. 718.—
Lath. Ind. Ornith. vol. ii. p. 761.