Computer Graphics Programming in OpenGL with Java 3rd Edition V. Scott Gordon pdf download
Computer Graphics Programming in OpenGL with Java 3rd Edition V. Scott Gordon pdf download
https://ebookmeta.com/product/computer-graphics-programming-in-
opengl-with-java-3rd-edition-v-scott-gordon/
https://ebookmeta.com/product/computer-graphics-programming-in-
opengl-with-c-2nd-edition-v-scott-gordon/
https://ebookmeta.com/product/introduction-to-computer-graphics-
using-opengl-and-java-3rd-edition-karsten-lehn/
https://ebookmeta.com/product/developing-graphics-frameworks-
with-java-and-opengl-1st-edition-lee-stemkoski/
https://ebookmeta.com/product/engaged-learners-and-digital-
citizens-critical-outcomes-for-teaching-and-learning-1st-edition-
brad-garner/
The Spy Whisperer 1st Edition Matthew Dunn
https://ebookmeta.com/product/the-spy-whisperer-1st-edition-
matthew-dunn/
https://ebookmeta.com/product/case-files-family-medicine-4e-4th-
edition-donald-briscoe/
https://ebookmeta.com/product/advanced-therapeutics-in-pain-
medicine-first-edition-sahar-swidan/
https://ebookmeta.com/product/gingerbear-christmas-howls-romance-
howliday-special-1st-edition-reina-torres-torres-reina/
https://ebookmeta.com/product/resonating-system-what-to-perceive-
so-you-can-receive-resonation-realm-book-1-2nd-edition-rinzen-
joye/
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/
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
Noin viisi kuusi tuntia vesi vielä alenisi. Toisin sanoen, kello
yhdentoista aikaan olisi sopivin hetki lähteä maihin.
Aika kului. Kello oli kohta kaksitoista. Vesi alkoi vähitellen taas
kohota ja aallokko yltyi yltymistään.
Carrin koulu
Pojat suunnittelevat
Henri ja Gordon olivat heti samaa mieltä siitä, että maissa on heti
etsittävä paikka, jossa kaikki, varsinkin pienet, voisivat olla
tuulensuojassa.
Kun Gordon oli kertonut, etteivät hän ja Henri ikävä kyllä olleet
löytäneet mitään paikkaa, johon olisi voinut asettua asumaan,
päätettiin lyhyen keskustelun ja pohtimisen jälkeen toistaiseksi jäädä
kuunariin. Köli oli kyllä saanut aimo kolauksen ja kannessa ammotti
suuri halkeama juuri skanssin yläpuolella, mutta alhaalla kajuutoissa
oli vielä turvallinen ja hyvä olla, ja kapyysi — tällä nimellä kulki
laivakeittiö merimieskielellä — ei ollut kärsinyt mitään vahinkoa. Siinä
voitiin vielä keittää, ja sehän oli tärkeätä.
"Ja ne ovat ravitsevia", lisäsi siihen Henri. "Olipa hyvä, että tulit
ajatelleeksi munia".
"Eläköön!"
Mitähän Henri nyt oli saanut käsiinsä? Se mahtoi olla jotain aivan
erinomaista, koska hän noin riemuitsi löydöstään. Ja se oli todellakin
jotain, mille kyllä sieti huutaa eläköötä: hän oli löytänyt kumiveneen,
joka oli suunniteltu niin, että sen saattoi panna kokoon ja kantaa
mukanaan kuin matkalaukun.
"Kunpa vain olisi jokin oikein korkea vuori, jolta olisi laaja
näköala", sanoi Henri. Mutta sellaista ei valitettavasti ollut.
Voidakseen siis tähystellä ympäristöä Henrillä ei ollut muuta neuvoa
kuin kavuta jyrkälle rantatörmälle. Sen korkeimmalta harjalta hän
varmaankin saattoi nuorilla silmillään nähdä kauas, ja kenties hän
saattoi saada vastauksen polttavaan kysymykseen: saari vai manner.
"Mitä sinä Gordon ajattelet?" kysyi Henri. "Pitäisiköhän minun
yrittää kiivetä sinne?"
Mutta eipä silti ettei hänellä olisi ollut kyllin työtä "päämajassa".
Hän piti huolen siitä, että osterinkalastusta ja oikeata kalanpyyntiä
harjoitettiin järkevien sääntöjen mukaan, niin että jokaisella
pikkupojalla oli oma erityinen tehtävänsä. Oli varottava, ettei koti-
ikävä saisi liian suurta tilaa nuorten haaksirikkoisten mielessä, ja sen
tähden Henri tahtoi aina vain yhtä: työtä.
Henri astui ripein askelin eteenpäin pitkin rantaa. Hän oli arvioinut
olevansa töyrään huipulla kahdeksan aikaan.
"Niin, niin", tuumi Henri. "Kerran kai koittaa sekin päivä, jolloin
meille selviää, minne päin maailmaa oikeastaan olemme joutuneet.
Mutta nyt minun täytyy koettaa pyrkiä vähän korkeammalle."
Mutta oli jotenkin vaikea nähdä itään. Niin kauas kuin silmä kantoi,
oli maa laakeata. Töyräs, jolla hän seisoi, vietti tasaisesti maan
puolelle ja siellä täällä kohosi suuria, tummia metsiä. Henri tähysteli,
tähysteli, mutta tasangot ja metsät ulottuivat aina näköpiiriin asti.
Olisikohan tämä mannerta?
Mutta ennen kuin hän alkoi laskeutua töyrästä alaspäin, hän loi
vielä kerran ympäristöön tarkan silmäyksen kaukoputkella.
Se oli meri!
Neuvottelu
Niin saivat nyt kaikki kuulla sen surullisen tosiasian, että he olivat
ajautuneet saareen. Ja samalla he ymmärsivät, että pelastuksen
toivo oli nyt hälvennyt melkein olemattomiin. Salamana valtasi
kaikki, sekä suuret että pienet, sama ajatus: nyt oli tosi edessä, nyt
sai jokainen näyttää, mihin kykeni.