Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (7 votes)
2K views65 pages

Computer Graphics Programming in OpenGL with Java 2nd Edition V. Scott Gordon all chapter instant download

Java

Uploaded by

yatomauley
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (7 votes)
2K views65 pages

Computer Graphics Programming in OpenGL with Java 2nd Edition V. Scott Gordon all chapter instant download

Java

Uploaded by

yatomauley
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 65

Experience Seamless Full Ebook Downloads for Every Genre at textbookfull.

com

Computer Graphics Programming in OpenGL with Java


2nd Edition V. Scott Gordon

https://textbookfull.com/product/computer-graphics-
programming-in-opengl-with-java-2nd-edition-v-scott-gordon/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Computer Graphics Programming in OpenGL with Java Gordon

https://textbookfull.com/product/computer-graphics-programming-in-
opengl-with-java-gordon/

textboxfull.com

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/

textboxfull.com

Computer graphics through openGL Third Edition Guha

https://textbookfull.com/product/computer-graphics-through-opengl-
third-edition-guha/

textboxfull.com

Introduction to Computer Graphics with OpenGL ES First


Edition Junghyun Han

https://textbookfull.com/product/introduction-to-computer-graphics-
with-opengl-es-first-edition-junghyun-han/

textboxfull.com
OpenGL Programming Guide The Official Guide to Learning
OpenGL Version 4 5 with SPIR V 9th Edition Kessenich

https://textbookfull.com/product/opengl-programming-guide-the-
official-guide-to-learning-opengl-version-4-5-with-spir-v-9th-edition-
kessenich/
textboxfull.com

Learn OpenGL Learn modern OpenGL graphics programming in a


step by step fashion 1st Edition Joey De Vries

https://textbookfull.com/product/learn-opengl-learn-modern-opengl-
graphics-programming-in-a-step-by-step-fashion-1st-edition-joey-de-
vries/
textboxfull.com

Computer Graphics Through OpenGL: From Theory to


Experiments Sumanta Guha

https://textbookfull.com/product/computer-graphics-through-opengl-
from-theory-to-experiments-sumanta-guha/

textboxfull.com

Java Performance In Depth Advice for Tuning and


Programming Java 8 11 and Beyond 2nd Edition Scott Oaks

https://textbookfull.com/product/java-performance-in-depth-advice-for-
tuning-and-programming-java-8-11-and-beyond-2nd-edition-scott-oaks/

textboxfull.com

Computer Graphics for Java Programmers 3rd Edition Leen


Ammeraal

https://textbookfull.com/product/computer-graphics-for-java-
programmers-3rd-edition-leen-ammeraal/

textboxfull.com
Computer Graphics
Programming in OpenGL
with Java
Second Edition

CGP_Java2E_CH00-2nd-Pass.indd 1 07-09-2018 11:16:11


LICENSE, DISCLAIMER OF LIABILITY, AND LIMITED WARRANTY

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.

Mercury Learning and Information (“MLI” or “the Publisher”) and anyone


involved in the creation, writing, or production of the companion disc,
accompanying algorithms, code, or computer programs (“the software”), and any
accompanying Web site or software of the Work, cannot and do not warrant the
performance or results that might be obtained by using the contents of the Work.
The author, developers, and the Publisher have used their best efforts to insure
the accuracy and functionality of the textual material and/or programs contained
in this package; we, however, make no warranty of any kind, express or implied,
regarding the performance of these contents or programs. The Work is sold “as is”
without warranty (except for defective materials used in manufacturing the book
or due to faulty workmanship).

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.

CGP_Java2E_CH00-2nd-Pass.indd 2 07-09-2018 11:16:12


Computer Graphics
Programming in OpenGL
with Java
Second Edition

V. Scott Gordon, PhD


California State University, Sacramento

John Clevenger, PhD


California State University, Sacramento

Mercury Learning and Information


Dulles, Virginia
Boston, Massachusetts
New Delhi

CGP_Java2E_CH00-2nd-Pass.indd 3 07-09-2018 11:16:12


Copyright ©2019 by Mercury Learning and inforMation LLC. All rights reserved.

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 scan­
ning, without prior permission in writing from the publisher.

Publisher: David Pallai

Mercury Learning and inforMation


22841 Quicksilver Drive
Dulles, VA 20166
info@merclearning.com
www.merclearning.com
(800) 232-0223

V. Scott Gordon & John Clevenger.


Computer Graphics Programming in OpenGL with Java, Second Edition
ISBN: 978-1-683922-19-3

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.

Library of Congress Control Number: 2018949984

181920321 Printed on acid-free paper in the United States of America.

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.authorcloudware.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.

Books for programmers


CGP_Java2E_CH00-2nd-Pass.indd 4 07-09-2018 11:16:12
Contents
Preface xi
What’s New in This Edition xiii
Intended Audience xiv
How to Use This Book xv
Acknowledgments xvii
About the Authors xix

Chapter 1 Getting Started 1


1.1 Languages and Libraries 1
1.1.1 Java 2
1.1.2 OpenGL / GLSL 2
1.1.3 JOGL 3
1.1.4 JOML 3
1.2 Installation and Configuration 4

Chapter 2 The OpenGL Graphics Pipeline 5


2.1 The OpenGL Pipeline 6
2.1.1 Java/JOGL Application 7
2.1.2 Vertex and Fragment Shaders 10
2.1.3 Tessellation 15
2.1.4 Geometry Shader 16
2.1.5 Rasterization 17
2.1.6 Fragment Shader 19
2.1.7 Pixel Operations 20

CGP_Java2E_CH00-2nd-Pass.indd 5 07-09-2018 11:16:12


vi ■ C o n ten ts

2.2 Detecting OpenGL and GLSL Errors 21


2.3 Reading GLSL Source Code from Files 26
2.4 Building Objects from Vertices 27
2.5 Animating a Scene 28
2.6 Organizing the Java Code Files 32

Chapter 3 Mathematical Foundations 37


3.1 3D Coordinate Systems 38
3.2 Points 38
3.3 Matrices 39
3.4 Transformation Matrices 42
3.4.1 Translation 42
3.4.2 Scaling 43
3.4.3 Rotation 44
3.5 Vectors 45
3.5.1 Uses for Dot Product 47
3.5.2 Uses for Cross Product 48
3.6 Local and World Space 49
3.7 Eye Space and the Synthetic Camera 50
3.8 Projection Matrices 53
3.8.1 The Perspective Projection Matrix 53
3.8.2 The Orthographic Projection Matrix 56
3.9 Look-At Matrix 57
3.10 GLSL Functions for Building Matrix Transforms 58

Chapter 4 Managing 3D Graphics Data 63


4.1 Buffers and Vertex Attributes 64
4.2 Uniform Variables 67
4.3 Interpolation of Vertex Attributes 68
4.4 Model-View and Perspective Matrices 69
4.5 Our First 3D Program—A 3D Cube 71
4.6 Rendering Multiple Copies of an Object 80
4.6.1 Instancing 81
4.7 Rendering Multiple Different Models in a Scene 84
4.8 Matrix Stacks 87
4.9 Combating “Z-Fighting” Artifacts 94
4.10 Other Options for Primitives 95
4.11 Coding for Performance 97
4.11.1 Minimizing Dynamic Memory Allocation 97

CGP_Java2E_CH00-2nd-Pass.indd 6 07-09-2018 11:16:12


C onte nts ■ vii

4.11.2 Pre-Computing the Perspective Matrix 99


4.11.3 Back-Face Culling 100

Chapter 5 Texture Mapping 107


5.1 Loading Texture Image Files 108
5.2 Texture Coordinates 110
5.3 Creating a Texture Object 112
5.4 Constructing Texture Coordinates 112
5.5 Loading Texture Coordinates into Buffers 114
5.6 Using the Texture in a Shader: Sampler Variables and Texture Units 114
5.7 Texture Mapping: Example Program 115
5.8 Mipmapping 118
5.9 Anisotropic Filtering 123
5.10 Wrapping and Tiling 124
5.11 Perspective Distortion 126
5.12 Loading Texture Image Files Using Java AWT Classes 128

Chapter 6 3D Models 133


6.1 Procedural Models—Building a Sphere 134
6.2 OpenGL Indexing—Building a Torus 142
6.2.1 The Torus 142
6.2.2 Indexing in OpenGL 143
6.3 Loading Externally Produced Models 148

Chapter 7 Lighting 161


7.1 Lighting Models 161
7.2 Lights 163
7.3 Materials 166
7.4 ADS Lighting Computations 168
7.5 Implementing ADS Lighting 171
7.5.1 Gouraud Shading 172
7.5.2 Phong Shading 180
7.6 Combining Lighting and Textures 185

Chapter 8 Shadows 191


8.1 The Importance of Shadows 191
8.2 Projective Shadows 192
8.3 Shadow Volumes 193

CGP_Java2E_CH00-2nd-Pass.indd 7 07-09-2018 11:16:12


viii ■ Co n te n ts

8.4 Shadow Mapping 194


8.4.1 Shadow Mapping (Pass One)—“Draw” Objects from
Light Position 195
8.4.2 Shadow Mapping (Intermediate Step)—Copying the
Z-Buffer to a Texture 196
8.4.3 Shadow Mapping (Pass Two)—Rendering the Scene with
Shadows 197
8.5 A Shadow Mapping Example 201
8.6 Shadow Mapping Artifacts 208
8.7 Soft Shadows 210
8.7.1 Soft Shadows in the Real World 211
8.7.2 Generating Soft Shadows—Percentage Closer Filtering (PCF) 212
8.7.3 A Soft Shadow/PCF Program 216

Chapter 9 Sky and Backgrounds 221


9.1 Skyboxes 221
9.2 Skydomes 224
9.3 Implementing a Skybox 226
9.3.1 Building a Skybox from Scratch 226
9.3.2 Using OpenGL Cube Maps 229
9.4 Environment Mapping 234

Chapter 10 Enhancing Surface Detail 243


10.1 Bump Mapping 243
10.2 Normal Mapping 245
10.3 Height Mapping 254

Chapter 11 Parametric Surfaces 261


11.1 Quadratic Bézier Curves 261
11.2 Cubic Bézier Curves 263
11.3 Quadratic Bézier Surfaces 266
11.4 Cubic Bézier Surfaces 268

Chapter 12 Tessellation 273


12.1 Tessellation in OpenGL 273
12.2 Tessellation for Bézier Surfaces 279
12.3 Tessellation for Terrain/Height Maps 286
12.4 Controlling Level of Detail (LOD) 293

CGP_Java2E_CH00-2nd-Pass.indd 8 07-09-2018 11:16:12


C onte nts ■ ix

Chapter 13 Geometry Shaders 299


13.1 Per-Primitive Processing in OpenGL 299
13.2 Altering Primitives 301
13.3 Deleting Primitives 305
13.4 Adding Primitives 306
13.5 Changing Primitive Types 309

Chapter 14 Other Techniques 313


14.1 Fog 313
14.2 Compositing/Blending/Transparency 316
14.3 User-Defined Clipping Planes 322
14.4 3D Textures 324
14.5 Noise 330
14.6 Noise Application—Marble 335
14.7 Noise Application—Wood 339
14.8 Noise Application—Clouds 342
14.9 Noise Application—Special Effects 347

Appendix A Installation and Setup for PC (Windows) 353


Appendix B Installation and Setup for Macintosh 357
Appendix C Using the Nsight Graphics Debugger 363

Index 371

CGP_Java2E_CH00-2nd-Pass.indd 9 07-09-2018 11:16:12


CGP_Java2E_CH00-2nd-Pass.indd 10 07-09-2018 11:16:12
Preface
This book is designed primarily as a textbook for a typical computer science undergradu-
ate course in OpenGL 3D graphics programming. However, we have also endeavored to
create a text that could be used to teach oneself, without an accompanying course. With
both of those aims in mind, we have tried to explain things as clearly and simply as we
can. Every programming example is stripped down and simplified as much as possible,
but still complete so that the reader may run them all as presented.

One of the things that 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,
progressing 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 [JO16]. 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.
• 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.

CGP_Java2E_CH00-2nd-Pass.indd 11 07-09-2018 11:16:12


xii ■ Pr e fa c e

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 [LW16]. 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++. The two books are organized in lockstep,
with the same chapter and section numbers and topics, figures, exercises, and theoretical
descriptions. Wherever possible, the code is organized similarly. Of course, the use of
Java versus C++ leads to considerable programming differences. Still, we believe that we
have provided virtually identical learning paths, even allowing a student to choose either
option within a single classroom.

An important point of clarification is that there exist both different versions of OpenGL
(briefly discussed later) and different variants of OpenGL. For example, in addition to
“standard OpenGL” (sometimes called “desktop OpenGL”), there exists a variant called
“OpenGL ES” which is tailored for development of embedded systems (hence the “ES”).
“Embedded systems” include devices such as mobile phones, game consoles, automo-
biles, and industrial control systems. OpenGL ES is mostly a subset of standard OpenGL,
eliminating a large number of operations that are typically not needed for embedded sys-
tems. OpenGL ES also adds some additional functionality, typically application-specific
operations for particular target environments. The JOGL suite of Java bindings includes
interfaces for different versions of OpenGL ES, although we do not use them in this book.

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 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 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

1 JavaScript is a scripting language that can be used to embed code in webpages. It has strong
similarities to Java, but also many important differences.

CGP_Java2E_CH00-2nd-Pass.indd 12 07-09-2018 11:16:12


Pre fa c e ■ xiii

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 since 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.

We also haven’t tried to create an OpenGL or JOGL “reference.” Our coverage of


OpenGL and JOGL represents only a tiny fraction of their capabilities. Rather, our aim is
to use OpenGL and JOGL as vehicles for teaching the fundamentals of modern shader-
based 3D graphics programming, and provide the reader with a sufficiently deep under-
standing for further study. If along the way this text helps to expand awareness of JOGL
and other related technologies, that would be nice too.

What’s New in This Edition


The biggest change we have made in this second edition is switching math libraries. In
the first edition, we used a math library called “graphicslib3D” which we had built our-
selves to support an advanced graphics course at California State University Sacramento.
Since then, a new Java-based math library called “JOML” has emerged that offers many
advantages over graphicslib3D. First, JOML was developed with speed in mind, and using
it enables us to more effectively introduce performance-related topics. Second, JOML is
becoming an extremely popular math library among JOGL users, and therefore learning
it is a valuable skill. Finally, JOML is an open source project with an active developer
community, and as such is likely to enjoy better long-term support than graphicslib3D.

The switch to JOML affects virtually every program in the book, although in most
cases the changes are small. Readers who have used our previous edition will find that
their existing code may not work without updating the code (and the library) to JOML.
We hope that any minor inconvenience will be offset by improved performance and the
benefits of standardization to a more widely used library.

As we did for graphicslib3D in our previous edition, we have included the latest ver-
sion of JOML on the companion disc distributed with this book. However, readers are
encouraged to seek out and utilize the newest version of JOML as it is being continually
updated. For this reason, our installation instructions describe how to obtain the latest
version of JOML from the Internet.

There are some new sections in the book that we hope readers will find exciting. As
alluded to above, we have added a section on coding for performance. We also added a
section on generating soft shadows that we promised in the instructor notes for our previ-
ous edition. The techniques for soft shadows also help with reducing jagged-edge shadow

CGP_Java2E_CH00-2nd-Pass.indd 13 07-09-2018 11:16:12


xiv ■ P refa c e

artifacts, and so users are likely to use them frequently, even when soft shadows aren’t
necessary. We also added a new section in Chapter 13 (on geometry), showing how to
generate hair or fur by using a geometry shader to change primitive types.

Almost immediately after our first edition was released, we were asked how to run
the programs on a Macintosh. After getting all of our examples running on a Mac, we pub-
lished the steps on our website. That information has become an additional appendix in
this edition. In fact, for this edition, we have moved all installation details into appendices.

We also added an appendix on using NVIDIA’s Nsight graphics debugger. The first
time we saw this tool we were blown away and desperately wanted to include it in our
book. Nsight was developed for use with C++, but after some experimentation—and some
much appreciated help from NVIDIA—we were able to get it to work with Java/JOGL.
We are delighted to include it in this second edition.

We have made numerous corrections and—we hope—improvements. The chapter on


skyboxes is largely rewritten, for example. Throughout the book, much of the code has
been restructured, such as by moving commonly reused functions into a separate utility
module. We also went through the entire book and spruced up the quality and resolution
of the figures.

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 don’t cover because
we assume the reader already has sufficient background, including the following:
• Java and its Abstract Window Toolkit (AWT) or Swing library, especially for
GUI-building
• Java configuration details, such as manipulating the CLASSPATH
• event-driven programming
• basic matrix algebra and trigonometry
• awareness of color models, such as RGB, RGBA, etc.

CGP_Java2E_CH00-2nd-Pass.indd 14 07-09-2018 11:16:12


Pre fa c e ■ xv

The audience for this new second edition is also hoped to be expanded by the release
of its “sister” textbook, Computer Graphics Programming in OpenGL with C++. In par-
ticular, we envision the possibility of a learning environment where students are free to
utilize either Java or C++ in the same classroom, selecting one or the other book. The two
texts cover the material sufficiently in lockstep that we believe conducting a course in this
manner should be possible.

How to Use This Book


This book is designed to be read from front to back. That is, material in later chapters
frequently relies on information learned in earlier chapters. So it probably won’t work to
jump back and forth in the chapters; rather, work your way forward through the material.

This book is 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 problems 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)” 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 at the very beginning 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
access in a browser, and expect to access them continuously for looking up items such

CGP_Java2E_CH00-2nd-Pass.indd 15 07-09-2018 11:16:13


xvi ■ P refa c e

as parameter and constructor details. Use the following URLs for the Java and JOGL
javadocs:

https://docs.oracle.com/javase/8/docs/api/
https://jogamp.org/deployment/webstart/javadoc/jogl/javadoc

Many of the entries in the JOGL javadoc are simply pointers to the corresponding
entry in the OpenGL documentation:

https://www.opengl.org/sdk/docs/man/

Our examples utilize a mathematics library called JOML. This is a Java library that
also has its own set of javadocs. After installing JOML (described in the appendices), the
reader should locate the accompanying javadoc link and bookmark it. At press time, the
current link is

https://joml-ci.github.io/JOML/apidocs/

There are many other books on 3D graphics programming that we recommend read-
ing in parallel with this book (such as for solving the “research” problems), including the
following five that we often refer to:
• (Sellers et al.) OpenGL SuperBible [SW15]
• (Kessenich et al.) OpenGL Programming Guide [KS16] (the “red book”)
• (Wolff) OpenGL 4 Shading Language Cookbook [WO13]
• (Angel and Shreiner) Interactive Computer Graphics [AS14]
• (Luna) Introduction to 3D Game Programming with DirectX 12 [LU16]

Companion Files
This book is accompanied by a companion disc that contains the following items:
• All of the Java/OpenGL programs and related utility class files and GLSL shader
code presented in the book, along with batch files for compiling and running them
• The models and texture files used in the various programs and examples
• The cubemap and skydome image files used to make the skies and horizons
• Normal maps and height maps for lighting and surface detail effects
• All of the figures in the book, as image files
• The JOML mathematics library (version 1.9.11)
Readers who have purchased the electronic version of this book may obtain these files
by contacting the publisher at info@merclearning.com.

CGP_Java2E_CH00-2nd-Pass.indd 16 07-09-2018 11:16:13


Pre fa c e ■ xvii

Instructor Ancillaries
Instructors in a college or university setting are encouraged to obtain the instructor ancil­
lary package that is available for this book, which contains the following additional items:
• A complete set of PowerPoint slides covering all topics in the book
• Solutions to most of the exercises at the ends of the chapters, including code
where applicable
• Sample syllabus for a course based on the book
• Additional hints for presenting the material, chapter-by-chapter
This instructor ancillary package is available by contacting the publisher at info@
merclearning.com.

Acknowledgments
Early drafts of this book (prior to the first edition) were used in the CSc-155 (Advanced
Computer Graphics Programming) course at CSU Sacramento, and benefited from many
student corrections and comments (and in some cases, code). The authors would like to
particularly thank Mitchell Brannan, Tiffany Chiapuzio-Wong, Samson Chua, Anthony
Doan, Kian Faroughi, Cody Jackson, John Johnston, Zeeshan Khaliq, Raymond Rivera,
Oscar Solorzano, Darren Takemoto, Jon Tinney, James Womack, and Victor Zepeda for
their suggestions.

Feedback started coming in almost immediately after the first edition was published.
We were especially excited to hear from instructors who adopted the book for their
courses and shared their experiences. Dr. Mauricio Papa from the University of Tulsa
traded several useful emails with us. Sean McCrory prepared a wonderfully detailed set
of corrections to a couple of our lighting (Chapter 7) and Perlin noise (Chapter 14) imple-
mentations. We also heard from many students at various institutions, and their questions
helped us to assess strengths and weaknesses in our book.

A sort of “acid test” for our book came in the fall of 2017, when our colleague Dr. Pinar
Muyan-Ozcelik used the first edition while teaching our CSc-155 course for her first time.
This gave us an opportunity to assess whether our book achieved its goal as a “teach
yourself” resource. The course went well, and along the way Dr. Muyan-Ozcelik kept a
running log of questions and corrections for each chapter, which led to many improve-
ments in this second edition.

Kai Burjack, lead developer of the JOML math library, has been extraordinarily
generous with his time and assistance as we migrated from graphicslib3D to JOML. He
reviewed key segments of our book and gave us insight into some important aspects of
JOML. He also helped guide us in using JOML correctly.

CGP_Java2E_CH00-2nd-Pass.indd 17 07-09-2018 11:16:13


xviii ■ P re fa c e

We are extremely grateful for the ongoing assistance provided to us by Julien Gouesse,
engine support maintainer at JogAmp. Mr. Gouesse has provided technical information
on JOGL textures, cube maps, buffer handling, proper loading of shader source files, and
a variety of other topics. His help has led to significant improvements in our text.

Jay Turberville of Studio 522 Productions in Scottsdale (Arizona) built the dolphin
model shown on the cover and used throughout this book. Our students love it. Studio 522
Productions does incredibly high-quality 3D animation and video production, as well as
custom 3D modeling. We were thrilled that Mr. Turberville kindly offered to build such a
wonderful model just for these books.

We wish to thank a few other artists and researchers who were gracious enough
to allow us to utilize their models and textures. James Hastings-Trew of Planet Pixel
Emporium provided many of the planetary surface textures. Paul Bourke allowed us to
use his wonderful star field. Dr. Marc Levoy of Stanford University granted us permis-
sion to use the famous “Stanford Dragon” model. Paul Baker’s bump-mapping tutorial
formed the basis of the “torus” model we used in many examples. We also thank Mercury
Learning for allowing us to use some of the textures from Introduction to 3D Game
Programming with DirectX 12 [LU16].

Dr. Danny Kopec connected us with Mercury Learning and introduced us to its
publisher, David Pallai. Dr. Kopec’s textbook, Artificial Intelligence in the 21st Century,
inspired us to consider Mercury, and our telephone conversations with him were extremely
informative. We were deeply saddened by Dr. Kopec’s untimely passing, and regret that
he didn’t have the chance to see our book come to fruition.

Finally, we wish to thank David Pallai and Jennifer Blaney of Mercury Learning for
their continued enthusiasm for this project and for guiding us through the textbook pub-
lishing process.

Errata
If you find any errors in our book, please let us know! Despite our best efforts, this book
certainly contains mistakes. We will do our best to post corrections as soon as errors are
reported to us. Shortly after the publication of the first edition, we established a webpage
for collecting errata and posting corrections—the same webpage will continue to be used
for the second edition:

http://athena.ecs.csus.edu/~gordonvs/errata.html

The publisher, Mercury Learning, also maintains a link to our errata page. So if the URL
for our errata page should ever change, check the Mercury Learning website for the latest link.

CGP_Java2E_CH00-2nd-Pass.indd 18 07-09-2018 11:16:13


Pre fa c e ■ xix

About the Authors


Dr. V. Scott Gordon has been a professor in the California State University system
for over twenty years, and currently teaches advanced graphics and game engineering
courses at CSU Sacramento. He has authored or coauthored over thirty publications in a
variety of areas, including artificial intelligence, neural networks, evolutionary computa-
tion, software engineering, video and strategy game programming, and computer science
education. Dr. Gordon obtained his PhD at Colorado State University. He is also a jazz
drummer and a competitive table tennis player.

Dr. John Clevenger has over forty years of experience teaching a wide variety of courses,
including advanced graphics, game architecture, operating systems, VLSI chip design,
system simulation, and other topics. He is the developer of several software frameworks
and tools for teaching graphics and game architecture, including the graphicslib3D
library used in the first edition of this textbook. He is the technical director of the ACM
International Collegiate Programming Contest, and oversees the ongoing development
of PC^2, the most widely used programming contest support system in the world.
Dr. Clevenger obtained his PhD at the University of California, Davis. He is also a
performing jazz musician and spends summer vacations in his mountain cabin.

References
[AS14] 
E. Angel and D. Shreiner, Interactive Computer Graphics: A Top-Down Approach
with WebGL, 7th ed. (Pearson, 2014).

[JO16] 
JogAmp, accessed July 2016, http://jogamp.org/

[KS16] 
J. Kessenich, G. Sellers, and D. Shreiner, OpenGL Programming Guide: The
Official Guide to Learning OpenGL, Version 4.5 with SPIR-V, 9th ed. (Addison-
Wesley, 2016).

[LU16] 
F. Luna, Introduction to 3D Game Programming with DirectX 12, 2nd ed.
(Mercury Learning, 2016).

[LW16] Lightweight Java Game Library (LWJGL), accessed July 2016, https://www
.lwjgl.org/

[SW15] G. Sellers, R. Wright Jr., and N. Haemel, OpenGL SuperBible: Comprehensive
Tutorial and Reference, 7th ed. (Addison-Wesley, 2015).

[WO13] D. Wolff, OpenGL Shading Language Cookbook, 2nd ed. (Packt Publishing,
2013).

CGP_Java2E_CH00-2nd-Pass.indd 19 07-09-2018 11:16:13


CGP_Java2E_CH00-2nd-Pass.indd 20 07-09-2018 11:16:13
C hapter 1
Getting Started

1.1 Languages and Libraries����������������������������������������������������������������������������������������������1


1.2 Installation and Configuration��������������������������������������������������������������������������������������4

■ ■ ■■■
Graphics programming has a reputation for being among the most challeng-
ing computer science topics to learn. These days, graphics programming is shader
based—that is, some of the program is written in a standard language such as Java
or C++ for running on the CPU and some is written in a special-purpose shader
­language for running directly on the graphics card (GPU). Shader programming has
a steep learning curve, so that even drawing something simple requires a convoluted
set of steps to pass graphics data down a “pipeline.” Modern graphics cards are able
to process this data in parallel, and so the graphics programmer must understand the
parallel architecture of the GPU, even when drawing simple shapes.
The payoff, however, is extraordinary power. The blossoming of stunning virtual
reality in videogames and increasingly realistic effects in Hollywood movies can be
greatly attributed to advances in shader programming. If reading this book is your
entrée into 3D graphics, you are taking on a personal challenge that will reward you
not only with pretty pictures but with a level of control over your machine that you
never imagined was possible. Welcome to the exciting world of computer graphics
programming!

1.1 LANGUAGES AND LIBRARIES


Modern graphics programming is done using a graphics library. That is, the
p­ rogrammer writes code which invokes functions in a predefined library (or set
of libraries) that provide support for lower-level graphical operations. There are
many graphics libraries in use today, but the most common library for platform-
independent graphics programming is called OpenGL (Open Graphics Library). This
book describes how to use OpenGL for 3D graphics programming in Java.

CGP_Java2E_CH01-2nd-Pass.indd 1 29-08-2018 13:17:19


2 ■ C o mp u te r G ra p h ic s P ro g ramming in O pe nG L w ith J a va , Se c ond Edition

Using OpenGL with Java requires configuring several libraries. In this sec-
tion, we describe which libraries are needed, some common options for each, and
the option(s) that we will use throughout the book. Details on how to install and
configure these libraries for your specific platform can be found in the appendices.
Running the programs in this book requires the following languages and
libraries:

• Java
• OpenGL / GLSL
• JOGL
• JOML
It is likely that the reader will need to do a few preparatory steps to ensure
that each of these are installed and properly accessible on his or her system. In the
following subsections we briefly describe each of them; see the appendices for
details on how to install and/or configure them for use.

1.1.1 Java
Java was developed at Sun Microsystems in the early 1990s, and the first stable
release of a development kit (JDK) occurred in 1995. In 2010, Oracle Corporation
acquired Sun and has maintained Java since that time [OR16]. This book assumes
at least Java version 8, which was released in 2014.

1.1.2 OpenGL / GLSL


Version 1.0 of OpenGL appeared in 1992 as an “open” alternative to vendor-­
specific application programming interfaces (APIs) for computer graphics.
Its specification and development was managed and controlled by the OpenGL
Architecture Review Board (ARB), a then newly formed group of industry par-
ticipants. In 2006 the ARB transferred control of the OpenGL specification to
the Khronos Group, a nonprofit consortium which manages not only the OpenGL
specification but a wide variety of other open industry standards.
Since its beginning OpenGL has been revised and extended regularly. In 2004,
version 2.0 introduced the OpenGL Shading Language (GLSL), allowing “shader
programs” to be installed and run directly in graphics pipeline stages.

CGP_Java2E_CH01-2nd-Pass.indd 2 29-08-2018 13:17:19


C ha pte r 1 · G e tting Sta rte d ■ 3

In 2009, version 3.1 removed a large number of features that had been depre-
cated, to enforce the use of shader programming as opposed to earlier approaches
(referred to as “immediate mode”).1 Among the more recent features, version 4.0
(in 2010) added a tessellation stage to the programmable pipeline.
This textbook assumes that the user is using a machine with a graphics card
that supports at least version 4.3 of OpenGL. If you are not sure which version of
OpenGL your GPU supports, there are free applications available on the web that
can be used to find out. One such application is GLView, by a company named
“realtech VR” [GV16].

1.1.3 JOGL
JOGL is a set of OpenGL bindings (sometimes called a “wrapper”) which
provides a mechanism for invoking C-based OpenGL functions from Java code.
JOGL first appeared in 2003, published on the website Java.net. Since 2010 it has
been an independent open source project, part of a suite of Java bindings main-
tained by JogAmp [JO16], an online community of developers. JogAmp also main-
tains JOAL and JOCL, bindings for OpenAL and OpenCL, respectively. As new
versions of OpenGL and/or Java are released, new versions of JOGL are developed
to support continued compatibility. JogAmp also maintains a short online user’s
guide that includes valuable guidelines for installing and using JOGL efficiently
and effectively [JU16]. This book assumes at least version 2.3 of JOGL.

1.1.4 JOML
3D graphics programming makes heavy use of vector and matrix algebra. For
this reason, use of OpenGL is greatly facilitated by an accompanying function
library or class package to support common mathematical tasks. For example, the
popular OpenGL SuperBible [SW15] utilizes a C library called “vmath”; in this
book, we use a Java library called Java OpenGL Math Library, or JOML.
JOML provides classes and basic math functions related to graphics concepts,
such as vector, matrix, and quaternion. It also contains a variety of utility classes
for creating and using common 3D graphics structures, such as a stack for building

1 Despite this, many graphics card manufacturers (notably NVIDIA) continue to support
deprecated functionality.

CGP_Java2E_CH01-2nd-Pass.indd 3 29-08-2018 13:17:19


4 ■ C o mp u te r G ra p h ic s P ro g ramming in O pe nG L w ith J a va , Se c ond Edition

hierarchical structures, perspective and look-at matrices, and a few basic shapes
such as a rectangle and a sphere.
JOML was conceived in mid-2015 by Richard Greenlees and is an open source
project currently being developed and maintained by Kai Burjack, who took over
the project shortly after its inception. While it is relatively new, it has enjoyed wide-
spread adoption because of its high-performance characteristics. JOML is specifi-
cally designed to maximize performance in an OpenGL render loop (animation).
The previous edition of this book utilized our own in-house Java mathematics
library called graphicslib3D. We hope that users of our earlier edition appreciate the
better support and performance of JOML.

1.2 INSTALLATION AND CONFIGURATION


While developing the second edition of this book, we decided to include
p­ latform-specific details for the Macintosh (which were omitted from the first
­edition). We then wrestled with the best approach for including the platform-specific
configuration information necessary to run the example programs. Configuring a
system for using OpenGL on a Mac is somewhat more complicated than the equiv-
alent configuration for the Windows PC. Ultimately, we opted to separate installa-
tion and configuration information into individual platform-specific appendices.
We hope that this will provide each reader with a single relevant place to look for
information regarding his or her specific system, while at the same time avoiding
bogging down the rest of the text with platform-specific details which may not be
relevant to every reader. In this edition, we provide detailed configuration instruc-
tions for Microsoft Windows in Appendix A and for the Macintosh in Appendix B.

References

[GV16] GLView, realtech-vr, accessed July 2016, http://www.realtech-vr.com/glview/


[JO16] JogAmp, accessed July 2016, http://jogamp.org/
[JU16] JOGL Users Guide, accessed July 2016, https://jogamp.org/jogl/doc/userguide/
[OR16] Java Software, Oracle Corp., accessed July 2016, https://www.oracle
.com/java/index.html
[SW15] G. Sellers, R. Wright Jr., and N. Haemel, OpenGL SuperBible: Comprehensive
Tutorial and Reference, 7th ed. (Addison-Wesley, 2015).

CGP_Java2E_CH01-2nd-Pass.indd 4 29-08-2018 13:17:19


C hapter 2
The OpenGL Graphics Pipeline

2.1 The OpenGL Pipeline����������������������������������������������������������������������������������������������������6


2.2 Detecting OpenGL and GLSL Errors ������������������������������������������������������������������������21
2.3 Reading GLSL Source Code from Files ��������������������������������������������������������������������26
2.4 Building Objects from Vertices������������������������������������������������������������������������������������27
2.5 Animating a Scene��������������������������������������������������������������������������������������������������������28
2.6 Organizing the Java Code Files����������������������������������������������������������������������������������32
Supplemental Notes������������������������������������������������������������������������������������������������������33

■ ■ ■■■
OpenGL (Open Graphics Library) is a multiplatform 2D and 3D graphics API
that incorporates both hardware and software. Using OpenGL requires a graphics
card (GPU) that supports a sufficiently up-to-date version of OpenGL (as described
in Chapter 1).
On the hardware side, OpenGL provides a multistage graphics pipeline that is
partially programmable using a language called GLSL (OpenGL Shading Language).
On the software side, OpenGL’s API is written in C, and thus the calls are directly
compatible with C and C++. However, stable language bindings (or “wrappers”) are
available for more than a dozen other popular languages (Java, Perl, Python, Visual
Basic, Delphi, Haskell, Lisp, Ruby, etc.) with virtually equivalent performance. This
textbook uses the popular Java wrapper JOGL (Java OpenGL). When using JOGL,
the programmer writes a Java program that runs on the CPU (more specifically, on
the Java Virtual Machine, or JVM) and includes JOGL (and thus, OpenGL) calls. We
will refer to a Java program that contains JOGL calls as a Java/JOGL application.
One important task of a Java/JOGL application is to install the programmer’s GLSL
code onto the GPU.
An overview of a JOGL-based graphics application is shown in Figure 2.1, with
the software components highlighted in pink.

CGP_Java2E_CH02-2nd-Pass.indd 5 29-08-2018 14:36:35


6 ■ C o mp u ter G ra p h ic s P ro g ramming in O pe nG L w ith J a va , Se c ond Edition

Some of the code we will write


will be in Java, with JOGL calls, and
some will be written in GLSL. Our
Java/JOGL application will work
together with our GLSL modules and
the hardware to create our 3D graph-
ics output. Once our application is
complete, the end user will interact
with the Java application.
GLSL is an example of a
shader language. Shader languages
Figure 2.1
Overview of a JOGL-based graphics application.
are intended to run on a GPU in
the context of a graphics pipeline.
There are other shader languages,
such as HLSL, which works with Microsoft’s 3D framework DirectX. GLSL is the
specific shader language that is compatible with OpenGL, and thus we will write
shader code in GLSL, in addition to our Java/JOGL application code.
For the rest of this chapter, we will take a brief “tour” of the OpenGL pipeline.
The reader is not expected to understand every detail thoroughly, but just to get a
feel for how the stages work together.

2.1 THE OPENGL PIPELINE


Modern 3D graphics programming utilizes a pipeline, in which the process
of converting a 3D scene to a 2D image is broken down into a series of steps.
OpenGL and DirectX both utilize similar pipelines.
A simplified overview of the OpenGL graphics pipeline is shown in Figure 2.2
(not every stage is shown, just the major ones we will study). The Java/JOGL appli-
cation sends graphics data into the vertex shader, processing proceeds through the
pipeline, and pixels emerge for display on the monitor.
The stages shaded in blue (vertex, tessellation, geometry, and fragment) are
programmable in GLSL. It is one of the responsibilities of the Java/JOGL applica-
tion to load GLSL programs into these shader stages, as follows:

1. It uses Java to obtain the GLSL shader code, either from text files or
­hardcoded as strings.

CGP_Java2E_CH02-2nd-Pass.indd 6 29-08-2018 14:36:35


C h a pte r 2 · The O pe nG L G ra phic s Pipe line ■ 7

2. It then creates OpenGL shader


objects, and loads the GLSL
shader code into them.
3. Finally, it uses OpenGL com-
mands to compile and link
­objects and install them on the
GPU.
In practice, it is usually necessary
to provide GLSL code for at least the
vertex and fragment stages, whereas
the tessellation and geometry stages
are optional. Let’s walk through the Figure 2.2
Overview of the OpenGL pipeline.
entire process and see what takes place
at each step.

2.1.1 Java/JOGL Application


The bulk of our graphics application is written in Java. Depending on the ­purpose
of the program, it may interact with the end user using standard Java libraries such
as AWT or Swing. For tasks related to 3D rendering, it uses the JOGL library. Other
windowing libraries exist that interface with JOGL, such as SWT and NEWT, that
have some performance advantages; in this book, however, we use AWT and Swing
because of the likelihood the reader already has familiarity with them.
JOGL includes a class called GLCanvas that is compatible with the standard
Java JFrame, and on which we can draw 3D scenes. As already mentioned, JOGL
also gives us commands for installing GLSL programs onto the programmable
shader stages and compiling them. Finally, JOGL uses buffers for sending 3D
models and other related graphics data down the pipeline.
Before we try writing shaders, let’s write a simple Java/JOGL application that
instantiates a GLCanvas and sets its background color. Doing that won’t require any
shaders at all! The code is shown in Program 2.1. It extends JFrame and instantiates
a GLCanvas, adding it to the JFrame. It also implements GLEventListener, required
to utilize OpenGL—this necessitates implementing some methods, specifically
display(), init(), reshape(), and dispose(). The display() method is where we place code
that draws to the GLCanvas. In this example, we use the glClearColor() command to
specify the color value to be applied when clearing the background—in this case

CGP_Java2E_CH02-2nd-Pass.indd 7 29-08-2018 14:36:35


8 ■ C o mp u ter G ra p h ic s P ro g ramming in O pe nG L w ith J a va , Se c ond Edition

(1,0,0,1), corresponding to the RGB values of the color red, plus a “1” for the opac-
ity component. We then use the OpenGL call glClear(GL_COLOR_BUFFER_BIT) to
actually fill the color buffer with that color.

Program 2.1 First Java/JOGL Application


import javax.swing.*;
import static com.jogamp.opengl.GL4.*;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
public class Code extends JFrame implements GLEventListener
{ private GLCanvas myCanvas;
public Code()
{ setTitle("Chapter2 - program1");
setSize(600, 400);
setLocation(200, 200);
myCanvas = new GLCanvas();
myCanvas.addGLEventListener(this);
this.add(myCanvas);
this.setVisible(true);
}
public void display(GLAutoDrawable drawable)
{ GL4 gl = (GL4) GLContext.getCurrentGL();
gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
gl.glClear(GL_COLOR_BUFFER_BIT);
}
public static void main(String[ ] args)
{ new Code();
}
public void init(GLAutoDrawable drawable) { }
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { }
public void dispose(GLAutoDrawable drawable) { }
}

When running a Java/JOGL application (such as Program 2.1) on a Microsoft


Windows machine, it is advisable to add a command-line option to disable the use
of Direct3D acceleration, such as
java -Dsun.java2d.d3d=false Code

CGP_Java2E_CH02-2nd-Pass.indd 8 29-08-2018 14:36:35


Another Random Scribd Document
with Unrelated Content
of the regular army, and March 19 took possession of Amelia Island,
subject to the President’s approval.
Matthews supposed his measures to be warranted by his
instructions, and thought the Government bound to sustain him; but
the Government took an opposite course. April 4 Monroe wrote to
Matthews[186] disavowing the seizure of Amelia Island, and referring
to the precedent of Baton Rouge as the proper course to have
followed. “The United States did not take possession until after the
Spanish authority had been subverted by a revolutionary proceeding,
and the contingency of the country being thrown into foreign hands
had forced itself into view.” Matthews failed to see why one
“revolutionary proceeding” was not as good as another, or why the
fiction of foreign interference might not serve as well at Fernandina
as at Baton Rouge. He was excessively indignant, and believed his
disavowal to be due to the publication of John Henry’s letters, which
had made the President suddenly sensitive to the awkwardness of
doing openly acts which he imputed as a crime in the governor-
general of Canada to imagine. Senator Crawford afterward wrote to
Monroe[187] that this impression was by no means confined to
Matthews; indeed, Crawford himself seemed to share it. Yet
governments were not bound to make explanations to their
instruments; and Matthews was told only that he had mistaken the
President’s wishes, and that his instructions were meant in good
faith to require that the Spaniards should of their own accord ask to
surrender their territory to the United States.
April 24 Madison wrote to Jefferson:[188] “In East Florida
Matthews has been playing a strange comedy in the face of
common-sense as well as of his instructions. His extravagances place
us in the most distressing dilemma.” The dilemma consisted in the
President’s wish to maintain possession of Amelia Island, and the
difficulty of doing it. In explaining the matter to the French minister,
Monroe made no secret of the President’s wishes:[189]—
“Mr. Monroe, in communicating the facts to me at one of our last
conversations, told me that General Matthews had gone beyond his
orders; that he was told to observe only; and in case a third Power,
which could be only England, should present itself to occupy the
island, he was to prevent it if possible, and in case of necessity
repulse the disembarking troops. He added that nevertheless, now
that things had reached their present condition, there would be more
danger in retreating than in advancing; and so, while disavowing the
General’s too precipitate conduct, they would maintain the
occupation.”
This decision required some double dealing. April 10 Monroe
wrote[190] to the governor of Georgia, requesting him to take
Matthews’s place and to restore Amelia Island to the Spanish
authorities; but this order was for public use only, and not meant to
be carried into effect. May 27 Monroe wrote again,[191] saying:—
“In consequence of the compromitment of the United States to the
inhabitants, you have been already instructed not to withdraw the
troops unless you find that it may be done consistently with their
safety, and to report to the Government the result of your conferences
with the Spanish authorities, with your opinion of their views, holding
in the mean time the ground occupied.”
Governor Mitchell would have been a poor governor and still
poorer politician, had he not read such instructions as an order to
hold Amelia Island as long as possible. Instead of re-establishing the
Spanish authority at Fernandina, he maintained the occupation
effected by Matthews.[192] June 19, the day after declaring war
against England, the House took up the subject on the motion of
Troup of Georgia, and in secret session debated a bill authorizing the
President not to withdraw the troops, but to extend his possession
over the whole country of East and West Florida, and to establish a
government there.[193] June 25, by a vote of seventy to forty-eight,
the House passed this bill, which in due time went successfully
through all its stages in the Senate until July 3, when the vote was
taken on its passage. Only then three Northern Republicans,—
Bradley of Vermont, Howell of Rhode Island, and Leib of
Pennsylvania,—joining Giles, Samuel Smith, and the Federalists,
defeated, by a vote of sixteen to fourteen, this bill which all the
President’s friends in both Houses supported as an Administration
measure, and upon which the President promised to act with
decision; but even after its failure the President maintained
possession of Fernandina, with no other authority than the secret
Act of Congress which had been improperly made by Matthews the
ground of usurping possession.
From the pacific theories of 1801 to the military methods of 1812
was a vast stride. When Congress rose, July 6, 1812, the whole
national frontier and coast from Prairie du Chien to Eastport, from
Eastport to St. Mary’s, from St. Mary’s to New Orleans,—three
thousand miles, incapable of defence,—was open to the attacks of
powerful enemies; while the Government at Washington had taken
measures for the military occupation of the vast foreign territories
northward of the Lakes and southward to the Gulf of Mexico.
CHAPTER XII.
While the Twelfth Congress at Washington from November, 1811,
until July, 1812, struggled with the declaration which was to spread
war westward to the Mississippi River, Napoleon at Paris prepared
the numberless details of the coming campaign that was to ravage
Europe eastward as far as Moscow; and in this fury for destruction,
no part remained for argument or diplomacy. Yet Joel Barlow, full of
hope that he should succeed in solving the problem which had thus
far baffled his Government, reached Paris, Sept. 19, 1811, and
began a new experience, ended a year later at Zarnovitch in Poland
by a tragedy in keeping with the military campaign to which Barlow
was in a fashion attached.
Joel Barlow felt himself at home in Paris. In 1788, at the age of
thirty-four, he had first come abroad, and during seventeen exciting
years had been rather French than American. In 1792 the National
Convention conferred on him the privileges of French citizenship,—
an honor then shared only by Washington and Hamilton among
Americans. He felt himself to be best understood and appreciated by
Frenchmen. His return to France in 1812 was, he said, attended by a
reception much more cordial and friendly than that which he had
received in America, in 1805, on his return to his native country after
seventeen years of absence. He settled with delight into his old
society, even into his old house in the Rue Vaugirard, and relished
the pleasure of recovering, with the highest dignity of office, the
atmosphere of refinement which he always keenly enjoyed. Yet
when these associations lost their freshness, and he turned to his
diplomatic task, he found that few lots in life were harder than that
of the man who bound himself to the destinies of Napoleon.
On the success of Barlow’s mission the fate of President Madison
might depend. As long as France maintained her attitude of hostility
to the United States, war against England would be regarded by a
majority of the Northern people with distrust and dislike. On that
point Madison was justly timid. The opposition of New England and
New York must be quieted, and in order to quiet it Madison must
prove France to be honest in respecting American rights; he must
show that the decrees had been really repealed as he had so often
and still so obstinately asserted, and that the vast confiscations of
American property under the authority of those decrees would
receive indemnity. The public had commonly supposed France to be
comparatively a slight aggressor; but to the general surprise, when
Congress, before the declaration of war against England, called for a
return of captures under the belligerent edicts, Monroe’s report
showed that the seizures by France and by the countries under her
influence in pursuance of the decrees were not less numerous than
those made by England under the Orders in Council. The precise
values were never known. The confiscations ordered by Napoleon in
Spain, Naples, Holland, Denmark, Hamburg, and on the Baltic
outnumbered those made in his empire; but all these taken together
probably exceeded the actual condemnations in British prize-courts.
This result, hardly expected by the American government, added to
its embarrassment, but was only a part of its grievances against
Napoleon. Not only had France since 1807 surpassed England in her
outrages on American property, but while England encouraged
American commerce with her own possessions, Napoleon
systematically prohibited American commerce with his empire. He
forbade American vessels to import sugar or other colonial produce
except by special license; he imposed a duty of sixty cents a pound
on Georgia cotton worth twenty or twenty-five cents; he refused to
take tobacco except in small quantities as a part of the government
monopoly; and he obliged every American ship to carry for its return
cargo two thirds in silks and the other third in wines, liquors, and
such other articles of French produce as he might direct. The official
returns made to Congress showed that in 1811 the United States
exported domestic produce to the amount of $45,294,000, of which
France and Italy took only $1,164,275.
Barlow’s instructions required him to reform these evils, but they
especially insisted upon indemnity for seizures under the decrees.
Haste was required; for Congress could not be expected to adopt
extreme measures against England until France should have made
such concessions as would warrant the American government in
drawing a distinction between the two belligerents. Barlow arrived in
Paris September 19, only to learn that on the same day the Emperor
set out for Antwerp and Amsterdam. The Duc de Bassano received
him kindly, assured him of the Emperor’s order to begin upon
business at once, and listened courteously to the American
complaints and demands. Then he too departed for Holland, whence
he returned only November 9, when at Washington Congress had
been already a week in session.
Nothing showed this delay to be intentional; but Napoleon never
allowed delay when he meant to act, and in the present instance he
was not inclined to act. Although the Duc de Bassano made no reply
to Barlow, he found time at Amsterdam to write instructions to
Serurier.[194] In these he declared that all American vessels captured
since November, 1810, had been released, except those coming by
way of England, which were not yet condemned, but only
sequestered.
“The French government would like to know, before making a
decision, how England would act toward American ships bound for
France. If I return once more on the motives for this delay, it is only
for your personal instruction and without making it a subject of an
official declaration on your part. On this question you should speak as
for yourself; appear ignorant what are the true motives for still
detaining some American ships which have had communication with
England; restrict yourself to receiving the representations sent you,
and to declaring that you will render an account of them; in short,
give no explanation that would imply that the Decrees of Berlin and
Milan are not entirely revoked.”
While the Emperor was thus secretly determined to enforce his
decrees, he was equally determined to pay no indemnities. Against
sacrifices of money Napoleon always made unconquerable
resistance.
In due time Barlow had his audience of reception, and made to
the Emperor a speech, not without flattery. He ventured to mention
his commercial objects, in the hope of calling out an answer that
would suit his purpose. Napoleon’s reply proved for the hundredth
time the danger of risking such experiments:—
“As to the commerce between the two Powers, I desire to favor it.
I am great enough to be just. But on your part you must defend your
dignity against my enemies and those of the Continent. Have a flag,
and I will do for you all that you can desire.”
In reporting the interview to Monroe, Barlow added that the
ambiguity of the Emperor’s reply made it unfit for publication.[195]
Ambiguity was not the quality that a more sensitive man would have
ascribed to a rebuff so sharp; but whatever the President may have
thought, he took Barlow’s advice. The interview was never made
known to Congress.
During the month of November Napoleon busied himself in
commercial questions only in order to show liberality to England at
the expense of America. He extended his system of licenses to the
exchange of French wines for sugar in large quantities, and even to
the importation of coffee, indigo, tea, wool, dyewoods, and other
articles, all to be obtained from England by license.[196] He
discovered that his exchanges would benefit France more than
England in the proportion of three to one. “It is therefore the
perfected system that has produced this result, which had not been
expected for several years. Evidently the system thus established is
a permanent system, which can be made perpetual.”[197] The motive
for this discovery might be traced throughout all his economical
experiments. He needed money.
Never had Napoleon’s ministers a harder task to give his acts a
color of consistency. During the months of November and December
Barlow held many interviews with Bassano, and made earnest efforts
to obtain some written pledge in favor of American interests, but
without success. December 19 he wrote that he was almost
discouraged by the unexpected and unreasonable delay.[198]
Napoleon made no more seizures, and released such American
vessels as were held for violation of the decrees; but he conceded
nothing in principle, and was far from abandoning his fiscal system
against the United States. In order to meet Barlow’s complaints,
Bassano gathered together every token of evidence that the decrees
were not in force; but while he was asking the American minister
how these facts could be doubted, a French squadron, Jan. 8, 1812,
sailed from Nantes with orders to destroy all neutral ships bound to
or from an enemy’s port. For several months American commerce
was ravaged by these ships under the Emperor’s order, in pursuance
of his decrees. January 19 Napoleon issued another order of the
gravest character. His quarrel with Bernadotte the new king of
Sweden had reached a rupture, and he carried out his threat of
seizing the Swedish provinces south of the Baltic; but his orders to
Marshal Davoust were almost as hostile to the United States as to
Sweden:[199] “As soon as you shall be sure of seizing a great
quantity of colonial merchandise in Swedish Pomerania, you will take
possession of that province; and you will cause to be seized both at
Stralsund and Anklam, in short at all points in Pomerania, whatever
colonial merchandise may be found.” January 28 he wrote again:
[200] “I wait with impatience your report on the colonial merchandise
you shall have found in Pomerania.” He made no exceptions in favor
of American property, for his need of money was greater than ever.
While Bassano amused Joel Barlow with conversations that
resulted in nothing, he drew up a report to the Emperor, to be laid
before the conservative Senate, dealing wholly with the question of
neutrals. Circumstances made the appearance of this report
peculiarly mortifying to Barlow. Jonathan Russell, who had been sent
to act as American chargé at London, wrote to Barlow asking for
additional proofs to satisfy Lord Castlereagh that the decrees were
repealed. Barlow replied, March 2, by a letter to Russell, recounting
seven cases of ships which had been admitted to French ports
contrary to the decrees, while in no case had the decrees been
enforced.[201] “It is difficult to conceive,” he added, “probably
impossible to procure, and certainly insulting to require, a mass of
evidence more positive than this or more conclusive to every
unprejudiced mind.” Hardly had he written this letter when news
arrived that French frigates were burning American vessels on the
ocean for infringing the decrees. March 12 he wrote to Bassano a
letter of strong protest against these depredations, and a demand
for redress. His letter received no answer. Had this been all, gross as
the outrage was, nothing need have become public; but on the heels
of this scandal came another more flagrant. March 16 the “Moniteur”
published Bassano’s official report to the Emperor, which had the
character of an Imperial message to the conservative Senate. This
document began by defining neutral rights as claimed by France;
and while one of these claims required that the flag should cover all
goods except arms and other munitions of war, another declared
that no blockade was real except of a port “invested, besieged, in
the presumption of being taken;” and until these principles should
be restored to force by England, “the Decrees of Berlin and Milan
must be enforced toward Powers that let their flags be
denationalized; the ports of the Continent are not to be opened to
denationalized flags or to English merchandise.” Barlow could
imagine no way of reconciling this language with Bassano’s
assertions that the decrees were withdrawn, and he enclosed the
report to Monroe in a letter speculating upon the reason of this
contradiction:[202]—
“You will notice that the minister in his report says nothing
particular of the United States, and nothing more precise than
heretofore on the revocation of the decrees.... I am afraid he is
forbidden to designate the United States as out of the gripe of those
decrees, because the Emperor did not like the bill we have seen
before Congress for admitting English goods contracted for before the
Non-importation Law went into operation.”

Barlow could not but maintain that the decrees were repealed;
yet the British government could hardly be required to hold the
same opinion. Taking Bassano’s report as proof that the United
States would no longer maintain the repeal, the Prince Regent
issued, April 21, 1812, a formal declaration, that in case those
decrees should at any future time by an authentic act publicly
promulgated be expressly and unconditionally repealed, then the
Orders in Council should be wholly and absolutely revoked. This step
brought matters to a crisis. As soon as the Prince Regent’s
declaration reached Paris, May 1, 1812, Barlow wrote to the French
government a letter declaring that, between Bassano’s report and
the Prince Regent’s declaration, proof that the decrees were
repealed had become absolutely necessary for the United States,
and he followed up his notes by a conversation in which he pressed
on the French minister the danger of further trifling.[203]
Then came the climax of Imperial diplomacy. Neither Talleyrand
nor Champagny had shown repugnance to falsehood; whatever end
they wished, they used naturally and without hesitation the most
convenient means. Yet free as they were from scruples, one might
doubt whether Talleyrand or Champagny would have done what
Bassano did; for when the American minister impatiently demanded
some authentic evidence that the decrees were repealed, Bassano
complained that such a demand should be made when the American
government possessed the repealing decree itself. Barlow was struck
dumb with astonishment when the French minister then passed to
him a decree signed by Napoleon at St. Cloud, April 28, 1811,
declaring his previous decrees non-existent for American vessels
after Nov. 1, 1810.[204]
That the American minister should have lost self-possession in
the face of an act so surprising and so unexpected was natural, for
Talleyrand himself could hardly have controlled his features on
seeing this document, which for an entire year had been sought by
the whole world in vain, and which suddenly appeared as a paper so
well known as to need only an allusion. In his embarrassment
Barlow asked the vacant question whether this decree had been
published, as though his surprise could be no greater had the
document been printed in the “Moniteur” and the “National
Intelligencer,” or been sent to Congress with the President’s Annual
Message. Bassano replied that it had not been published, but had
been communicated at the time to Jonathan Russell and sent to
Serurier with orders to communicate it to the Secretary of State.
These assertions increased the American minister’s embarrassment,
for they implied a reflection on the American government which he
could not resent without in his turn implying that Napoleon had
invented the story so gravely told. Barlow said no more, but asked
for a copy of the repealing decree, which was sent to him May 10.
If evidence were necessary to show that no such decree was
issued April 28, 1811, Napoleon’s correspondence proves that the
Emperor did not consider the subject until April 29, and his note to
the Council dated that day is proof that no such decree had then
been adopted.[205] Yet such a decree might naturally have been
afterward ante-dated without objection. Had the Emperor signed it
within the year 1811 he might have set what date upon it he liked,
and need have made no mystery of the delay. The interest of
Bassano’s conduct lay not so much in his producing an ante-dated
paper as in his averring that the paper was not ante-dated, but had
been communicated to the American government at the time. The
flagrancy of the falsehood relieved it from the usual reproach of an
attempt to deceive; but if it did not embarrass Bassano in the telling,
it embarrassed President Madison beyond calculation in admitting.
Still more characteristic than the calmness with which Bassano
made these announcements to the American minister at Paris, was
the circumstantial gravity with which he repeated them to his own
minister at Washington. Writing the same day, May 10, 1812, he
enclosed a copy of the decree, explaining his reasons for doing so:
[206]—

“I have learned from Mr. Barlow that he is not acquainted with the
Decree of April 28, 1811, ... and I have addressed a copy to him. You
yourself, sir, have never acknowledged its reception; you have never
mentioned it in any of your despatches; you have never dwelt upon it
in any of your interviews with the American Secretary of State. This
silence makes me fear that the communication made of it to you
under date of May 2, 1811, did not reach you, and I think it proper to
enclose herewith a new copy.”
He explained at some length why he had ignored this decree in
his report to the conservative Senate:
“It had become useless to recall in this report a measure in respect
to which no one could longer raise a doubt; it would have been even
improper to specify the Americans by name; it would have entailed
other citations; it would have required too much prominence to be
given to the true motives of the Senatus Consultum which was to be
proposed. The Emperor had reason to complain of the numerous
infractions made by Russia in the Continental system, in spite of her
engagement to co-operate with and maintain it. Therefore against
Russia were directed the provisions of that report; but although
various circumstances rendered war inevitable, it was still necessary
to avoid naming her while preparing forces against her.”
Bold and often rash a diplomatist as Napoleon was, he still felt
that at the moment of going to war with Russia he could not entirely
disregard the wishes of the United States. In appearance he gave
way, and sacrificed the system so long and so tenaciously defended;
but in yielding, he chose means that involved the United States
government in common responsibility for his previous acts.
Even had the Emperor’s deception stopped there, it would have
offered the most interesting example in American experience of one
peculiarity of his genius; but this was not all. He seemed to grudge
the success which Barlow had wrung from him. One is tempted to
think that this victory cost Barlow his life. The decree he had gained
was flung at him like a missile. Bassano’s letter was dated May 10;
the Emperor already, the day before, had left Paris to take command
of his Grand Army on the Russian frontier, and as yet the negotiation
had not advanced a step. Meanwhile Barlow took a course of his
own. Monroe and Madison cared little for a commercial treaty, but
insisted upon indemnities. Barlow, finding that indemnity was for the
present out of the question, showed great earnestness to make a
commercial treaty, and admitted suggestions altogether displeasing
to his Government. Thus June arrived, producing no change in the
attitude of France other than the new decree, which was as grave an
offence to the President’s dignity as though it had been couched in
terms of the lie direct.
Deceived and deserted, Madison was driven without an ally into a
war that required the strongest alliances. Mortified at the figure he
had been made to present, he wrote to Barlow that the shameful
conduct of the French government would be an everlasting reproach
to it, and that if peace were made with England, “the full tide of
indignation with which the public mind here is boiling” would be
directed against France. His anger was the more bitter because of
his personal outrage. The repealing Decree of April, 1811, spared no
kind of humiliation, for it proved, even to himself, his error in
asserting that Napoleon imposed no condition precedent on the
original promise to withdraw his decrees.[207] On that point the
Federalists were shown to be right, and Madison could offer no
defence against their charge that he had made himself a tool of
Napoleon.
When Bassano left Paris to follow Napoleon into Russia he
intrusted the negotiation with Barlow to the Duc Dalberg, by birth a
German, who was in the Imperial service. While Dalberg listened to
Barlow and wrote long reports to Bassano, Napoleon, entering
Russia June 23, five days after Congress declared war against Great
Britain, advanced to Wilna in Poland, where he remained until July
17, and then with five hundred thousand men plunged into the heart
of Russia, leaving Bassano at Wilna with general charge of matters
of state. These events made Barlow conscious that his negotiation
was hopeless. His communications with Dalberg must be sent from
Paris to Wilna, and thence to Napoleon on the road to Moscow, with
the certainty of receiving no attention during the active campaign;
while even if Napoleon had been able to give them ample attention,
he would soon have taken offence at the increasing ill-temper of
their tone, and would have been more likely to show anger than to
grant favors. Under new instructions from Monroe, which were
almost a reprimand, Barlow said less and less about a commercial
treaty, and pressed harder for indemnities. Under instructions from
Bassano, dated August 10,[208] Dalberg was obliged to avoid the
discussion of indemnities and to talk only about commerce. Barlow
insisted upon explanations in regard to seventeen American vessels
recently burned at sea under the Decrees of Berlin and Milan; but no
explanation could be obtained from Bassano. When the news arrived
that Congress had declared war against England, Bassano, August
10, renewed his instructions to Dalberg without essential change:
[209]—

“As for the commercial advantages that his Majesty may be


disposed to grant the Americans, particularly since the last measures
their Government has taken, communicate to the Minister of
Commerce the different demands of Mr. Barlow; consult with him to
what points and in what proportion these advantages might be
granted, and communicate the result of these interviews to me before
concluding anything in that respect with Mr. Barlow. You are to
encourage his hopes and his confidence in the benevolent views of his
Majesty toward the United States; explain, on the score of his
Majesty’s distance and the importance of his actual occupations, the
kind of languor of the negotiation which has been begun, and the
failure to decide some of the questions proposed by that minister; and
you can point him to the American declaration of war against England
as a motive the more for removing from their proposed arrangements
with France whatever would tend to complicate them and too long
delay their adoption.”

These instructions showed no change in the Imperial policy even


in consequence of the war declared by the United States against
England. The Decrees of Berlin and Milan were no more repealed by
the Decree of 1811, so unexpectedly produced by Bassano, than
they had been by Champagny’s famous letter of August 5, 1810; no
order was ever given to any official of the empire that carried the
revocation into effect. While Bassano protested to Barlow against
implications of the Emperor’s good faith, Bassano’s colleagues
equally protested to Barlow that they had no authority to exempt
American ships from the operation of the decrees. Decrès, the
Minister of Marine, gave orders to his cruisers to destroy all vessels
infringing the decrees, and not even an apology could be wrung
from him for the act. If Barlow lost patience at this conduct, the Duc
Dalberg, with German simple-mindedness, felt even more acutely
the odium of his part, and sent to Bassano remonstrances as strong
as those he received from Barlow. August 11, only one day after
Bassano wrote from Wilna the instruction just quoted, Dalberg wrote
from Paris in language such as had been of late seldom used in the
Emperor’s service:[210]—
“If we wish to inspire any confidence in the American government,
of what use is an isolated proof of revocation if a little while afterward
another proof overthrows it, and if Mr. Barlow, by his means of
information at the Department of Commerce, at that of the Marine, at
the Council of Prizes, learns that they are ignorant of it; that nothing
is changed in that legislation, and that it may at any instant be again
enforced? Under such circumstances, I pray you, Monsieur le Duc, to
consider what is the good of all the fine phrases and fair words that I
may use to Mr. Barlow when he is every moment receiving news that
our privateers in the Baltic and on the coast permit themselves the
most reckless (les plus fortes) violations against the property of
Americans. In such circumstances the art of diplomacy becomes
insufficient, a sorry game (triste métier) of which no one is long the
dupe.”

Dalberg seemed to suspect that Bassano himself knew little of


the true situation:—
“Your Excellency is perhaps not informed of the complaints made
by Americans to Mr. Barlow. If you believe that, while nothing is
settled in regard to American navigation, the Americans enjoy the
favor of navigating freely, of being well treated in our ports, and of
being exposed to no annoyance, you deceive yourself. What with the
Decrees of Berlin and Milan, whose revocation is not yet known to the
authorities; what with our forms of custom-house examinations; what
with the multiplied obstacles to all commercial movement,—this is
impossible.”

Plain as such language was, it could have no effect; for Bassano


could do nothing without Napoleon’s approval, and Napoleon was
already beyond reach. September 7 he fought the battle of
Borodino; September 15 he entered Moscow.
During all these months Barlow received by every packet
despatches more and more decided from Monroe, letters more and
more threatening from Madison. He told Dalberg in substance that
these orders left no choice except between indemnities and war.
Dalberg reported his language faithfully to Bassano; and Bassano,
struggling with the increasing difficulties of his position, invented a
new expedient for gaining time. While Napoleon remained at
Moscow, unable to advance and unwilling to retreat, Bassano wrote,
October 11, from Wilna a letter to Barlow saying that the Emperor,
regretting the delay which attended negotiation conducted at so
great a distance, had put an end to the Duc Dalberg’s authority and
requested Barlow to come in person to Wilna. The request itself was
an outrage, for its motive could not be mistaken. For an entire year
Barlow had seen the French government elude every demand he
made, and he could not fail to understand that the journey to Wilna
caused indefinite further delay, when a letter of ten lines to Dalberg
might remove every obstacle; but however futile the invitation might
be, refusal would have excused the French government’s inaction.
Throughout life Barlow exulted in activity; a famous traveller, no
fatigue or exposure checked his restlessness, and although
approaching his sixtieth year he feared no journey. He accepted
Bassano’s invitation, and October 25 wrote that he should set out
the following day for Wilna. A week earlier, Napoleon quitted
Moscow, and began his retreat to Poland.
Ten days brought Barlow to Berlin, and already Napoleon’s army
was in full flight and in danger of destruction, although the winter
had hardly begun. November 11 Barlow reached Königsberg and
plunged into the wastes of Poland. Everywhere on the road he saw
the devastation of war, and when he reached Wilna, November 18,
he found only confusion. Every one knew that Napoleon was
defeated, but no one yet knew the tragedy that had reduced his
army of half a million men to a desperate remnant numbering some
fifty thousand. While Barlow waited for Napoleon’s arrival, Napoleon
struggled through one obstacle after another until the fatal passage
of the Beresina, November 27, which dissolved his army and caused
him to abandon it. December 5, at midnight, he started for Paris,
having sent a courier in advance to warn the Duc de Bassano, who
lost no time in dismissing his guests from Wilna, where they were no
longer safe. Barlow quitted Wilna for Paris the day before Napoleon
left his army; but Napoleon soon passed him on the road. The
weather was very cold, the thermometer thirteen degrees below
zero of Fahrenheit; but Barlow travelled night and day, and after
passing through Warsaw, reached a small village called Zarnovitch
near Cracow. There he was obliged to stop. Fatigue and exposure
caused an acute inflammation of the lungs, which ended his life Dec.
24, 1812. A week earlier Napoleon had reached Paris.
Barlow’s death passed almost unnoticed in the general
catastrophe of which it was so small a part. Not until March, 1813,
was it known in America; and the news had the less effect because
circumstances were greatly changed. Madison’s earnestness in
demanding satisfaction from France expressed not so much his own
feelings as fear of his domestic opponents. The triumph of Russia
and England strengthened the domestic opposition beyond hope of
harmony, and left the President in a desperate strait. No treaty,
either with or without indemnities, could longer benefit greatly the
Administration, while Napoleon’s overthrow threatened to carry
down Madison himself in the general ruin. In his own words,[211]—
“Had the French emperor not been broken down, as he was to a
degree at variance with all probability and which no human sagacity
could anticipate, can it be doubted that Great Britain would have been
constrained by her own situation and the demands of her allies to
listen to our reasonable terms of reconciliation? The moment chosen
for war would therefore have been well chosen, if chosen with a
reference to the French expedition against Russia; and although not
so chosen, the coincidence between the war and the expedition
promised at the time to be as favorable as it was fortuitous.”
Thus the year 1812 closed American relations with France in
disappointment and mortification. Whatever hopes Madison might
still cherish, he could not repeat the happy diplomacy of 1778 or of
1803. From France he could gain nothing. He had challenged a
danger more serious than he ever imagined; for he stood alone in
the world in the face of victorious England.
CHAPTER XIII.
While Napoleon thus tried the temper of America, the
Government of England slowly and with infinite reluctance yielded to
American demands. Not for the first time experience showed that
any English minister whose policy rested on jealousy of America
must sooner or later come to ruin and disgrace.
After the departure of Pinkney and Foster in May, 1811,
diplomatic action was for a time transferred to Washington. The
young American chargé in London, John Spear Smith, could only
transmit news that came officially to his hands. The Marquess
Wellesley, still struggling to reorganize the Ministry, found the Prince
Regent less and less inclined to assist him, until at last he despaired.
American affairs resumed their old position. In June, 1811, Sir
William Scott, after some months of hesitation, rendered final
decision that the French Decrees were still in force, and that in
consequence all American vessels falling within the range of the
British Orders in Council were liable to condemnation.[212] In the
Cabinet, Wellesley urged his colleagues either to negotiate with
America or to show themselves prepared for war; but his colleagues
would do neither.[213] Convinced that the United States would not
and could not fight, Perceval and Eldon, Bathurst and Liverpool,
were indifferent to Wellesley’s discomfort. In the autumn of 1811
nothing in the attitude of the British government, except its previous
hesitation, held out a hope of change.
Yet many reasons combined to show that concessions were
inevitable. The sweeping ruin that overwhelmed British commerce
and industry in 1810 sank deep among the laboring classes in 1811.
The seasons doubled the distress. The winter had been intense, the
summer was unfavorable; wheat rose in the autumn to one hundred
and forty-five shillings, or about thirty-six dollars the quarter, and as
the winter of 1811 began, disorders broke out in the manufacturing
districts. The inland counties reached a state of actual insurrection
which no exercise of force seemed to repress. The American non-
importation aggravated the trouble, and worked unceasingly to
shake the authority of Spencer Perceval, already one of the most
unpopular ministers England had ever seen.
Popular distress alone could hardly have effected a change in
Perceval’s system; so great a result was not to be produced by
means hitherto so little regarded. The moment marked an era in
English history, for the new class of laborers, the mill-operatives and
other manufacturing workmen, took for the first time an active share
in shaping legislation. In their hostility to Perceval’s policy they were
backed by their employers; but the united efforts of employers and
workmen were not yet equal to controlling the Government, even
though they were aided by the American non-importation. They
worried Perceval, but did not break him down. At the close of 1811
he showed still no signs of yielding; but news then arrived that the
American Congress had met, and that the President’s Message, the
debates in the House, the tone of the press, and the feelings of the
American people announced war. This was a new force with which
Perceval could not deal.
No man of common-sense could charge England with want of
courage, for if ever a nation had fought its way, England had a right
to claim whatever credit such a career bestowed; but England lived
in war, she knew its exact cost, and at that moment she could not
afford it. The most bigoted Tory could see that if Napoleon
succeeded in his coming attack on Russia, as he had hitherto
succeeded in every war he had undertaken in Europe even when
circumstances were less favorable, he would need only the aid of
America to ruin beyond redemption the trade and finances of Great
Britain. Little as Englishmen believed in the military capacity of the
United States, they needed too much the markets and products of
America to challenge war.
The gradual decline of the domineering tone which Canning had
made fashionable offered a curious study in politics. In 1807 the
affair of the “Little Belt” would have caused violent anger; in 1812 it
created hardly a flurry. The Tory “Courier” talked wildly, but the
“Times” took the matter with calmness; the Ministry showed no
offence, and within a few weeks the affair was forgotten. Even after
this irritation, the British public seemed pleased rather than angered
to learn that Lord Wellesley had yielded complete apology and
redress to America for the “Chesapeake” outrage. The commercial
class for many months expected energetic retaliation by their
government against the American Non-importation Act; but in
September this idea was laid aside, and no one complained. Little by
little the press took a defensive tone. In the place of threats the
newspapers were filled with complaints. America was unfair,
unreasonable, unjust; she called on England to admit that the
French Decrees were repealed when in fact they were still in force;
she threatened war; she hectored and bullied,—but the more
dignified course required England to be temperate though firm.
Parliament met Jan. 7, 1812, and the Prince Regent’s speech was
studiously moderate in its reference to the United States. In the
Commons, January 8, Whitbread attacked ministers for their failure
to conciliate America; and Spencer Perceval replied in a manner that
could hardly have satisfied himself.
“He would allow,” he said,[214] “that a war with America would be
an evil to Great Britain, but he also knew that such a war would be a
greater evil to America. As an evil to America he was anxious to avert
it; he looked upon America as accessory to the prosperity and welfare
of Great Britain, and would be sorry to see her impoverished, crushed,
or destroyed.... Sure he was that no one could construe those truly
conciliatory dispositions of England into fear; but he was of the
opinion that England, conscious of her own dignity, could bear more
from America for peace’s sake than from any other Power on earth.”
This sentiment was the more significant because the latest news
showed that England in the immediate future would be obliged to
bear a great deal from America. The news became every day more
and more alarming, and was reinforced by steadily increasing outcry
from Birmingham, Liverpool, Nottingham, Hull, ending in a general
agitation organized by active radicals, with Brougham at their head.
So rapidly was one attack followed by another, that Perceval and his
lieutenants—George Rose and James Stephen—could no longer
carry their points by mere weight of office. The Marquess Wellesley,
refusing to serve longer under Perceval, resigned from the Cabinet
January 16, and no one felt confident that Perceval could supply his
place. During more than a month negotiations continued without
result, until, February 22, Lord Castlereagh received the appointment
of Foreign Secretary.
During this interval the movement against the Orders in Council
gained strength. In the Commons, February 13, another debate
occurred when Whitbread, in a strong American speech, moved for
the diplomatic correspondence with the United States, and was
answered with some temper by Stephen and Perceval. Stephen went
so far as to declare,—and whatever he declared he certainly
believed,—that “nothing but the utmost aversion to a quarrel with
America would have enabled this country to have borne so much. So
far from having done anything to provoke a rupture with America,
the strongest, most persevering, and almost even humiliating means
had been employed to avoid it;”[215] but he would not surrender to
her the carrying and coasting trade of Europe even to prevent a war.
Perceval spoke more evasively than usual, defending his commercial
system as one that had been begun by his Whig predecessors, and
throwing the blame for its irregularities on Napoleon’s decrees; but
although that day he was supposed to be in extreme peril of losing
his majority, he closed his speech by declaring that sooner than yield
to the repeal of the Orders in Council he would refuse share in any
Administration. Alexander Baring answered that in this case war
could hardly be avoided, and made an earnest appeal, founded on
the distress of the manufacturing towns, in favor of the direct
interference of Parliament to overrule the minister. Even William
Wilberforce, whose speeches sometimes recalled those of Polonius,
and whose hesitations generally marked the decline rather than the
rise of a Ministry in power, felt himself constrained to say that “there
was not at all times a sufficient attention in this country to the spirit
of conciliation toward other countries, and particularly toward
America. It would be well if persons in high situations in government
had been more abundant in their civilities to that nation.”
Again, five days afterward, Baring attacked Perceval by an
embarrassing motion on the subject of licenses. No such scandal as
the license system had been known in England since the monopolies
of the Tudors and Stuarts. Most of the trade between Great Britain
and the Continent was conducted by the Board of Trade on one side
and Napoleon on the other, under special licenses issued for the
carriage of specified articles. In 1807 the number of such licenses
amounted to sixteen hundred; in 1810 they reached eighteen
thousand. Owing to practical difficulties and to Napoleon’s dislike,
American vessels took few licenses. A nondescript class of so-called
neutrals under the flags of Pappenberg, Kniphausen, and Varel,
carrying double licenses and double sets of papers, served as the
agents for this curious commerce which reeked with fraud and
perjury. In the case of the “Æolus,” Aug. 8, 1810, the Court said: “It
is a matter perfectly notorious that we are carrying on the trade of
the whole world under simulated and disguised papers. The
commerce of the world unavoidably assumes a disguise; these
disguises we ourselves are under the necessity of employing, with
simulation and dissimulation.” Dr. Joseph Phillimore, perhaps the
highest authority on civil law in England, in two strong
pamphlets[216] declared that ancient rules and practices had been
rendered obsolete, so that the Admiralty Courts were no longer
occupied with the law of nations, but only with the interpretation of
licenses; and while the property of enemies was as invariably
restored as formerly it had been condemned, the condemnation of
true neutral property had become as much a matter of course as
had been its restitution a few years before. No one, even among the
sternest supporters of the Orders in Council, ventured to defend the
licenses on any other ground than that of their necessity.
Baring’s motion called up Perceval again. “The only principle on
which Government acted,” said he,[217] “was to secure to the natives
of England that trade by means of licenses, the profits of which
without them would devolve to the hands of aliens.” This admission,
or avowal, seemed to yield the whole ground of complaint which
America had taken; neither Perceval nor Rose ventured to defend
the licenses as in themselves deserving support; they stood only by
the system. Their attitude led to another and more famous debate,
which added an interesting chapter to the history of England.
In the Lords, February 28, the Marquess of Lansdowne moved for
a committee to consider the subject of the Orders in Council. Like all
that Lord Lansdowne did, his speech was temperate and able; but
his arguments were the same that have been so often repeated.
Lord Bathurst, President of the Board of Trade, replied. Bathurst’s
argument was singularly free from the faults of Perceval and Rose;
and he went to the verge of destroying his own case by avowing
that in the clamor raised about the Orders in Council no one could
say what those orders were, or what would be the consequences of
yielding to American demands. He was sure that France had suffered
from the effect of the system, but he was not so certain that
England had been also a sufferer, while he maintained that the
licenses tended to diminish the spirit of perjury, and that the
abandonment of licenses would only place an additional obstacle in
the way of trade. “Were they to put restraints on the freedom of
British commerce for the simple purpose of giving the trade of
Europe to the Americans?” This avowal, like those made by Perceval
and Stephen, seemed to concede the justice of American
complaints; but perhaps it admitted only the reply made by Lord
Holland, who said in plain words that the choice lay between the
orders and war, and that he could not suppose the orders to be their
Lordships’ preference. Lansdowne’s motion was rejected by a vote of
one hundred and thirty-five to seventy-one.
In the Commons the great debate took place March 3, when
Henry Brougham repeated Lansdowne’s motion for a committee,
after a speech showing as much self-restraint as clearness and force.
In reply, George Rose offered a general denial of the facts which
Brougham alleged. He denied that the orders injured the British
export trade; that the license system injured British shipping or
increased perjury; or that the orders caused manufacturing distress.
On all these points he arrayed statistics in his support; but toward
the close of his speech he made a remark—such as had been made
many times by every defender of the system—surrendering in effect
the point in diplomatic dispute between England and the United
States. “The honorable gentleman,” he said,[218] “had not been
correct in calling these orders a system of retaliation; they were
rather a system of self-defence, a plan to prevent the whole trade of
the world from being snatched away from her.” He was followed by
Alexander Baring, who condemned the policy which built up the
shipping of France at the cost of American shipping, and
manufactures in Massachusetts at the cost of British manufactures;
and after Baring came James Stephen, who repeated his old
arguments without essential change. Then toward midnight, after
these four long, serious, statistical speeches, such as usually
emptied the House, George Canning rose; and so keen was the
interest and anxiety of the moment that more than four hundred
members crowded in, curious to learn by what ingenuity Canning
would defend a threatened vote against those Orders in Council of
which he had been so long the champion.[219]
“For these Orders in Council,” he said, “so far as he had been
connected with their adoption, he was ready to take his full share of
responsibility. What orders were truly meant? Why, they were the
Orders in Council which, until he had heard the speech of the right
honorable gentleman (Mr. Rose), he had always looked upon as
retaliatory upon the enemy; which had been so understood in every
instance, until the Vice-President of the Board of Trade, in
contradiction to every statement which had hitherto been given to the
public on the subject,—in contradiction to every document in office
respecting these Orders,—in contradiction to every communication
which he (Mr. Canning) had made, and every despatch written in his
official character explanatory of their nature and spirit,—in
contradiction to every speech which had been made in Parliament in
defence of them,—had thought proper to represent them not as
measures retaliatory upon the enemy, but as measures of self-
defence. Self-defence, but not retaliatory!... If they were to be in no
larger a sense retaliatory than as self-defensive,—if they were not to
retaliate directly against the enemy, but to be defensive against a rival
in trade,—if they were not to be belligerent measures, but purely
defensive,—then all the arguments by which they had hitherto been
supported would fail to apply.”
Again and again Canning returned to this slip of the tongue by
which Rose had given him pretext for turning against the
Administration.
“If at any time it should appear that these orders did not retort his
aggression upon the enemy, but operated solely to the injury of the
neutrals; if even the British government should appear to have
interfered to relieve their pressure upon the enemy,—they would
stand upon far different principles than those upon which he had
supported them, and would in his opinion be very proper objects for
examination and revision.... Were he called upon to state his opinion
of what he conceived the Orders in Council should be, he could not do
it more fully than by saying that they were most perfect as they
approached toward a belligerent measure and receded from a
commercial one. Let them have for their object the pressure and
distress of the enemy, for the purpose of compelling him to listen to
terms of accommodation, and not for the narrow policy of wringing
temporary concessions from him with which they might go to his own
market.”
To the amazement of friend and foe Canning next attacked the
license system as one of which he had little knowledge, but whose
details required investigation. As for America, as he was the last man
who would lay the honor of the country at her feet, so would he be
among the first to go far in the work of honorable conciliation, and
he would not oppose the motion before the House because it might
have incidentally the effect of conciliating her. Finally, if the account
of Plumer Ward be true, “he concluded the first dull and flat speech I
ever heard him make, without the smallest support from the House,
and sat down without a cheer and almost without its being known
that he had finished.”
Plumer Ward was a passionate admirer of Spencer Perceval, and
his anger with Canning showed the soreness caused by Canning’s
sudden change of front. Perceval was obliged to rescue Rose, but in
doing so made the case worse rather than better as far as regarded
America. Having declared that the orders were strictly retaliatory, he
added, in the same breath, that “the object of Government was to
protect and to force the trade of this country.... The object of the
Orders in Council was not to destroy the trade of the Continent, but
to force the Continent to trade with us.” Had this assertion been
made by Madison or Brougham it would have been instantly
contradicted; but Perceval’s silence was still less creditable than his
avowals. No one knew so well as Perceval where to strike with effect
at Canning; for not only could he show that from the first Canning
was privy to the system of forcing commerce upon France, but he
had preserved the letter in which Canning at the outset advised him
to keep out of sight the exceptions which gave the measure the air
of a commercial rather than a political transaction. Never had a
distinguished man exposed himself with less caution than Canning,
by declaring that in his opinion the orders required revision from the
moment the British government should appear to intervene to relax
their pressure upon the enemy; for during two years of his official
life he had given steady though silent support to the Board of Trade
in its persistent efforts to supply France, by means of licenses in
thousands and smuggling without limit, with every product known to
commerce. Such conduct challenged the severest retort, but
Perceval made none. He would have been superior to the statesmen
of his time had he felt the true nature of that sleight-of-hand which
he and Canning practised, and which, like the trick of blacklegs on
the race-course, consisted in shuffling together the two words,
“Retaliation—Self-defence! Self-defence—Retaliation!” but he could
at least understand the impossibility of exposing Canning without
also exposing himself.
The debate ended in a division. One hundred and forty-four
members, including Canning and Wilberforce, went into the lobby
with Brougham. Only a majority of seventy-two remained to be
overcome; and to Brougham’s energetic nature such a majority
offered an incentive to exertion. Perceval’s friends, on the other
hand, exulted because this majority of seventy-two stood by him
against the combined forces of Wellesley, Canning, the Radicals, and
the Whigs.[220] Except for one danger, Perceval and his system were
still secure; but the fear that the Americans meant at last to fight
gave him no rest,—it dogged his steps, and galled him at every
motion. Neither Rose nor James Stephen could prove, by any
statistics under the control of the Board of Trade, that their system
would benefit British commerce if it produced an American war.
Already the north and west of England, the inland counties, the
seaports, had risen in insurrection against the orders. Stephen and
Rose exhausted themselves and the House to prove that the balance
of profit was still in England’s favor; but what would become of their
balance-sheet if they were obliged to add the cost of an American
war to the debtor side of their account?
In the effort to strengthen his Ministry Perceval persuaded Lord
Sidmouth to enter the Cabinet, but only on condition that the orders
should be left an open question. Sidmouth plainly said that he would
rather give up the orders than face an American war.[221] He also
asked that the license system should be renounced. Perceval replied
that this would be a greater sacrifice than if the licenses had never
been granted.[222] Lord Sidmouth was not a great man,—Canning
despised his abilities, and the Prince of Wales called him a
blockhead;[223] but he was, except Lord Castlereagh, the only ally to
be found, and Perceval accepted him on his own terms. The new
Cabinet at once took the American question in hand, and
Castlereagh then wrote his instructions of April 10 to Foster, making
use of Bassano’s report to justify England’s persistence in the orders;
but besides this despatch Castlereagh wrote another of the same
date, in which Sidmouth’s idea took shape. If the United States
would restore intercourse with Great Britain, the British government
would issue no more licenses and would resort to rigorous
blockades.[224] This great concession showed how rapidly Perceval
lost ground; but this was not yet all. April 21 the Prince Regent
issued his formal declaration that whenever the French government
should publish an authentic Act expressly and unconditionally
repealing the Berlin and Milan Decrees, the Orders in Council,
including that of Jan. 7, 1807, should be wholly and absolutely
revoked.
Had the United States at that moment been so fortunate as to
enjoy the services of Pinkney in London, or of any man whose
position and abilities raised him above the confusion of party politics,
he might have convinced them that war was unnecessary. The mere
threat was sufficient. Sidmouth’s entrance into the Cabinet showed
the change of current, and once Perceval began to give way, he
could not stop. Unfortunately the United States had no longer a
minister in England. In July, 1811, the President ordered Jonathan
Russell to London to act as chargé until a minister should be
appointed, which he added would be done as soon as Congress met;
[225] but he changed his mind and appointed no minister, while
Jonathan Russell, seeing that Perceval commanded a majority and
was determined to maintain his system, reported the situation as
hopeless.[226]
Brougham, without taking the precaution of giving Russell the
daily information he so much needed, devoted all his energies to
pressing the popular movement against the Orders in Council.
Petition after petition was hurried to Parliament, and almost every
petition caused a new debate. George Rose, who possessed an
unhappy bluntness, in conversation with a Birmingham committee
said that the two countries were like two men with their heads in
buckets of water, whose struggle was which of the two could hold
out longest before suffocation. The phrase was seized as a
catchword, and helped agitation. April 28 Lord Stanley, in the House,
renewed the motion for a committee on the petitions against the
orders. Perceval had been asked whether he would consent to the
committee, and had refused; but on consulting his followers he
found such symptoms of disaffection as obliged him to yield rather
than face a defeat. George Rose then announced, greatly against his
will, that as a matter of respect to the petitioners he would no longer
oppose their request; Castlereagh and Perceval, cautioning the
House that nothing need be expected from the investigation,
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like