Introduction to OpenGL - Department of Computing

Download Report

Transcript Introduction to OpenGL - Department of Computing

CS293 Graphics with Java and OpenGL
Introduction
UniS
• The OpenGL graphics system is a software
interface to graphics hardware. (The GL stands for
Graphics Library.)
• For interactive programs that produce color images
of moving three-dimensional objects.
• First introduced 1992.
UniS
2
OpenGL
With OpenGL, you can control
computer-graphics technology to
produce realistic pictures or ones
that depart from reality in
imaginative ways.
OpenGL has become the industry
standard for graphics applications
and games.
UniS
3
JOGL
OpenGL is originally written in C.
JOGL is the Java OpenGL
programming bindings to
OpenGL APIs.
JOGL, since 2003, is maintained and supported by
Sun Microsystems as one of their official Java
projects: https://jogl.dev.java.net/
UniS
4
JOGL
• JOGL is very much still being developed.
• Our goal is to understand OpenGL. Java is simply a
means to an end.
• We study OpenGL basics and how to build interesting
animated 3D models.
• Hence, we do not devote any significant effort to
worrying about the current foibles of the JOGL
implementation.
• We stick with an early version of JOGL which is tried
and tested, which is available from the course web
site.
• We do not use any additional tools to build 3D
models beyond Netbeans 5.5. Most of these are in
flux and are not stable. At the time of writing,
NetBeans 6.0 still has unpredictable behaviour when
compiling some JOGL code.
UniS
5
Texts
• Free online copy of the original OpenGL V1.1
Redbook:
http://www.glprogramming.com/red/index.html
• Note: written in C, not Java. However this is a
very informative book, which has been used
extensively for this course as the main source
of examples and core material.
• Goes in-depth into many aspects of computer
graphics that are invaluable as aid to
understanding subject.
• Many examples from Redbook have been
translated into Java and are available online:
http://ak.kiet.le.googlepages.com/theredbookinjava.html
UniS
6
Texts
• BEWARE EARLY VERSIONS of JOGL texts.
• Learning Java Bindings for OpenGL (JOGL). Not compatible
with current version of JOGL, beware!
UniS
7
Course Details
• Much of the material for this course is a direct
translation of the material available in the Open
GL Redbook, except we use JOGL not C.
• Core material split into following sections
• "Introduction to OpenGL," provides a glimpse
into the kinds of things OpenGL can do.
Includes simple OpenGL program and essential
programming details you need to know for
subsequent sections.
UniS
8
Course Details
• "State Management and Drawing Geometric
Objects," how to create a three-dimensional
geometric description of an object that is eventually
drawn on the screen.
• "Viewing," how three-dimensional models are
transformed before being drawn onto a twodimensional screen. You can control these
transformations to show a particular view of a
model.
• "Color," how to specify the colour and shading
method used to draw an object.
• "Lighting," how to control the lighting conditions
surrounding an object and how that object
responds to light (that is, how it reflects or absorbs
light). Lighting is an important topic, since objects
usually don't look three-dimensional until they're lit.
UniS
9
Introduction to OpenGL
• "What Is OpenGL?", what it does and doesn't do, and
how it works.
• "A Smidgen of OpenGL Code" presents a small
OpenGL program and briefly discusses it.
• "OpenGL Command Syntax" explains some of the
conventions and notations used by OpenGL
commands.
• "OpenGL as a State Machine" describes the use of
state variables in OpenGL and the commands for
querying, enabling, and disabling states.
•
"OpenGL Rendering Pipeline" shows a typical
sequence of operations for processing geometric and
image data.
• "Animation" explains in high level terms how to
create pictures on the screen that move.
UniS
10
Introduction to OpenGL
UniS
•
OpenGL is a software interface to graphics hardware.
•
This interface consists of about 200 distinct commands that you
use to specify the objects and operations needed to produce
interactive three-dimensional applications.
11
Introduction to OpenGL
UniS
•
OpenGL is designed as a streamlined, hardware-independent
interface to be implemented on many different hardware platforms.
•
No commands for performing windowing tasks or obtaining user
input are included in OpenGL;
•
Similarly, OpenGL doesn't provide high-level commands for
describing models of three-dimensional objects.
•
With OpenGL, you must build up your desired model from a small
set of geometric primitives - points, lines, and polygons.
12
Introduction to OpenGL, Basic Image Construction
• Lets look at how the cover plate for the Redbook is
constructed with OpenGl
UniS
13
Introduction to OpenGL, Basic Image Construction
• Cover scene constructed as a wireframe model
UniS
14
Introduction to OpenGL, Basic Image Construction
• Each line of wire corresponds to an edge of a
primitive (typically a polygon).
• For example, the surface of the table is constructed
from triangular polygons that fit together in a sort of
3d jigsaw
UniS
15
Introduction to OpenGL, Basic Image Construction
• Note that you can see portions of objects that would be
obscured if the objects were solid rather than wireframe.
• For example, you can see the entire model of the hills outside
the window even though most of this model is normally hidden
by the wall of the room.
• The globe appears to be nearly solid because it's composed of
hundreds of colored blocks, and you see the wireframe lines for
all the edges of all the blocks, even those forming the back side
of the globe.
UniS
16
Introduction to OpenGL, Basic Image Construction
• Depth-cued version of wireframe scene. Note that the
lines farther from the eye are dimmer, giving a visual
cue of depth.
UniS
17
Introduction to OpenGL, Basic Image Construction
• OpenGL uses atmospheric effects (collectively
referred to as fog) to achieve depth cueing.
UniS
18
Introduction to OpenGL, Basic Image Construction
Antialiased version of the wireframe scene.
UniS
19
Introduction to OpenGL, Basic Image Construction
• Antialiasing is a technique for reducing the jagged
edges (also known as jaggies) created when
approximating smooth edges using pixels - short for
picture elements - which are confined to a
rectangular grid.
• Such jaggies are usually the most visible with nearhorizontal or near-vertical lines.
UniS
20
Introduction to OpenGL, Basic Image Construction
• Flat-shaded, unlit version of the scene.
UniS
21
Introduction to OpenGL, Basic Image Construction
• The objects in the scene are now shown as solid.
• They appear "flat" in the sense that only one color is
used to render each polygon, so they don't appear
smoothly rounded.
• There are no effects from any light sources.
UniS
22
Introduction to OpenGL, Basic Image Construction
• Lit, smooth-shaded version of the scene.
UniS
23
Introduction to OpenGL, Basic Image Construction
• scene looks much more realistic and threedimensional
• objects are shaded to respond to the light sources in
the room as if the objects were smoothly rounded.
UniS
24
Introduction to OpenGL, Basic Image Construction
• Final Image again, built from previous images, also
has texture mapping and shadows.
• Texture mapping allows you to apply a twodimensional image onto a three-dimensional object.
• Table surface is the most vibrant example of texture
mapping.
• The wood grain on the floor and table surface are all
texture mapped, as well as the wallpaper and the toy
spinning top.
UniS
25