0% found this document useful (0 votes)
71 views15 pages

4.1 Overview of The Project

This project summarizes the key features and functions of a 3D graphics editor developed in C++ on the Windows platform. It provides basic modeling operations like contouring, depth, color changes, and rotation. The interface is designed to be user-friendly. Common functions used include glutInit() to initialize GLUT, glutMainLoop() to enter the event loop, glutSwapBuffers() for buffer swapping, and glutKeyboardFunc() to set the keyboard callback. Basic shapes are drawn using vertices specified between glBegin() and glEnd() calls.

Uploaded by

rjgsanka
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views15 pages

4.1 Overview of The Project

This project summarizes the key features and functions of a 3D graphics editor developed in C++ on the Windows platform. It provides basic modeling operations like contouring, depth, color changes, and rotation. The interface is designed to be user-friendly. Common functions used include glutInit() to initialize GLUT, glutMainLoop() to enter the event loop, glutSwapBuffers() for buffer swapping, and glutKeyboardFunc() to set the keyboard callback. Basic shapes are drawn using vertices specified between glBegin() and glEnd() calls.

Uploaded by

rjgsanka
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

Description of the project

4- DESCRIPTION OF THE PROJECT

4.1 OVERVIEW OF THE PROJECT:

This project provides most of the features that a 3D


graphic editor should have. It is developed in C++ programming
language and implemented on the WINDOWS platform. The graphics
package designed here provides an interface for the users for handling
the display and manipulation of basic picture objects. The operations like
contouring , depth, color change, rotation is shown here. The interface is
user-friendly.

4.2 DESIGN:

The Graphics Package is designed using the in built graphics


library. The objects, which are drawn, are stored as functions that can be
used according to the requirements which should be kept in mind during
phase of design and implementation.

4.3 COMMON FUNCTIONS USED IN THE PROJECT:

The 2-D transformation project has been developed in turbo c++


compiler that also provides an in-built graphics library through
"GL/glut.h".
Following are the brief descriptions of the functions used for the
implementation of the program.

 Main:
• The execution of the program starts from the main function.
• Main function initializes the system, describes therequired

Dept of CSE, NCET 9


Description of the project
display properties, creates the output window etc.

• The last statement of main function puts the program in an


event loop and the program’s further behaviour is determined
through the callbacks.
glutMainLoop();
• In this program we call reshape ,keyboard, animate, display
functions.
glutReshapeFunc(Reshape);
glutKeyboardFunc(key);
glutIdleFunc(Animate);
glutDisplayFunc(Animate);
• Here in this program we create the window of width 300
and height 300. The name of the window is “WAVE DEMO”.
glutInitwindowSize(300,300);
glutCreateWindow(“WAVE DEMO”);

 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

Dept of CSE, NCET 10


Description of the project
may cause the termination of the GLUT program with an error
message to the user if GLUT cannot be properly initialized.

 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.

Dept of CSE, NCET 11


Description of the project
• If the layer in use is not double buffered,
glutSwapBuffers has no effect.

 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

Dept of CSE, NCET 12


Description of the project
“3” refers to 3-dimension “f” refers to floating point numbers
and we use “v” if we use to store the information for a 3-
dimensional vertex.

• To specify a vertex in a 2- dimension we have to use a


command glVertex2f(GLfloatx,GLfloaty);.
• For int use “i” in the 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.

 glBegin() and glEnd();


• We can group as many vertices between these functions
to draw different primitives.

Dept of CSE, NCET 13


Description of the project
• The argument of glBegin(); specifies the geometric type that
we wnt our vertices to define.
• Wecan draw different types by using GL_POLYGON,
GL_LINE_LOOP, GL_QUAD_STRIP, GL_POINTS etc.

• If we want to draw lines , we can write


glBegin(GL_LINES);
glVertex3f(x1,y2,z3);
glVertex3f(x4,y5,z6);
glEnd() ;

 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

Dept of CSE, NCET 14


Description of the project
initially registered, and ASCII key strokes in the window are
ignored.
• Passing NULL to glutKeyboardFunc disables the generation of
keyboard callbacks.

 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.

Dept of CSE, NCET 15


Description of the project

4.5 MATRIX TRANSFORMATIONS:

• Vertices and normals are transformed by the modelview


and projection matrices before they're used to produce an
image in the frame buffer.
• You can use commands such as glMatrixMode(), glMultMatrix(),
glRotate() and glTranslate() to compose the desired
transformations, or you can directly specify matrices with
glLoadMatrix() and glLoadIdentity().
• Use glPushMatrix() and glPopMatrix() to save and restore
modelview and projection matrices on their respective
stacks.

 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.

Dept of CSE, NCET 16


Description of the project
 glLoadIdentity:
• The glLoadIdentity function replaces the current
transformation matrix with the identity matrix.
void glLoadIdentity(void);

 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 ENABLE AND DISABLE FEATURES:

• Use thus OpenGL command for enabling some of the OpenGL


features
void glEnable(GLenum feature);

Dept of CSE, NCET 17


Description of the project
• Use this command for disabling some of the OpenGL feature
void glDisable(GLenum feature);
• Some of the features are GL_DEPTH_TEST ,GL_LIGHTING,
GL_LIGHT0 , GL_LIGHTi , GL_TEXTURE_1D , GL_TEXTURE_2D ,
GL_TEXTURE_3D, GL_LINE_SMOOTH , GL_BLEND , GL_LINE_STIPPLE
etc.

• Example: Turning on the depth testing


Depth testing is used to remove hidden surfaces. We
did not yet need it, because we always rendered wired
objects. Lighting makes much more sense, when objects are
filled and wired model everything else but certainly not
realistic. Depth testing is difficult easy to use. Pass one
more constant to the below function
InitDisplayMode (GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);
Now a depth buffer is created on which the depth
information is stored for each pixel. The next thing is to enable
it glEnable(GL_DEPTH_TEST);. If u want disable depth_test
by giving glDisable(GL_DEPTH_TEST);.

4.6 SHADING:

• Shades are computed at one or more vertices as


part of the geometric part of the pipeline. Shades are then
assigned to fragment by interpolating these vertex shades
as part of fragment processing.
glShadeModel (GL_SMOOTH);

Dept of CSE, NCET 18


Description of the project
• The above function enables smooth shading to assign
each vertex, the normal of the polygon being shaded.

4.7 TRANSLATION,ROTATION AND SCALING:

• Translation is an operation that displaces points by


a fixed distance in a given direction, to specify a translation
we need only specify a displacement vector d. Because the
transformation points are given by, p’=P+d for all points P
on the object.
• That pixel information is stored in a buffer. The bottom
right corner of the area is considered as reference for
translation. The selected area is moved using mouse to the
destination by dragging it.
• The command is glTranslatef(dx,dy,dz);

• Rotation is more difficult specify than translation because


we must specify more parameters. A two dimensional point at
(x, y) in this frame is rotated about the origin by an angle ө
to the position (x’, y’) we can obtain the standard equation
describing this rotation by representing (x, y) and (x’, y’) in
polar form:
x=ρ cos(Φ),
y=ρ sin(Φ),

Dept of CSE, NCET 19


Description of the project
x’=ρ cos(Φ+ Ө),
y’=ρ sin(Φ+ Ө),
• Expanding this using the trigonometric identities for the
sine and cosine of the sum of two angles we find,
x’=xcos(Ө)-ysin(Ө)
y’= xsin(Ө)-ycos (Ө).

• Rotation and translation are known as rigid-body


transformations.
• No combination of rotations and translations can alter the
shape or volume of an object; they can alter only the
object’s location and orientation.
• The command used to rotate the object is
glRotatef(angle,vx,vy,vz);
• Here the parameter angle is specified in degrees and the
variables vx, vy, vz are the components of the vector about
which we wish to rotate.

• In scaling there is a fixed point that is unchanged by


transformation. Let the fixed point be origin.
• A scaling matrix with a fixed point of the origin allows for
independent scaling along the coordinate axes.
• The equations are
x’= βx x
y’= βy y
z’= βz z
• These equations are combined in homogeneous form as
p’=Sp.

Dept of CSE, NCET 20


Description of the project

4.8 TEXTURE MAPPING:

• Texture mapping uses a pattern to determine the color of


a fragment . These patterns could be determined by a fixed
pattern , such as a regular pattern often used to fill polygons;
by a procedural texture-generation method or through the
diditized image.
• Texture are patterns. They can range from regular patterns
such as stripes and checkerboards, to the complex patterns
that characterize natural materials.
• Texture can be done in 1,2,3,4 dimension.
 OpenGL functions used in texture mapping:
• This function sets up a 2-dimensional texture target of
height x width texels of type and format.The array texels is
of format iformat. A border of 0 or 1 can be specified.
glTexImage2D[ui as f]v(GLenum target, GLint level,
GLint format, GLsizei width , GLsizei height, Glint border,
GLenum format, GLenum type, GLvoid *texels);
• This function sets the texture parameter param to value
for texture of type target (GL_TEXTURE_1D, GL_TEXTURE_2D,
GL_TEXTURE_3D)

Dept of CSE, NCET 21


Description of the project
glTexParameter[if](GLenum target , GLenum param,
TYPE value);
glTexParameter[if]v(GLenum target , GLenum param,
TYPE *value);
• This function sets texture param to value. Here target
must be GL_TEXTURE_ENV.
glTexenv[if](GLenum target, Glenum param, TYPE
value);
glTexenv[if]v(GLenum target, Glenum param, TYPE
*value);

• This function sets up automatic texture coordinate


generation for coordinate texcoord(GL_S, GL_T, GL_R or GL_Q).If
name is GL_TEXTURE_GEN_MODE then param specifies the
method for generating the coordinate values.If the name is
GL_OBJECT_LINEAR or GL_EYE_LINEAR ,then param is an array
containing values that determine a plane.
glTexGen[ifd](GLenum texcoord , GLenum name, TYPE
param);
glTexGen[ifd]v(GLenum texcoord , GLenum name, TYPE
*param);

4.9 MATERIAL PROPERTIES IN OPENGL:

• Ambient reflector: The uniform lighting on the objects is called


ambient. That is the intensity of the light is same at every point on
the surface.
• Diffuse reflector: A perfectly diffuse reflector scatters the light
that it reflects equally in all directions. Hence such a surface
appears to same to all viewers.

Dept of CSE, NCET 22


Description of the project
• These functions specify the required vector and scalar
parameters. There are four vector parameters that we can set :
the position of the light source and the amount of ambient,diffuse
and specular lght associated with the source.
glLightfv(GLenum source,GLenum parameter,Glenum
*pointer_to_ array) ;
glLightfv(GLenum source,Glenum parameter,Glfloat
value);

Dept of CSE, NCET 23

You might also like