Professional Documents
Culture Documents
1.Introduction
Graphics provides one of the most natural means of communicating with a computer,
since our highly developed 2D and 3D pattern-recognition abilities allow us to perceive and
process pictorial data rapidly and efficiently. Interactive computer graphics is the most
important means of producing pictures since the invention of photography and television. It
has the added advantage that, with the computer, we can make pictures not only of concrete
real world objects but also of abstract, synthetic objects, such as mathematical surfaces and
of data that have no inherent geometry, such as survey results.
Using this editor you can draw and paint using the mouse. It can also perform a host
of other functions like drawing lines, circles, polygons and so on. Interactive picture
construction techniques such as basic positioning methods, rubber-band methods are used.
Block operations like cut, copy and paste are supported to edit large areas of the workspace
simultaneously. It is user friendly and intuitive to use.
Graphics Editors can normally be classified as:
2D Graphics Editors.
3D Graphics Editors.
Dept of CSE,REC,hulkoti 1
Graphics Editor
3D modelers are used in a wide variety of industries. The movie industry uses them to create
and manipulate characters and objects for animated and real-life motion pictures. The video
game industry uses them to create assets for video games. The science sector uses them to
create highly detailed models of chemical compounds. The architecture industry uses them to
create models of proposed buildings and landscapes. The engineering community uses them
to design new devices, vehicles and structures as well as a host of other uses.
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 raytracer 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.
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. 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.
Dept of CSE,REC,hulkoti 2 2
Graphics Editor
OpenGL is used for various purposes, from CAD engineering and architectural
applications to modeling programs used to create computer-generated monsters in
blockbuster movies. The introduction of an industry-standard 3D API to mass-market
operating systems such as Microsoft Windows and the Macintosh OS X has some exciting
repercussions. With hardware acceleration and fast PC microprocessors becoming
commonplace, 3D graphics are now typical components of consumer and business
applications, not only of games and scientific applications.
1. User Interface- The presentation of the graphics editor is crucial to its acceptance by
its users. The package should provide easy selection and implementation of the
features through iconic interfaces.
2. Color Selection - To select a suitable color for drawing the primitives. The editor
implements support for drawing various shapes mentioned above.
3. Graphics Drawing – To draw basic primitives like line, circle, rectangle on the
canvas and to use tools like pencil, colour filling, eraser, etc. to manipulate the image.
Line: line is drawn by selecting two points start point and the end point. The
start point begins with mouse click and end point is the point where mouse
button is released.
Circle: Circle is drawn by selecting a point and dragging thereafter till the
desired radius.
Text: selecting the text icon and thereafter entering the text from keyboard
Rectangle: rectangle is drawn by selecting a start point and dragging to end
point of required size.
Dept of CSE,REC,hulkoti 3 3
Graphics Editor
Other features:
Fill Shapes: this is done by selecting a co-ordinate by click of mouse and the
enclosed area of the point is filled with the selected color.
Eraser: this feature allows deleting particular portions of figure as selected by
click of the user.
Dialog boxes: Dialog boxes and menus add user friendliness to the package.
The aim of this project is to develop a 2-D graphics package which supports basic
operations which include creating objects like lines, circles, polygons, etc. The package must
also have a user-friendly interface that may be menu-oriented, iconic or a combination of
both.
1.5 Scope
It provides most the features that a 2D graphic editor should have. It is developed in
VC++. it has been implemented by using openGL APIs. The 2-D graphics package designed
here provides an interface for the users for handling the display and manipulation of basic
picture objects like point, line, rectangle, polygon, etc. It also provides various features like
colour filling, erasing, etc. The interface is user -friendly with icons for all the functions. The
mouse is the main input device used.
Dept of CSE,REC,hulkoti 4 4
Graphics Editor
Dept of CSE,REC,hulkoti 5 5
Graphics Editor
2.Literature Survey
Computer graphics is the creation and manipulation of pictures with the aid of computers. It
is divided into two broad classes:
Non-Interactive Graphics.
Interactive Graphics.
Non-Interactive graphics
This is a type of graphics where observer has no control over the pictures produced
on the screen. It is also called as Passive graphics.
Interactive Graphics
This is the type of computer graphics in which the user can control the pictures
produced. It involves two-way communication between user and computer. The computer
upon receiving signal from the input device can modify the displayed picture appropriately.
To the user it appears that the picture changes instantaneously in response to his commands.
2.1 Icon Interface
An icon is a pictorial representation of an object, an action or a property. The user-
interface designer often has the choice of using icons to represent such concepts. Here icons
have been used for feature selection.
Dept of CSE,REC,hulkoti 6
Graphics Editor
3.1 Introduction
Dept of CSE,REC,hulkoti 7 7
Graphics Editor
Dept of CSE,REC,hulkoti 8 8
Graphics Editor
System Design
Dept of CSE,REC,hulkoti 9 9
Graphics Editor
This is the most important algorithm used here in this editor. This is an accurate and efficient
raster line-generating algorithm that scans converts line using only incremental integer
calculations that is adapted here to display lines. The algorithm can be suitably adapted for
drawing circles and other curves.
Free- hand drawing is a special case of polyline drawing where we have a large number of
points obtained by continuously poling the mouse position during the time the mouse' left
button is clicked.
4.3Design Techniques
The various techniques that are implemented in this projects are as given below.
4.3.1Rubber-Banding Technique
One way to construct a line is to have the user indicate one endpoint and then the
other, once the second endpoint is specified, a line is drawn between the two points. With
this technique however the user has no easy way to try out different line positions before
settling on a final one, because the line is not actually drawn until the second endpoint is
given. A far superior approach is Rubber-Banding. When the user clicks the mouse button,
the starting position of the line is established by the cursor. As the cursor moves, so does the
endpoint of the line. When the button is released, the endpoint is frozen. The rubber-band is
active only when the mouse button is held down. It is in this state that cursor movements
cause the current line to change. An entire genre of interaction techniques is derived from
rubber-banding line drawing. The same concept can be extended to rectangle, circle, ellipse
or polygon drawing.
Dept of CSE,REC,hulkoti 10 10
Graphics Editor
Dept of CSE,REC,hulkoti 11 11
Graphics Editor
CirclePoints( x, y, value );
}
}
4.1.3. Integration:
All the fore-mentioned units are integrated to completely give us the graphics
editor.
5.Detailed Design
This design stage involves the actual building of the core components of the different
functions, which are involved in the graphics editor. The design can be sub-divided as
follows
Dept of CSE,REC,hulkoti 12 12
Graphics Editor
The design is done mainly using glut library functions or APIs. The design of the
User Interface is done in such a way that it is based on simple iconic interfaces with
toolboxes for various operations, drawing primitive selection, color selection and fill pattern
selection.
The main algorithm for the graphics editor is the one shown below.
4.2 If so then
that button.
color.
executed.
5. Close the graphics mode and restore back the CRT mode.
Dept of CSE,REC,hulkoti 13 13
Graphics Editor
As we see above, the main algorithm is an infinite loop continuously polling for
mouse movements. Whenever the mouse is clicked, the position of the mouse is checked and
depending on the position of the mouse the appropriate operation is executed. The loop is
exited when the user wants to quit the editor.
6.Implementation
6.1 Working With The Window System
6.1.1 glutInit
glutInit is used to initialize the GLUT library.
Usage
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.
Description
glutInit will initialize the GLUT library and negotiate a session with the window
system. During this process, glutInit may cause the termination of the GLUT program with
an error message to the user if GLUT cannot be properly initialized. Examples of this
situation include the failure to connect to the window system, the lack of window system
support for OpenGL, and invalid command line options. glutInit also processes command
line options, but the specific options parse are window system dependent.
Dept of CSE,REC,hulkoti 14 14
Graphics Editor
Description
Windows created by glutCreateWindow will be requested to be created with the
current initial windowposition and size. The initial value of the initial window position
GLUT state is -1 and -1. If either the X or Y component tothe initial window position is
negative, the actual window position is left to the window system to determine.
6.1.3 glutInitDisplayMode
glutInitDisplayMode sets the initial display mode.
Usage
void glutInitDisplayMode(unsigned int mode);
mode Display mode, normally the bitwise OR-ing of GLUT display mode bit masks. See
values below:
GLUT RGBA Bit mask to select an RGBA mode window. This is the default if neither
GLUT RGBA nor
GLUT INDEX are specified.
GLUT RGB An alias for GLUT RGBA.
GLUT SINGLE Bit mask to select a single buffered window. This is the default if neither
GLUT DOUBLE or
GLUT SINGLE are specified.
Dept of CSE,REC,hulkoti 15 15
Graphics Editor
GLUT DOUBLE Bit mask to select a double buffered window. This overrides GLUT
SINGLE if it is also specified.
GLUT DEPTH Bit mask to select a window with a depth buffer
Dept of CSE,REC,hulkoti 16 16
Graphics Editor
Initiates a new primitive of type mode and starts the collection of vertices. Values of
mode include GL_POINTS, GL_LINES, GL_POLYGON, GL_LINE_LOOP,
GL_TRIANGLES.
6.3.1 Menu
GLUT supports simple cascading pop-up menus. They are designed to let a user
select various modes within a program. The functionality is simple and minimalistic and is
meant to be that way. Do not mistake GLUT's pop-up menu facility with an attempt to create
a full-featured user interface. It is illegal to create or destroy menus, or change, add, or
remove menu items while a menu (and any cascaded sub-menus) are in use (that is, popped
up).
The popup menus can be arranged in a hierachy of menus, sub-menus, sub-sub-menus, and
so on. Since a sub-menu identifier must be passed as an argument to the GLUT functions that
create the parent menu, the menu must be created from the bottom up. For example, assume
we want to create a main menu with entries Option A or Submenu1, where the sub-menu has
entries of Options B, C, or Submenu2, where the sub-sub-menu has Options D and E.
Dept of CSE,REC,hulkoti 17 17
Graphics Editor
Submenu identifiers must be declared for each of our menu entries. This is a unique
integer value will be assigned as the menus are called by glutCreateMenu(). Start with the
lowest level menu and pass as an argument the callback function, menuCB, which defines
menu selection options. To create the lowest level menu and its entries:
Finally, we need to go the same thing for the highest level menu:
glutCreateMenu(menuCB);
glutAddMenuEntry("Option A", 1);
glutAddSubMenu("SubMenu1", sub1);
glutAddMenuEntry("Quit", 6)
These menu options can now be used in the callback function menuCB to process the users
menu choice.
void menuCB(int item)
{
switch (item) {
case 1:
/ do whatever option A does
break;
case 2:
/ do whatever option B does
Dept of CSE,REC,hulkoti 18 18
Graphics Editor
6.3.2Mouse
glutMouseFunc
Usage
void glutMouseFunc(void (*func)(int button, int state,
int x, int y));
func The new mouse callback function.
Description
glutMouseFunc sets the mouse callback for the current window. When a user presses
and releases mouse buttons in the window, each press and each release generates a mouse
callback.
The button parameter is one of GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON,
or GLUT_RIGHT_BUTTON. For systems with only two mouse buttons, it may not be
possible to generate GLUT_MIDDLE_BUTTON callback. For systems with a single
mouse button, it may be possible to generate only a GLUT LEFT BUTTON callback. The
state parameter is either GLUT UP or GLUT DOWN indicating whether the callback was
due to a release or press respectively. Thex and y callback parameters indicate the window
relative coordinates when the mouse button state changed.
If a GLUT DOWN callback for a specific button is triggered, the program can assume
a GLUT UP callback for the same buttonwill be generated (assuming the window still has a
mouse callback registered) when the mouse button is released even if the mouse has moved
outside the window.
If a menu is attached to a button for a window, mouse callbacks will not be generated
for that button. when the mouse event generating the callback occurred.
Passing NULL to glutMouseFunc disables the generation of mouse callbacks.
Dept of CSE,REC,hulkoti 19 19
Graphics Editor
6.3.3glutMotionFunc
glutMotionFunc set the motion callbacks respectively
for the current window.
Usage
void glutMotionFunc(void (*func)(int x, int y));
Description
glutMotionFunc set the motion callback for the current window. The motion callback
for a window is called when the mouse moves within the window while one or more mouse
buttons are pressed. The x and y callback parameters indicate the mouse location in window
relative coordinates.
Passing NULL to glutMotionFunc or glutPassiveMotionFunc disables the generation of the
mouse motion callback.
6.3.4Keyboard
glutKeyboardFunc
glutKeyboardFunc sets the keyboard callback for the current window.
Usage
void glutKeyboardFunc(void (*func)(unsigned char key,
int x, int y));
22 7. CALLBACK REGISTRATION
func The new keyboard callback function.
Description
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
Dept of CSE,REC,hulkoti 20 20
Graphics Editor
window relative coordinateswhen the key was pressed. When a new window is created, no
keyboard callback is initially registered, and ASCII key strokes in thewindow are ignored.
Passing NULL to glutKeyboardFunc disables the generation of keyboard callbacks.
6.3.5 glutReshapeFunc
Description
glutReshapeFunc sets the reshape callback for the current window. The reshape
callback is triggered when a window is reshaped. A reshape callback is also triggered
immediately before a window’s first display callback after a window is created or whenever
an overlay for the window is established. The width and heightparameters of the callback
specify the new window size in pixels. Before the callback, the current window is
set to the window that has been reshaped.
If a reshape callback is not registered for awindow or NULL is passed toglutReshapeFunc(to
deregister a previously registered callback), the default reshape callback is used. This default
callback will simply call glviewport(0,0,width,height) on the normal plane (and on the
overlay if one exists). If an overlay is established for thewindow, a single reshape callback
is generated. It is the callback’s responsibility to update both the normal plane and overlay
for the window (changing the layer in use as necessary).
6.4 Transformations
Dept of CSE,REC,hulkoti 21 21
Graphics Editor
Pushes to and pops from the matrix stack corresponding to the current matrix mode.
7. SNAPSHOTS
This section gives us an overview of various functions that have been implemented and their
respective representation on the output screen .The various functions are explained along
with the illustration of using it is as shown below.
A basic output of the editor before implementing any of the tools and the function used to
implement it is as shown below.
Dept of CSE,REC,hulkoti 22 22
Graphics Editor
Dept of CSE,REC,hulkoti 23 23
Graphics Editor
Dept of CSE,REC,hulkoti 24 24
Graphics Editor
Dept of CSE,REC,hulkoti 25 25
Graphics Editor
This graphics editor is very user friendly tool. The user can very easily use this tool to draw
or manipulate a drawing. The interface is mouse driven and the user can select a function by
clicking on an icon representing that function.
For the user’s help the function performed by each icon is displayed in the status bar
as soon as the mouse pointer moves over the icon. We have tried our best to make this editor
very realistic, so that the user does not face any trouble when switching over from any real
life graphics editor to this highly useful one.
The following are some of the features that are planned to be supported in the future versions
of the graphics editor.
Features like "Undo" and "Redo " could be provided.
The editor can be made to save images in standard image file formats such as bmp,
jpeg, gif. Therefore Support for different file formats like bmp, jpeg, gif etc. could be
provided.
Support for advanced 3d drawings and transformations.
Only Single Document Interface (SDI) has been provided, multiple document
interface can be provided.
Dept of CSE,REC,hulkoti 26 26
Graphics Editor
Bibliography
[3]. James D Foley, Andries Van Dam, Steven K Feiner, John F Huges,
[4]. Donald hearn and Pauline Baker: Computer Graphics-OpenGL Version ,2nd Edition
Dept of CSE,REC,hulkoti 27 27