4.1 Overview of The Project
4.1 Overview of The Project
4.2 DESIGN:
Main:
• The execution of the program starts from the main function.
• Main function initializes the system, describes therequired
glutInit():
• glutInit is used to initialize the GLUT library.
void glutInit(int *argcp, char **argv);
• argcp : A pointer to the program's unmodified argc
variable from main. Upon return, the value pointed to by
argcp will be updated, because glutInit extracts any command
line options intended for the GLUT library.
• argv :The program's unmodified argv variable from main.
Like argcp, the data for argv will be updated because glutInit
extracts any command line options understood by the GLUT
library.
• glutInit will initialize the GLUT library and negotiate a
session with the window system. During this process, glutInit
GlutMainLoop():
• glutMainLoop enters the GLUT event processing loop.
• void glutMainLoop(void);
• glutMainLoop enters the GLUT event processing loop. This
routine should be called at most once in a GLUT program.
Once called, this routine will never return.
• It will call as necessary any callbacks that have been
registered.
glutSwapBuffers():
• glutSwapBuffers swaps the buffers of the current window
if double buffered.
void glutSwapBuffers(void);
• Performs a buffer swap on the layer in use for the
current window. Specifically, glutSwapBuffers promotes the
contents of the back buffer of the layer in use of the
current window to become the contents of the front buffer.
The contents of the back buffer then become undefined. The
update typically takes place during the vertical retrace of the
monitor, rather than immediately after glutSwapBuffers is
called.
• An implicit glFlush is done by glutSwapBuffers before it
returns. Subsequent OpenGL commands can be issued
immediately after calling glutSwapBuffers, but are not
executed until the buffer exchange is completed.
glutInitDisplayMode():
• glutInitDisplayMode — sets the initial display mode.
• void glutInitDisplayMode(unsigned int mode);
• It requests a display with the properties in modes. The
value of mode is determined by the logical OR (|) of options
including the color model (GLUT_RGB,GLUT_INDEX) buffering
(GLUT_SINGLE,GLUT_DOUBLE).
• The initial display mode is used when creating top-level
windows, subwindows, and overlays to determine the OpenGL
display mode for the to be- created window or overlay. any
bits of alpha (sometimes called an alpha buffer or destination
alpha) be allocated.
• Note that GLUT_RGBA selects the RGBA color model, but it
does not request. To request alpha, specify GLUT_ALPHA. The
same applies to GLUT_LUMINANCE. Note that some bits "request"
a capability and other bits "select" a capability. A requestable
capability may be assigned to the create window.
• For example, GLUT may create a window with a depth
buffer even though GLUT_DEPTH is not specified.
Vertices:
• To specify a vertex we have to use the glut command
glVertex3fv(GLfloatx,GLfloaty,GLfloatz); . In this command
glFlush():
• glFlush — force execution of GL commands in finite time.
• void glFlush();
• Different GL implementations buffer commands in several
different locations, including network buffers and the graphics
accelerator itself. glFlush empties all of these buffers, causing
all issued commands to be executed as quickly as they are
accepted by the actual rendering engine. Though this execution
may not be completed in any particular time period, it does
complete in finite time.Because any GL program might be
executed over a network, or on an accelerator that buffers
commands, all programs should call glFlush whenever they count
on having all of their previously issued commands
completed.
• For example, call glFlush before waiting for user input that
depends on the generated image.
glutKeyboardFunc():
• glutKeyboardFunc sets the keyboard callback for the current
window.
void glutKeyboardFunc(void (*func)(unsigned char key, int
x, int y));
• This function registers the new keyboard callback
function.
• glutKeyboardFunc sets the keyboard callback for the current
window.
• When a user types into the window, each key press
generating an ASCII character will generate a keyboard callback.
The key callback parameter is the generated ASCII character. The
state of modifier keys such as Shift cannot be determined
directly; their only effect will be on the returned ASCII data.
• The x and y callback parameters indicate the mouse location
in window relative coordinates when the key was pressed.
When a new window is created, no keyboard callback is
Color:
• Color is handled in a graphics system from the programmers
perspective that is through an API. There are two different
approaches RGB-color model and indexed-color model.
• We use RGB color system here, there are conceptually 3
separate buffers for red, green and blue colors. Each pixel
operation has separate red, green and blue components that
correspond to locations in the memory.
• A natural technique is use the color cube and to specify
color components as numbers from 0.0 to 1.0.
• To draw in red use this command glColor3f(1.0,0.0,0.0);
.The execution of this command will set the drawing color is
red.
• We shall also use the 4 color system –RGBA. The fourth
color is alpha which is stored in the frame buffer. This can be set
with 4 dimensional versions of the color systems.
• The function call glClearColor(1.0,1.0,1.0,1.0); define an
RGB color clearing color that is white, because the first three
components are set to 1.0, and is opaque because the alpha
component is set 1.0.
• We can then use the command glClear to make the
window solid and white.
glMatrixMode:
• The glMatrixMode function specifies which matrix is the
current matrix.
• void glMatrixMode(GLenum mode);
• Parameter mode refers to the matrix stack that is the
target for subsequent matrix operations. The mode has values like
GL_MODELVIEW , GL_PROJECTION, GL_TEXTURE.
gluPerspective:
• The gluPerspective function sets up a perspective
projection matrix. The gluPerspective function specifies a
viewing frustrum into the world coordinate system.
• In general aspect ratio in gluPerspective should match the
aspect ratio of the associated viewport.
• void gluPerspective (GLdouble fovy,GLdouble aspect,
GLdouble near , GLdouble far);
• Parameters: fovy- the field of view angle in degrees in y-
direction. aspect –the aspect ratio that determines the field
of view in x-direction. It is the ratio of x(width) to y(height).
Znear- The distance from the viewer to the near clipping plane.
Zfar- The distance from the viewer to the far clipping
plane.
4.6 SHADING: