0% found this document useful (0 votes)
12 views35 pages

L3

Bb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views35 pages

L3

Bb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Introduction to Open GL

Content

1. Coordinate Representations
2. Graphics Functions
3. Software Standards
4. Other Graphics Packages
5. Introduction to OpenGL
Computer Graphics Software

Graphics Software
Special-purpose packages General programming packages
Designed for nonprogrammers who want Designed for computer programmers.
to generate pictures, graphs, or charts, etc.

The interface is a set of menus that Provides a library of graphics functions that
allow users to communicate with the can be used in a programming language
programs in their own terms. such as C, C++, Java, or Fortran.
Basic functions in a typical graphics library
include those for specifying picture
components (straight lines, polygons,
spheres, and other objects), setting color
values, selecting views of a scene, and
applying rotations or other transformations.
Examples of such applications include Examples are GL (Graphics Library),
artists' painting programs and various OpenGL, VRML (Virtual-Reality Modeling
architectural, business, medical, and Language), Java 2D, and Java 3D.
engineering CAD systems.
Computer Graphics Software

• A set of graphics functions is often called a computer-graphics


application programming interface (CG API) because the
library provides a software interface between a programming
language (such as C++) and the hardware.

• So when we write an application program in C++, the graphics


routines allow us to construct and display a picture on an
output device.
Coordinate Representations
Coordinate Representations

• With few exceptions, general graphics packages


require geometric descriptions to be specified in a
standard, right-handed, Cartesian-coordinate
reference frame.

• First, we can define the shapes of individual objects,


such as trees or furniture, within a separate references
frame for each object. These reference frames are
called modeling coordinates, or sometimes local
coordinates or master coordinates.
Coordinate Representations

• Once the individual object shapes have been


specified, we can construct ("model") a scene by
placing the objects into appropriate location within a
scene reference frame called world coordinates.

• For scenes that are not too complicated, object


components can be set up directly with the overall
world-coordinate object structure, by passing the
modeling-coordinate and modeling-transformation
steps.
Coordinate Representations

• After all parts of a scene have been specified, the


overall world-coordinate description is processed
through various routines onto one or more output-
device reference frames for display. This process is
called the viewing pipeline.
Coordinate Representations

• World-coordinate positions are first converted to viewing


coordinates corresponding to the view we want of a scene,
based on the position and orientation of a hypothetical
camera. Then object locations are transformed to a two-
dimensional (2D) projection of the scene, which corresponds
to what we will see on the output device. The scene is then
stored in normalized coordinates, where each coordinate
value is in the range from -1 to 1 or in the range from 0 to 1,
depending on the system.
Coordinate Representations

• Finally, the picture is scan-converted into the refresh buffer of


a raster system for display. The coordinate systems for display
devices are generally called device coordinates, or screen
coordinates in the case of a video monitor.

• Often, both normalized coordinates and screen coordinates


are specified in a left-handed coordinate reference so that
increasing positive distances from the xy plane (the screen, or
viewing plane) can be interpreted as being farther from the
viewing position.
Coordinate Representations

• An initial modeling-coordinate position (xmc, ymc, zmc) in this


illustration is transferred to world coordinates, then to viewing
and projection coordinates, then to left-handed normalized
coordinates, and finally to a device-coordinate position (xdc,
ydc) with the sequence:

(xmc, ymc, zmc) → (xwc , ywc , zwc) → (xvc , yvc , zvc) → (xpc , ypc ,
zpc)→ (xnc , ync , znc) → (xdc, ydc).
Graphics Functions

• These are routines which can be broadly classified according


to whether they deal with graphics output, input, attributes,
transformations, viewing, subdividing pictures, or general
control.

• The basic building blocks for pictures are referred to as


graphics output primitives.

• Attributes are properties of the output primitives; that is, an


attribute describes how a particular primitive is to be
displayed.
Graphics Functions

• We can change the size, position, or orientation of an object


within a scene using geometric transformations.

• View transformations are used to select a view of the scene,


the type of projection to be used, and the location on a
video monitor where the view is to be displayed.
Graphics Functions

• Input functions are used to control and process the


data flow from these interactive devices.

• Control operations functions perform a number of


housekeeping tasks, such as clearing a screen display
area to a selected color and initializing parameters.
Software Standards

• The OpenGL library is specifically designed for efficient


processing of three-dimensional applications, but it
can also handle two-dimensional scene descriptions
as a special case of three dimensions where all the Z
coordinate values are 0
Other Graphics Packages
• A package called Open Inventor furnishes a set of object-
oriented routines for describing a scene that is to be displayed
with calls to OpenGL.
• The Virtual-Reality Modeling Language (VRML), which began
as a subset of Open Inventor, allows us to set up three-
dimensional models of virtual worlds on the Internet.
• With Java 2D,wecan create two-dimensional scenes within
Java applets, for example; or we can produce three-
dimensional web displays with Java 3D.
• Graphics libraries are often provided in other types of systems,
such as Mathematica, MatLab, and Maple.
Introduction to OpenGL

• A basic library of functions is provided in OpenGL for


specifying graphics primitives, attributes, geometric
transformations, viewing transformations, and many
other operations.

Basic OpenGL Syntax
• Functions, symbols, and types:
glBegin, glClear, glCopyPixels, glPolygonMode
GL_2D, GL_POLYGON, GL_BUFFER_BIT
GLbyte, GLshort, GLint, GLfloat, Gldouble

▪ Prefix gl
▪ Each component word in the function name has its first letter
capitalized
▪ Arguments are assigned symbolic constants specifying parameter
names, values of parameters, or a mode.
▪ Constants defined with GL_, and underscores separate words.
▪ OpenGL defines its own types which correspond to C types GLbyte:
signed char; GLshort:short; GLint: int; GLfloat: float…
Related Libraries
• Related libraries for specific windowing systems:
• GLX: X-Window System (Linux, Unix, OS X)
▪ Prefix glx

• WGL: Microsoft Windows


▪ 16 functions
▪ Prefix wgl

• Appel GL (AGL): Apple

• OpenGL Auxiliary Lib. (glaux.lib )


▪ 31 functions, for Windows NT|95, 98, 2000 mainly.
▪ Prefix aux
Related Libraries

• OpenGL Utility (GLU) (glu32.lib | glu.lib )


▪ 43 functions
▪ Setting up viewing and projection matrices
▪ Complex objects
➢ Line and polygon approximations
➢ Displaying quadrics, B-splines, surface rendering
▪ Prefix glu

• OpenGL Utility Toolkit (GLUT) (glut32.lib)


▪ A windowing application programming interface (API) for OpenGL
▪ About 30 functions, for interacting with any screen-windowing system,
plus quadric curves and surfaces.
▪ Prefix glut
Header Files

• For most applications we will also need GLU, and on many systems we will
need to include the header file for the window system.

• For the OpenGL and GLU, the source code must begin with:
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>

• We can replace the header files for OpenGL and GLUT with:
#include <windows.h>
#include <GL/glut.h>
Display Video Management Using Glut

• We perform the GLUT initialization with the statement:


glutInit(&argc, argv);

• Next, we can state that a display window is to be created on


the screen with a given caption for the title bar.
glutCreateWindow("An Example OpenGL Program");

• Then we need to specify what the display window is to


contain.
glutDisplayFunc(lineSegment);
which assigns our picture to the display window.
Display Video Management Using Glut

glutMainLoop();
• This function must be the last one in our program. It display the
initial graphics and puts the program into an infinite loop that
checks for input from devices such as a mouse or keyboard.

• We use the glutInitWindowPosition function to give an initial


location for the upper-left corner of the display window.
glutInitWindowPosition(50, 100);
Display Video Management Using Glut
Display Video Management Using Glut

• The glutInitWindowSize function is used to set the initial pixel


width and height of the display window.
glutInitWindowSize (400, 300);

• To set the buffering the the color mode, we can use with the
glutInitDisplayMode function.

glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);


A Complete OpenGL Program

• Using RGB color values, we set the background color for the
display window to be white, as in Figure 2, with the OpenGL
function:
glClearColor (1.0, 1.0, 1.0, 0.0);
The first three values are for the Red, Green and Blue, and the fourth value
is an alpha value if 0.0 means a transparent color, and if 0.1 means an
opaque color.
A Complete OpenGL Program

• To get the assigned window color displayed, we need to


invoke the following OpenGL function:
glClear(GL_COLOR_BUFFER_BIT);
The argument GL_COLOR_BUFFER_BIT is an OpenGL symbolic constant
specifying that it is the bit values in the color buffer(refresh buffer) that are
to be set to the values indicated the glClearColor function.

• For our initial programming example, we will simply set the


object color to be a dark green:
glColor3f(0.0, 0.4, 0.2);
A Complete OpenGL Program

• So, although we only want to produce a very simple two-


dimensional line, OpenGL processes our picture through the
full three-dimensional viewing operations. We can set the
projection type (mode) and other viewing parameters that we
need with the following two functions:
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 200, 0.0, 150.0);
This specifies that an orthogonal projection is to be used to map the
contents of a two-dimensional rectangular area of world coordinates to
the screen, and that the x-coordinate value within this rectangle range
from 0.0 to 200.0 with y-coordinate values ranging from 0.0 to 150.0.
A Complete OpenGL Program

• For now, we will use a world-coordinate rectangle with the


same aspect ratio as the display window, so that there is no
distortion of our picture.

• The following code defines a two-dimensional, straight-line


segment with integer, Cartesian endpoint coordinates (180,
15) and (10, 145).
glBegin(GL_LINES)
glVertex2i(180, 15);
glVertex2i(10, 145);
glEnd();
A Complete OpenGL Program
A Complete OpenGL Program
Error Handling in OpenGL
• The base OpenGL library defines a number of symbolic
constants which represent different error conditions; the ones
which occur most often are listed in Table 1.
Error Handling in OpenGL
THANK YOU

You might also like