1.1 Computer Graphics: Multi Level Mirror Effect
1.1 Computer Graphics: Multi Level Mirror Effect
Chapter 1
Introduction
With the use of interactive graphics we can control the movement of an object.
The interactive graphics provides tool called motion dynamics. With this tool user
can move and tumble objects with respect to stationary observer, or he can make
object stationary and the viewer moving around them.
Interactive graphics provides facility called update dynamics.
Chapter 2
Introduction to OpenGL
OpenGL API
OpenGL is strictly defined as “a software interface to graphics hardware”. In
essence, it is a 3D graphics and modeling library that is highly portable and very fast.
Using OpenGL, you can create elegant and beautiful 3D graphics with exceptional visual
quality. The greatest advantage to using OpenGL is that it is orders of magnitude faster
than a ray tracer or software rendering engine. Initially, it used algorithms carefully
developed and optimized by Silicon Graphics, Inc. (SGI), an acknowledged world leader
in computer graphics and animation. Over time, OpenGL has evolved as other vendors
have contributed their expertise and intellectual property to develop high-performance
implementations of their own.
OpenGL is not a programming language like C or C++. It is more like the C
runtime library, which provides some prepackaged functionality. There really is no such
thing as an “OpenGL program” but rather a program the developer wrote that “happens”
to use OpenGL as one of its Application Programming Interfaces (APIs). One might use
the C runtime library to access a file or the Internet, and one might use OpenGL to create
real-time 3D graphics.
OpenGL is intended for use with computer hardware that is designed and
optimized for the display and manipulation of 3D graphics. Software-only
implementations of OpenGL are also possible, and the older Microsoft implementations
and Mesa3D fall into this category. Apple also makes a software implementation
available on OS X. With these software-only implementations, rendering may not be
performed as quickly, and some advanced special effects may not be available at all.
However, using a software implementation means that your program can potentially run
on a wider variety of computer systems that may not have a 3D accelerated graphics card
installed.
OpenGL is used for various purposes, from CAD engineering and architectural
applications to modeling programs used to create computer-generated monsters in
Chapter 3
Requirement Specification
Chapter 4
Design
Virtual memory is a technique that allows the execution of processes that may not
be completely in memory. Hence can be larger than the physical memory. This frees
programmers from the concern of memory storage limitations.
The objective is to create a “Multi Level Mirror Effect” that has the objects like
spike ball, teapot, sphere and cone, where the sphere will be rotating around the cone and it will
reflect on a wall. We can also view the top view of the objects. The model will be created
through OpenGL programming.
When we start drawing any graphics on the screen we need a header file called
GL/glut.h, stdlib.h, stdio.h and stdarg.h. The header file contains definitions and
explanations of the functions and constants we will need, whereas the graphics functions
are kept in the OpenGL utility library.
The OpenGL Utility Library (GLU) contains several groups of commands that
complement the core OpenGL interface by providing support for auxiliary features. Since
these utility routines make use of core OpenGL commands, any OpenGL implementation
is guaranteed to support the utility routines. Note that the prefix for Utility Library
routines is glu.
Chapter 5
Implementation
glutInit(&argc,argv);
This function initializes the interaction between opengl toolkit and windows.
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLULT_DEPTH);
This function characterizes the window with RGB colors, depth buffer for
hidden surface removal and double rather than GLUT_DOUBLE.
glBegin();
Initiates a new primitive of type mode and starts the collection of vertices values of mode
include GL_POINTS,GL_POLYGON etc.
glBegin(GL_LINES);
glEnd();
This module is used to draw lines
glBegin(GL_POINTS);
glEnd();
This is the module to draw the pixels.
glBegin(GL_POLYGON);
glEnd();
This is the module function to draw the polygons
glColor3f(RGB color format );
This function Sets the current color used for drawing.
glutCreateWindow(char *title);
Opens a window with the previously specifies size, position, and other properties.
The specified text string may be displayed in the window title bar, depending on the
options available in the window system.
glutInitWindowSize(int width,int height);
This function specifies the initial position of the top-left corner of the window.
glutInitWindowPosition();
Initializes GLUT and specifies command-line options for window system in use.
This function should be called before any other GLUT routine.
glutDisplayFunc(user defined function);
This opengl call to user defined functions.
glutKeyboardFunc(user defined func);
This is the opengl call to use keyboard interaction.
glFlush();
This function forces any buffered Open gl commands to execute.
glRotate( );
This function Rotates the current matrix by a Rotation matrix
Void glRotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
This function multiplies the current matrix by a Rotation matrix that performs a
counterclockwise rotation around a directional vector that passes from the origin through the
point (x,y,z). The newly rotated matrix becomes the current Transformation matrix.
glTranslate( );
This function Multiplies the current matrix by a Translation matrix.
void glTranslatef(GLfloat x, GLfloat y, GLfloat z);
This function multiplies the current matrix by a Translation matrix. The newly translated
matrix becomes the current Transformation matrix.
glutPostRedisplay();
Request that the display callback be executed after the current callback returns.
glPushMatrix( );
This function Pushes the current matrix onto the matrix stack. This function is used to
push the current matrix onto the current matrix stack. This is most often used to save the
current Transformation matrix so that it can be restored later with a call to glPopMatrix.
glPopMatrix( );
This function Pops the current matrix off the matrix stack. This function is used to
pop the last (topmost) matrix off the current matrix stack. This is most often used to restore
the previous condition of the current Transformation matrix if it was saved with a call to
glPushMatrix.
gluLookAt();
This function Defines a viewing transformation.
void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez,
GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble
upx, GLdouble upy, GLdouble upz );
This function defines a viewing transformation based on the position of the eye, the
position of the center of the scene, and a vector pointing up from the viewer’s perspective.
glclear( );
We need an instruction to do the actual clearing. This accomplished by the line
glClear(GL_COLOR_BUFFER_BIT);
The glClear() function clears a particular buffer or combination of buffers. A buffer is a
storage area for image information. The red, green, and blue components of a drawing
actually have separate buffers, but they are usually collectively referred to as the color
glClearColor();
In the glClearColor function, the first three parameters set the RGB color
components in the range 0 to 1. The fourth parameter is used to set an “alpha value”.
glViewport(int x, int y, Glsizei width,Glsizei height)
Specifies a width*height view port in pixels whose lower left corner is at (x,y)
measured from the origin of the window.
glLoadIdentity( );
This function Sets the current matrix to Identity.
void glLoadIdentity(void);
This function replaces the current Transformation matrix with the Identity matrix.This
essentially resets the coordinate system to eye coordinates.
glVertex3f();
A vertex is a position in space. We vertices to define atomic geometric primitives that are
recognized by our graphics system.
glutMainLoop();
Cause the program to enter an event processing loop.It should be the last statement in
main( ).
glEnable();
Enables an OpenGL features,Features that can be enabled include
GL_DEPTH_TEST,GL_LIGHTING,GL_LIGHTi and GL_NORMALIZE.
Chapter 6
Snapshots
Chapter 7
Conclusion
This program is user friendly and has an interactive user interface. Keyboard
interaction serves a lot to the program. The multi-level mirror effect has been designed which
recognizes the concept of lighting and depth of a particular object under OpenGL using
simple geometric primitives. It demonstrates the basics which are required to create
some preliminary objects like sphere, teapot, and spike, here we have also included the
camera effects. Here we mainly concentrated on reflection, rotation and shading of the
objects.
This application gave us an opportunity to explore the graphic abilities of OpenGL.
We can further improve this mini project depending on the needs and views of the users.
This mini project has enhanced our programming and imaginative abilities to a great
extent.
Bibliography
Websites Reffered
http://www.opengl.org