Analog Clock

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

Analog Clock

CHAPTER 1

INTRODUCTION

Computer Graphics is a complex and diversified technology. To understand the


technology it is necessary to subdivide it into manageable Parts. This can be
accomplished by considering that the end product of computer graphics is a picture. The
picture may, of course, be used for a large variety of purposes; e.g., it may be an
engineering drawing, an exploded parts illustration for a service manual, a business
graph, an architectural rendering for a proposed construction or design project, an
advertising illustration, or a single frame from an animated movie. The picture is the
fundamental cohesive concept in computer graphics.
Consider how: Pictures are represented in computer graphics.
 Pictures are prepared for presentation.
 Previously prepared pictures are presented.
 Interaction with the picture is accomplished.
Here “picture” is used in its broadest sense to mean any collection of lines, points, text,
etc. displayed on a graphics device.

1.1 Computer Graphics


The totality of computer graphics software encompasses the concepts from data
structures, from data base design and management, from the psychology, ergonometric of
the man-machine interface, from programming languages and operating system.
Numerous computer graphics standards can be grouped following categories.
 First is the graphics application interface, where ideas are translated into a form
that is understandable by a computer system. Current representative standards are
the GKS, GKS-3D, and the Programmer’s Hierarchical Interactive Graphics
Standards (PHIGS).
 The Second is concerned with the storage and transmission of data between
graphics systems and between graphics-based computer aided design and
computer aided manufacturing systems. The current standard in this area is the
Initial Graphics Exchange Specification (IGES).

Dept. Of CSE, DSATM 2013-2014 Page 1


Analog Clock

A computer graphics system is a computer system with all the components of the general
purpose computer system. There are five major elements in system: input devices, proces-
sor, memory, frame buffer, output devices.

Fig. 1.1: A graphics system

1.2 A Brief History Of OpenGl


OpenGL was developed by Silicon Graphics and is popular in the video games industry
where it competes with Direct3D on Microsoft Windows IrisGL, a propietary graphics
API, is the precursor of OpenGL. It is developed by Silicon Graphics Inc. (SGI). IrisGL
was used as the starting point of an open standard for computer graphics that would save
time porting applications by avoiding direct hardware access. After SGI cleaned up IrisGL
and opened up the standard to other companies, OpenGL was born.

In 1992 the OpenGL Architectural Review Board (OpenGL ARB) was established. The
OpenGL ARB is a group of companies that maintain and update the OpenGL standard.

In 2003 the first OpenGL (Exchange Specification) ES specification was released. OpenGL
ES is a subset of OpenGL designed for mobile phones, embedded devices and video game
systems.

In 2004 the OpenGL 2.0 specification was released, including the GLSL (OpenGL Shading
Language) specification.

In August 2008, the OpenGL 3.0 specification was released.

Dept. Of CSE, DSATM 2013-2014 Page 2


Analog Clock

1.2.1 What is OpenGL?


 OpenGL is a Software Interface to Graphics Hardware
 OpenGL is designed as a streamlined, hardware-independent interface to be
implemented on many different hardware platforms
 It Consists of about 250 Distinct Commands.
 It is Hardware-independent Interface
• No command for windows or user input handling
• Does not include low-level I/O management
 It is developed primarily by SGI
 It consists of 2D/3D graphics, lower-level primitives (polygons)
 It is Basis for higher-level libraries/toolkits
What does it do?
 Main purpose is to render two and three dimensional objects into a frame buffer.
These objects are described as sequences of vertices (which define geometric
objects) or pixels (which define images).

1.2.2 Programming using OpenGL: A first Introduction

OpenGL is an API …

• Application programmers’ interface: link between

• low-level: graphics hardware

• high-level: application program you write


OpenGL is a …

Library for 2D and 3D graphics programming

• 200+ functions for building application programs

• Portable to many platforms (Win, Mac, Unix, Linux)

• Callable from many programming languages (C, Java,Perl, Python)

• Primarily concerned with modeling and rendering

Operations

• Specify geometric primitives (lines, pixels, polygons ...)

Dept. Of CSE, DSATM 2013-2014 Page 3


Analog Clock

• Apply geometric transformations


• Specify camera, light, color, texture information, etc.

• No windowing or (platform-specific) input/interaction

• functions— these are the jobs of GLUT

1.3 OpenGL-Related Libraries


OpenGL provides a powerful but primitive set of rendering commands, and all higher-
level drawing must be done in terms of these commands. Also, OpenGL programs have to
use the underlying mechanisms of the windowing system. A number of libraries exist to
allow you to simplify your programming tasks, including the following:

 The OpenGL Utility Library (GLU) contains several routines that use lower-level
OpenGL commands to perform such tasks as setting up matrices for specific viewing
orientations and projections, performing polygon tessellation, and rendering surfaces.
GLU routines use the prefix glu.
 The OpenGL Utility Toolkit (GLUT) is a window system-independent toolkit,
written by Mark Kilgard, to hide the complexities of differing window system
APIs. GLUT is the subject of the next section, and it’s described in more detail in
Mark Kilgard’s book OpenGL Programming forthe X Window System (ISBN 0-
201-48359-9). GLUT routines use the prefix glut. "How to Obtain the Sample
Code" in the Preface describes how to obtain the source code for GLUT, using ftp.

Dept. Of CSE, DSATM 2013-2014 Page 4


Analog Clock

CHAPTER 2
REQUIREMENTS SPECIFICATION

2.1 Hardware Requirements:


 Intel® Pentium 4 CPU and higher versions
 128 MB or more RAM.
 A standard keyboard, and Microsoft compatible mouse
 VGA monitor.

2.2 Software requirements:


 The graphics package has been designed for OpenGL; hence the machine must
Have Dev C++.
 Software installed preferably 6.0 or later versions with mouse driver installed.
 GLUT libraries, Glut utility toolkit must be available.
 Operating System: Windows
 Version of Operating System: Windows XP, Windows NT and Higher
  Language: C

2.3 MISCELLANEOUS REQUIREMENTS:


All the required library and header files should be available in the include directories. The
files associated with this editor should be placed in either the same folder or in a specified
folder.

2.4 LANGUAGE USED IN CODING:


C/C++ and OpenGL as an API.

Dept. Of CSE, DSATM 2013-2014 Page 5


Analog Clock

CHAPTER 3
SYSTEM DESIGN
Design of any software depends on the architecture of the machine on which that software
runs, for which the designer needs to know the system architecture. Design process
involves design of suitable algorithms, modules, subsystems, interfaces etc.

3.1 Architecture:

CONTROL FLOW DIAGRAM

START

main()

init() Options() Display() TimeEvent()

about() Display_clock()

Ortho/
Perspectivev view Sprint()

Light
ON/OFF Num()

Quit
Draw_clock()

Draw_gear()

Fig. 3.1: Control flow diagram

Dept. Of CSE, DSATM 2013-2014 Page 6


Analog Clock

CHAPTER 4
IMPLEMENTATION
The implementation stage of this model involves the following phases.

 Implementation of OpenGL built in functions.


 User defined function Implementation.

4.1 Implementation of OpenGL Built In Functions:

1. glutInit( ):
glutInit is used to initialize the GLUT library.
Usage: void glutInit(int *argcp, char **argv);
Description: glutInit will initialize the GLUT library and negotiate a session with the
window system.

2. 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.
Description: The initial display mode is used when creating top-level windows, sub
windows, and overlays to determine the OpenGL display mode for the to-be-created
window or overlay.

3. glutCreateWindow( ):
glutCreateWindow creates a top-level window.
Usage: int glutCreateWindow(char *name);
Name - ASCII character string for use as window name.
Description: glutCreateWindow creates a top-level window. The name will be provided
to the window system as the window's name. The intent is that the window system will
label the window with the name. Implicitly, the current window is set to the newly
created window. Each created window has a unique associated OpenGL context.
Dept. Of CSE, DSATM 2013-2014 Page 7
Analog Clock

4. glutDisplayFunc( ):
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.
The display callback is called with no parameters. The entire normal plane region should
be redisplayed in response to the callback.

5. glutMainLoop( ):
glutMainLoop enters the GLUT event processing loop.
Usage: void glutMainLoop(void);
Description: 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.

6. glMatrixMode( ):
The two most important matrices are the model-view and projection matrix. At any time,
the state includes values for both of these matrices, which are initially set to identity
matrices. There is only a single set of functions that can be applied to any type of matrix.
Select the matrix to which the operations apply by first set in the matrix mode, a variable
that is set to one type of matrix and is also part of the state.

7. glutTimerFunc();

  glutTimerFunc registers a timer callback to be triggered in a specified number of


milliseconds.

Usage :void glutTimerFunc(unsigned int msecs,void (*func)(int value), value);

Description :glutTimerFunc registers the timer callback func to be triggered in at least


msecs milliseconds. The value parameter to the timer callback will be the value of the
value parameter to glutTimerFunc. Multiple timer callbacks at same or differing times
Dept. Of CSE, DSATM 2013-2014 Page 8
Analog Clock

may be registered simultaneously. The number of milliseconds is a lower bound on the


time before the callback is generated. GLUT attempts to deliver the timer callback as
soon as possible after the expiration of the callback's time interval. There is no support for
canceling a registered callback. Instead, ignore a callback based on its value parameter
when it is triggered.

4.2 Implementation of User Defined Functions:

1. void init(void):
Here the initialization function init() is used to set the OpenGL state variables dealing
with viewing and attributes-parameters that is prefered to set once, independently of the
display function.

2. void Sprint( float x, float y, char *st):


This function is used to print the text on the visualizer window. It takes x and y as pixel
values, which is the point on the screen where the character is required to be printed of
type font. Positioning is achieved through glRasterPos3f(x,y,-1). If string is needed to be
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.

3. static void TimeEvent(int te):

This function is used to rotate the hands (second,minute & hour) as per the angle
specified.

This function uses “glutTimerFunc()” that calls back this function once timer ellapses.

4. void Draw_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.

Dept. Of CSE, DSATM 2013-2014 Page 9


Analog Clock

5. void Draw_clock( GLfloat cx, GLfloat cy, GLfloat cz ):


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 ie; the second hand, minute hand, and hour hand
are drawn using the functions “glRotatef()” to rotate the hands periodically and
“gluCylinder()” wit appropriate parameters to draw the hands of the clock.

6. void num():
This function is to display the numbers(1 to 12) along with its corresponding seconds on
the face of the clock.
This calls the user defined function “Sprint()” with appropriate co-ordinates and numbers.

7. void about():
This function gives the description of the clock on the visualizer window.
This uses the user defined function “Sprint()” to display the characters.

8. void display_clock():
This function basically renders various views of the clock like ortho view and perspective
view depending upon the “if” condition. Depending upon the input given the user defined
function “draw_clock()” and “num()” are called.

9. void main(int argc, 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
with desired properties. After initialization the display function is called with respect to
the window and finally the last statement of this section is the glutMainLoop(). Which is
an event processing function that enters into an infinite loop.

Dept. Of CSE, DSATM 2013-2014 Page 10


Analog Clock

CHAPTER 5
SNAPSHOTS

Fig. 5.1: Ortho view

Dept. Of CSE, DSATM 2013-2014 Page 11


Analog Clock

Fig. 5.2: Perspective view

Dept. Of CSE, DSATM 2013-2014 Page 12


Analog Clock

Fig. 5.3: Gears of the hands

Dept. Of CSE, DSATM 2013-2014 Page 13


Analog Clock

Fig. 5.4: Ortho view at 280 degrees

Dept. Of CSE, DSATM 2013-2014 Page 14


Analog Clock

CHAPTER 6

FUTURE ENHANCEMENT

We have implemented the essential features of the Analog Clock to our best knowledge.
Even still, we would like to enhance the quality and appearance of the clock in the following
ways:

 3D View
 Enhanced appearance
 Lighting and shading
 Implementation of Alarm

CHAPTER 7
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, colour swapping etc.

We thus would like to emphasize of the importance of this project that opened our eyes to
many other perspectives of Technical, mathematical, graphical and software concepts which
we were unaware of.

Thus we thank all Principal, the HOD, the faculty and all our classmates for their continuous
support and belief in us.

Dept. Of CSE, DSATM 2013-2014 Page 15


Analog Clock

CHAPTER 8

REFERENCES

Books:
Interactive Computer Graphics, 5th Edition, Edward Angel
Computer Graphics and Multimedia, Udit Sharma

Websites:
 http://www.amazon.in/Computer-Graphics-Multimedia-Udit-Agarwal/dp/
935014316X?tag=googinhydr18418-21
 http://en.wikipedia.org/wiki/Computer_graphics
 http://stackoverflow.com/questionsquickly
 http://www.opengl-tutorial.org/intermediate-tutorials/

Dept. Of CSE, DSATM 2013-2014 Page 16


Analog Clock

CHAPTER 9
APPENDIX

9.1 User Manual

Right click on the visualizer window, you will be asked for four options
1. About the project
2. Toggle Ortho/Perspective view
3. Light ON/OFF
4. Quit
Depending on the selection the corresponding output will be displayed.
The clock can be viewed in any degrees by changing the degrees in “Draw_clock()”
function.

Make sure that the folder ‘Analog clock’ is copied to the C:\ drive ONLY

9.2 Personal Details

NAME: DHEERAJ JAIN A.H

USN: 1DT11CS009

SEMESTER AND SECTION: 6TH SEM, A SEC

DEPARTMENT: COMPUTER SCIENCE AND ENGINEERING

COLLEGE: DAYANANDA SAGAR ACADEMY OF TECHNOLOGY AND


MANAGEMENT

EMAIL ID: dheerajjainah@gmail.com

Dept. Of CSE, DSATM 2013-2014 Page 17


Analog Clock

NAME: AKSHAY KUMAR TELKAR

USN: 1DT11CS003

SEMESTER AND SECTION: 6TH SEM, A SEC

DEPARTMENT: COMPUTER SCIENCE AND ENGINEERING

COLLEGE: DAYANANDA SAGAR ACADEMY OF TECHNOLOGY AND


MANAGEMENT

EMAIL ID: akshaytelkar@gmail.com

Dept. Of CSE, DSATM 2013-2014 Page 18

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy