1.1 Opengl: Cineplex Arena
1.1 Opengl: Cineplex Arena
CHAPTER 1
INTRODUCTION
1.1 OPENGL
OpenGL is the abbreviation for Open Graphics Library. It is a software interface for graphics hardware.
This interface consists of several hundred functions that allow you, a graphics programmer, to specify the
objects and operations needed to produce high-quality color images of two-dimensional and three-dimensional
objects. Many of these functions are actually simple variations of each other, so in reality there are about 120
substantially different functions.The main purpose of OpenGL is to render two-dimensional and three-
dimensional objects into the frame buffer. These objects are defined as sequences of vertices (that define
geometric objects) or pixels (that define images).OpenGL performs several processes on this data to convert it
to pixels to form the final desired image in the frame buffer.
1.2 HISTORY
As a result, SGI released the OpenGL standard In the 1980s, developing software that could function
with a wide range of graphics hardware was a real challenge. Software developers wrote custom interfaces and
drivers for each piece of hardware. This was expensive and resulted in much duplication of effort.By the early
1990s, Silicon Graphics (SGI) was a leader in 3D graphics for workstations. Their IRIS GL API was considered
the state of the art and became the de facto industry standard, overshadowing the open standards-based PHIGS.
This was because IRIS GL was considered easier to use, and because it supported immediate mode rendering.
By contrast, PHIGS was considered difficult to use and outdated in terms of functionality.SGI's competitors
(including Sun Microsystems, Hewlett-Packard and IBM) were also able to bring to market 3D hardware,
supported by extensions made to the PHIGS standard. This in turn caused SGI market share to weaken as more
3D graphics hardware suppliers entered the market. In an effort to influence the market, SGI decided to turn the
Iris GL API into an open standard.
SGI considered that the Iris GL API itself wasn't suitable for opening due to licensing and patent issues.
Also, the Iris GL had API functions that were not relevant to 3D graphics. For example, it included a
windowing, keyboard and mouse API, in part because it was developed before the X Window System and Sun's
NEWSsystems were developed.In addition, SGI had a large number of software customers; by changing to the
Dept. of CSE, B.I.E.T DVG. Page 1
OpenGL API they planned to keep their customers locked onto SGI (and IBM) hardware for a few years while
market support for OpenGL matured. Meanwhile, SGI would continue to try to maintain their customers tied to
SGI hardware by developing the advanced and proprietary Iris Inventor and Iris Performer programming APIs.
Industry standard
An independent consortium, the OpenGL Architecture Review Board, guides the OpenGL
specification. With broad industry support, OpenGL is the only truly open, vendor-neutral,
multiplatform graphics standard.
Stable
OpenGL implementations have been available for more than seven years on a wide variety of
platforms. Additions to the specification are well controlled, and proposed updates are
announced in time for developers to adopt changes. Backward compatibility requirements
ensure that existing applications do not become obsolete.
Reliable and portable
All OpenGL applications produce consistent visual display results on any OpenGL API-compliant
hardware, regardless of operating system or windowing system.
Evolving
Because of its thorough and forward-looking design, OpenGL allows new hardware innovations to
be accessible through the API via the OpenGL extension mechanism. In this way, innovations
appear in the API in a timely fashion, letting application developers and hardware vendors
incorporate new features into their normal product release cycles.
Scalable
OpenGL API-based applications can run on systems ranging from consumer electronics to PCs,
workstations, and supercomputers. As a result, applications can scale to any class of machine
that the developer chooses to target.
Easy to use
OpenGL is well structured with an intuitive design and logical commands. Efficient OpenGL
routines typically result in applications with fewer lines of code than those that make up
programs generated using other graphics libraries or packages. In addition, OpenGL drivers
encapsulate information about the underlying hardware, freeing the application developer from
having to design for specific hardware features.
Well-documented
Numerous books have been published about OpenGL, and a great deal of sample code is readily
available, making information about OpenGL inexpensive and easy to obtain.
The following diagram illustrates how OpenGL processes data. As shown, commands enter from the left
and proceed through a processing pipeline. Some commands specify geometric objects to be drawn, and others
control how the objects are handled during various processing stages.
Display list
Rather than having all commands proceed immediately through the pipeline, you can choose to
accumulate some of them in a display list for processing later.
Evaluator
The evaluator stage of processing provides an efficient way to approximate curve and surface geometry
by evaluating polynomial commands of input values.
OpenGL processes geometric primitives - points, line segments, and polygons all of which are described
by vertices. Vertices are transformed, and primitives are clipped to the viewport in preparation for
rasterization.
Rasterization
The rasterization stage produces a series of frame-buffer addresses and associated values using a
two-dimensional description of a point, line segment, or polygon. Each so produced is fed into the last
stage, per-fragment operations.
Per-fragment operations
These are the final operations performed on the data before it is stored as pixels in the frame buffer Per-
fragment operations include conditional updates to the frame buffer based on incoming and previously
stored z values (for z buffering) and blending of incoming pixel colors with stored colors, as well as
masking and other logical operations on pixel values
Pixel operation
Input data can be in the form of pixels rather than vertices. Such data which might describe an image for
texture mapping skips the first stage of processing and instead processed as pixels in the pixel operation
stage.
Texture memory
The result of pixel operation stage is either stored as texture memory for use in rasterization stage or
rasterised and resulting fragment merged into the frame buffer just as they were generated from the
geometric data.
Most of our applications will be designed to access OpenGL directly through functions in three libraries.
They are
GL – Graphics Library
Functions in the main GL (or OpenGL in Windows) library have names that begin with the letters gl
and are stored in a library usually referred to as GL (or OpenGL in Windows).
This library uses only GL functions but contain code for creating common objects and simplifying
viewing. All functions in GLU can be created from the core GL library but application programmers
prefer not to write the code repeatedly. The GLU library is available in all OpenGL implementations;
functions in the GLU library begins with the letters glu.
To interface with the window system and to get input from external devices into our programs we need
at least one more library. For the X window System, this library is called GLX, for Windows, it is wgl,
and for the Macintosh, it is agl. Rather than using a different library for each system, we use a readily
available library called the OpenGL Utility Toolkit (GLUT) , which provides minimum functionality
that should be expected in any modern windowing system.
Fig 1.5.1: Library Organization
The above figure shows the organization of the libraries for an X Window System environment.
In most implementations, one of the include lines
#include<GL/glut.h>
or
#include<GLUT/glut.h>
is sufficient to read in glut.h, gl.h and glu.h.
Our basic model of a graphics package is a black box, a term that engineers use to denote a system
whose properties are described only by its inputs and outputs; we may know nothing about its internal
workings.
OpenGL functions can be classified into seven major groups:
Primitive function: The primitive functions define the low-level objects or atomic entities that our
system can display. Depending on the API, the primitives can include points, lines, polygons , pixels,
text, and various types of curves and surfaces.
Attribute functions
If primitives are the what of an API – the primitive objects that can be displayed- then attributes
are the how. That is, the attributes govern the way the primitive appears on the display.
Attribute functions allow us to perform operations ranging from choosing the color with which
we display a line segment, to picking a pattern with which to fill inside of a polygon.
Viewing functions
The viewing functions allow us to specify various views, although APIs differ in the degree of
flexibility they provide in choosing a view.
Transformation functions
One of the characteristics of a good API is that it provides the user with a set of transformations
functions such as rotation, translation and scaling.
Input functions
For interactive applications, an API must provide a set of input functions, to allow users to deal
with the diverse forms of input that characterize modern graphics systems. We need functions
to deal with devices such as keyboards, mice and data tablets.
Control functions
These functions enable us to communicate with the window system, to initialize our programs,
and to deal with any errors that take place during the execution of our programs.
Query functions
If we are to write device independent programs, we should expect the implementation of the API
to take care of the differences between devices, such as how many colors are supported or the
size of the display. Such information of the particular implementation should be provides
through a set of query functions.
CINEPLEX ARENA
CHAPTER
2 SYSTEM ANALYSIS SYSTEM DESIGN
Whenever there is an event, the appropriate action will be taken by the software
3.2.2 SOFTWARE
ImplementationofOpenGLbuiltinfunctions.
4.1 ImplementationofOpenGLBuiltInFunctions:
1. glutInit ():
glutInitisusedtoinitializetheGLUTlibrary.
Usage:voidglutInit(int*argcp,char**argv);
Description: glutInit will initialize the GLUT library and negotiate a session with the window
system.
2. glutInitDisplayMode():
3.glutCreateWindow():
glutCreateWindow creates a top-level window. Usage: int
glutCreateWindow(char *name);
Name - ASCII character string for use as window name.
glutDisplayFunc sets the display callback for the current window. Usage:
void glutDisplayFunc(void (*func)(void));
Func - The new display callback function.
Description: glutDisplayFunc sets the display callback for the current window. When GLUT
determines that the normal plane for the window needs to be redisplayed, the display callback for
the window is called. Before the callback, the current window is set to the window needing to be
redisplayed and the layer in use is set to the normal plane.
5.GlutMainLoop ():
glutMainLoopenterstheGLUTeventprocessingloop. Usage:
voidglutMainLoop(void);
Description:glutMainLoopenterstheGLUTeventprocessingloop.Thisroutineshould
becalledatmostonceinaGLUTprogram.Oncecalled,thisroutinewillneverreturn.It
willcallasnecessaryanycallbacksthathavebeenregistered.
6. GlMatrixMode():
7. GlutTimerFunc ();
Description:glutTimerFuncregistersthetimercallbackfunctobetriggeredinatleast
msecsmilliseconds.Thevalueparametertothetimercallbackwillbethevalueofthe
valueparametertoglutTimerFunc.Multipletimercallbacksatsameordifferingtimes
mayberegisteredsimultaneously.Thenumberofmillisecondsisalowerboundonthe
timebeforethecallbackisgenerated.GLUTattemptstodeliverthetimercallbackas
soonaspossibleaftertheexpirationofthecallback'stimeinterval.
4.1 ImplementationofUserDefinedFunctions:
1. Voidinit(void):
Heretheinitializationfunctioninit()isusedtosettheOpenGLstatevariablesdealing
withviewingandattributes-parametersthatispreferedtosetonce,independentlyofthe
displayfunction.
2. voidSprint(floatx,floaty,char*st):
Thisfunctionisusedtoprintthetextonthevisualizerwindow.Ittakesxandyaspixel
values,whichisthepointonthescreenwherethecharacterisrequiredtobeprintedof
typefont.PositioningisachievedthroughglRasterPos3f(x,y,-1).Ifstringisneededtobe printed then,
find the length of the string needed to be printed and using the loop construct call
glutBitmapCharacter to print the character by character until the loop ends.
This function uses “glutTimerFunc()” that calls back this function once timer ellapses.
4. voidDraw_gear( void):
This function is used to draw the gears of the hands (second,minute& hour) at the back end of the
clock.
This uses “gluCylinder()” and “gluDisk()”to draw the gears of every individual hand.
5. voidDraw_clock(GLfloatcx,GLfloatcy,GLfloatcz):
This function basically draws the whole face of the clock. This includes a round circular board and
three conic geometrics (second, minute & hour).
The face of the clock is drawn using the function “gluDisk()” with the appropriate parameters.
Now the conic geometrics I.e; the second hand, minute hand, and hour hand are drawn using the
functions “glRotatef()” to rotate the hands periodically and “gluCylinder()” with appropriate
parameters to draw the hands of the clock.
6. voidnum():
Thisfunctionistodisplaythenumbers(1to12)alongwithitscorrespondingseconds
onthefaceoftheclock.
This calls the user defined function “Sprint()” with appropriate co-ordinates and numbers.
7. voidabout():
Thisfunctiongivesthedescriptionoftheclockonthevisualizerwindow.
Thisusestheuserdefinedfunction“Sprint()”todisplaythecharacters.
8.voiddisplay_wind_energy():
This function basically renders various views of the clock like ortho view and perspective view
depending upon the “if” condition. Depending upon the input giventheuser defined function
“draw_wind_energy()” and “num()” are called.
9.voidmain(intargc,char**argv):
This is the function from where the execution of the program begins.
In this function we have certain “gl” functions used to initialize the basic glut window
withdesiredproperties.Afterinitializationthedisplayfunctioniscalledwithrespectto
thewindowandfinallythelaststatementofthissectionistheglutMainLoop().
CHAPTER 5
RESULT
5.1 SNAPSHOTS
FIG 5.1: WELCOME PAGE
CHAPTER 6
CONCLUSION
Thus in this project we have acquired a lot of knowledge about
various techniques in OpenGL programming. We have
explored many new concepts on the World Wide Web, such as
Texture mapping, randomizing, color swapping etc.
BIBLIOGRAPHY
Books:
Websites:
1. http://www.amazon.in/Computer-Graphics-Multimedia-Udit-
Agarwal/dp/935014316X?tag=googinhydr18418-21
2. http://en.wikipedia.org/wiki/Computer_graphics
3. https://www.youtube.com/watch?v=Hj6-M-Vj0p4