0% found this document useful (0 votes)
98 views

CG Final

Computer graphics refers to the representation and manipulation of images using computers, as well as the technologies used to create and manipulate digital images. Interactive computer graphics allows users to create both realistic and abstract images, including mathematical surfaces and data visualizations. Graphics provide a natural way to communicate with computers by leveraging human abilities to rapidly perceive and process visual information.

Uploaded by

Subramani M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
98 views

CG Final

Computer graphics refers to the representation and manipulation of images using computers, as well as the technologies used to create and manipulate digital images. Interactive computer graphics allows users to create both realistic and abstract images, including mathematical surfaces and data visualizations. Graphics provide a natural way to communicate with computers by leveraging human abilities to rapidly perceive and process visual information.

Uploaded by

Subramani M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

Jnana Sangama, Belgaum-590014

A COMPUTER GRAPHICS Project Report


On

“TRAIN STATION”

Submitted in Partial fulfilment of the Requirements for the VI Semester of the Degree of
Bachelor of Engineering
In
Computer Science & Engineering
By
JUDAH A (1CE20CS038)
SUBRAMANI M (1CE20CS073)

Under the Guidance of


Prof. SWETHA A
Asst. Professor, Dept. of CSE

CITY ENGINEERING COLLEGE


Doddakallasandra, Kanakapura Road,
Bengaluru-560061
CITY ENGINEERING COLLEGE
Doddakallasandra, Kanakapura Road, Bengaluru-560061

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CERTIFICATE

Certified that the Computer Graphics Project work entitled “TRAIN STATION” has been
carried out by JUDAH A (1CE20CS038), SUBRAMANI M(1CE20CS073) Bonafede
students of City Engineering College in partial fulfilment for the award of Bachelor of
Engineering in Computer Science and Engineering of the Visveswaraya Technological
University, Belgaum during the year 2022-2023. It is certified that all corrections/suggestions
indicated for Internal Assessment have been incorporated in the Report deposited in the
departmental library. The CG Mini Project Report has been approved as it satisfies the
academic requirements in respect of project work prescribed for the said Degree.

Prof. SWETHA A Dr. SOWMYA NAIK Dr. THIPPESWAMY H .N


Asst.Prof, Dept.of CSE Head, Dept. of CSE Principal

External Viva
Name of the examiners Signature with date
1.

2.
ABSTRACT

Train Station is a newly designed computer graphics mini project. In this mini project, there
will be objects like trains, signals, and a place called “railway station”. There will be a train
in which it will start arriving at the railway station when the signal light “green” is turned on.
It will stop at the railway station when the red light is turned on and the train will not move
from the railway station till the user displays the green light in the traffic signal when the
green light is turned on then the train will start to depart from the railway station. In this
project, there will be night mode and day mode. This is an overview of the project.The train
arrival and departure is a brand new computer graphics mini project developed using the
OpenGL language. The project is a bit difficult to implement since there are lots of objects in
this project a train, railway station, signal light these are the main objects and some more in
the project

i
ACKNOWLEDGEMENT

The completion of the Project brings a sense of satisfaction, but it is never completed without
thanking the persons who are all responsible for its successful completion. First and foremost,
we wish to express our deep sincere feelings of gratitude to our Institution,City Engineering
College, for providing us an opportunity to do our education.

We extend our deepest sense of sincere gratitude to Dr. Thippeswamy H.N, Principal, City
Engineering College, Bengaluru, for having permitted us to carry out the project work on
TRAIN STATION.

We express our heartfelt sincere gratitude to Dr. Sowmya Naik, Professor and Head,
Department of Computer Science and Engineering, City Engineering College, Bengaluru, for
her valuable suggestions and support.

We express my special in-depth, heartfelt, sincere gratitude to Prof. Swetha A, Asst. Prof,
Dept., of CS&E, City Engineering College, Bengaluru for their constant support in
completing the project.

Finally, we would like to thank all the Teaching, Technical faculty and supporting staff
members of Department of Computer Science and Engineering, City Engineering College,
Bengaluru, for their support.

JUDAH A(1CE20CS038)
SUBRAMANI M (1CE20CS073)

ii
TABLE OF CONTENTS
1.Introduction…………………………………………………………………………………01
1.1 About Computer Graphics……………………..…………………………………01
1.2 History of Computer Graphics………………….……………….……………….02
1.3 About OpenGL…………..……………………..………………….…..…………03
1.4 Applications of Computer Graphics…………...…………………….…….……..05
1.5 Built-In Functions……...…………….……………………..…….…...….......….06
1.6 Mouse Functions……………..……….…………..…………..…….…..…..……08
2.Literature Survey……………………………….………………...…..……………..….…..09
3.System Requirement Specification……….……………………….…….….…...………….11
3.1 Hardware Requirements.……………………………….………….....…………..11
3.2 Software Requirements……………………….……………………….………….11
4. System Analysis And Design…..…………………………………………………….……12
4.1 System Analysis….………………..………………………………..…………….12
4.2 System Design.……….………………………………..………………………….12
5.Implementation…………..……………………..…………………………..………………13
5.1 Description of Implementation Modules…………………………..……………..13
5.2 List of Implementation Functions…………...……………………………………13
5.3 Description of inbuilt functions…………..……………….……………..……….14
6.Snapshots…………………….…………………………………………..…………………15
Appendix…………………………………………………………………..………………….19
Conclusion…………………………...………………………….……………………………25
Future scope………….……...……………………………….……………………………….25
References…………………….………………………………..……………………………..26

iii
LIST OF FIGURES

FIGURE NO. FIGURE NAME PAGE NO.

1.1 Library Organisation 4

6.1 Railway Station at day time 15

6.2 Railway Station at night time 15

6.3 Train arriving at Railway Station 16

6.4 Train stopped at Railway Station 16

6.5 Train leaving the Railway Station 17

6.6 Comet flying across the night sky 17

6.7 Aeroplane flying across the sky 18

6.8 Menu for Aeroplane and Comet 18

iv
CHAPTER 1
INTRODUCTION
1.1 About Computer Graphics
The term computer graphics has been used in a broad sense to describe almost everything on
computers that is not text or sound. Typically, the term computer graphics refers to several
different things:
• The representation and manipulation of image data by a computer
• The various technologies used to create and manipulate images
• The sub-field of Computer Science which studies methods for digitally synthesising and
manipulating visual content.

Today, computer graphics are widespread. Such imagery is found in and on television,
newspapers, weather reports, and in a variety of medical investigations and surgical
procedures. A well-constructed graph can present complex statistics in a form that is easier to
understand and interpret. In the media such graphs are used to illustrate papers, reports and
other presentation material. 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, and polygons and so on. Interactive picture construction
techniques such as basic positioning methods, rubber-band methods, dragging and drawing
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 provides one of the most natural means of communicating with a computer, since
our highly developed 2D Or 3D pattern-recognition abilities allow us to perceive and process
pictorial data rapidly. Computers have become a powerful medium for the rapid and

economical production of pictures. Graphics provide a natural means of communicating with


the computer that they have become widespread. Interactive graphics is the most important

Dept., of CSE, CEC 2022-23 1


means of producing pictures since the invention of photography and television. We can make
pictures of not only the real-world objects but also of abstract objects such as mathematical
surfaces on 4D and of data that have no inherent geometry. 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, processor, memory, frame buffer and output
devices

There are different types of Graphics architectures which are:


• Display processors: The earliest attempts to build special purpose graphics systems were
concerned primarily with relieving the general-purpose computer from the task of refreshing
the display continuously. These display processors had conventional architecture but included
instructions to display primitives on the CRT.

• Pipeline architectures: The availability of inexpensive solid-state memory led to the


universality of raster display. For computer graphics applications, the most important use of
custom VLSI circuits has been in creating pipeline architectures.

• Graphics pipeline: Each object comprises a set of graphical primitives. Each primitive
comprises a set of vertices.

• Vertex processing: The assignment of vertex colour scan is as simple as program specifying
a colour or as complex as computation of a colour from a physically realistic lightning model
that incorporates the surface properties of the object and the characteristic light sources in the
scene.

• Clipping and primitive assembly: We must do clipping because of the limitations of that
no imaging system can see the whole world at once. The human retina has a limited size
corresponding to an approximately 90-degree field of view.

1.2 History of Computer Graphics


William Fetter was credited with coining the term Computer Graphics in 1960, to describe his
work at Boeing. One of the first displays of computer animation was future world (1976),
which included an animation of a human face and was hand-produced by Carmel and Fred
Parel at the University of Utah. There are several international conferences and journals
where the most significant results in computer graphics are published, among them are the

Dept., of CSE, CEC 2022-23 2


SIGGRAPH and Euro graphics conferences and the association for computing machinery
(ACM) transaction on graphics journals.

1.3 About OpenGL


OpenGL (open graphics library) is a standard specification defining a cross language cross
platform API for writing applications that produce 2D and 3D computer graphics. The
interface consists of over 250 different function calls which can be used to draw complex 3D
scenes from simple primitives. OpenGL was developed by silicon graphics Inc.(SGI) in 1992
and is widely used in CAD ,virtual reality , scientific visualisation , information visualisation
and flight simulation. It is also used in video games, where it competes with direct 3D on
Microsoft Windows platforms. OpenGL is managed by the non-profit technology consortium,
the khronos group, Inc. OpenGL serves two main purposes:
• To hide the complexities of interfacing with different 3D accelerators, by presenting
programmers with a single, uniform API.
• To hide the differing capabilities of hardware platforms, by requiring that all
Implementations support the full OpenGL feature set.

OpenGL has historically been influential on the development of 3D accelerator, promoting a


base level of functionality that is now common in consumer level hardware:

• Rasterized points, lines and polygons are basic primitives.


• A transform and lighting pipeline.
• Z buffering.
• Texture Mapping.
• Alpha.
• Blending.
OpenGL is the premier environment for developing portable, interactive 2D and 3D graphics
applications. Since its introduction in 1992, OpenGL has become the industry's most widely
used and supported 2D and 3D graphics application programming interface (API), bringing
thousands of applications to a wide variety of computer platforms. OpenGL fosters innovation
and speeds application development by incorporating a broad set of rendering, texture
mapping, special effects, and other powerful visualisation functions. Developers can leverage

Dept., of CSE, CEC 2022-23 3


the power of OpenGL across all popular desktop and workstation platforms, ensuring wide
application deployment.

OpenGL Available Everywhere: Supported on all UNIX® workstations, and shipped standard
with every Windows 95/98/2000/NT and Mac OS PC, no other graphics API operates on a
wider range of hardware platforms and software environments. OpenGL runs on every major
operating system including Mac OS, OS/2, UNIX, Windows 95/98, Windows 2000, Windows
NT, Linux, Open Step, and BeOS; it also works with every major windowing system,
including Win32, Mac OS, Presentation Manager, and X-Window System. OpenGL is
callable from Ada, C, C++, FORTRAN, Python, Perl and Java and offers complete
independence from network protocols and topologies. The OpenGL interface: Our application
will be designed to access OpenGL directly through functions in three libraries namely-

❖ GL
❖ GLU
❖ Glut

Fig 1.1 Library Organisation

Dept., of CSE, CEC 2022-23 4


1.4 Applications of Computer Graphics
(1) Video games:
➢ These games require human interaction with theUserInterfaceformakingnice visual result
on the Video Device
(2) Education Field:
➢ In the learning process, acquiring knowledge and skills required for better career path CG
is needed. So Computer generated models in economic, financial and physical systems are
often used.
➢ We regularly love to have computerised model to understand any topic easily. Equipment,
Physiological systems, physical systems are coded using CG.
(3) Computer Aided Design (CAD):
➢ Most of engineering and Architecture students are concerned with Design. CAD is used to
design various structures such as Computers, Aircrafts, Building, in almost all kinds of
Industries (where designing is necessary)
➢ After making a full diagram, we can even see its animation (Operation and working of a
Product)
(4) Computer Arts:
➢ If we are intelligent enough, we can rock by making creative arts using these Graphics
tools. For making these arts we generally use CAD packages, paint and Paint brush programs
and in animation too
➢ Computer Arts Examples include Logo design (for companies, college, Industries,
Institutions), Cartoon drawing, Product advertisements and many.
(5) Simulation:
➢ Using CG graphics reproduction or duplicating already existing thing will be done. For
Instance, if we go for the Flight simulators, these computer-generated images are very much
needed for training pilots to understand easily (learning standard methods)
(6) Entertainment:
➢ When we talk about Entertainment, immediately movies and games get in to picture.CG
are mostly used in music videos, motion pictures, cartoon animation films. For finding out
tricks to be used in Games, for its interactivity we often use CG
(7) Image Processing: (Medical)
➢ In Medical field, concerning Image Processing CG is used to various technologies to
interpret already existing pictures and is useful to modify Photographs and TV scans.

Dept., of CSE, CEC 2022-23 5


Basically, CG is used to improve the picture quality, and visualising effects. Some of its
applications includes
i). Tomography
ii). Ultrasonic medical scanners
iii). Picture enhancements
(8) User Interfaces (Graphical User Interfaces):
❖ CG is effectively used to make Menus, Icons (Graphical Symbols),to make window
manager(multiple windows).And Some of the Graphic packages include PHIGS, Graphics
Kernel System, Painting and drawing.
Some of the other applications are: -
➢ Scientific and Business Visualization
➢ Graphic Presentation
➢ Graphic Design
➢ Web Designing
➢ Computational Physics
➢ Information Visualization
➢ Display of Information
➢ Information Architecture
➢ Genetics, Molecular Biology, Neuroscience, Animation, Statistics
➢ Desktop Publishing.

1.5 Built-In Functions

(1) glColor3f (float, float, float):-


This function will set the current drawing colour.

(2) gluOrtho2D (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top):-
Which defines a two-dimensional viewing rectangle in the plane z=0.

(3) glClear ( ):-


Takes a single argument that is the bitwise OR of several values indicating which buffer is to
be cleared.

(4) glClearColor ():-


Specifies the red, green, blue, and alpha values used by glClear to clear the colour buffers.

Dept., of CSE, CEC 2022-23 6


(5) glLoadIdentity ( ):-
Sets the current matrix to an identity matrix.

(6) glMatrixMode (mode):-


Sets the current matrix mode, mode can be GL_MODELVIEW, GL_PROJECTION or
GL_TEXTURE.

(7) glutInit (int *argc, char**argv):-


Initialises GLUT, the arguments from main are passed in and can be used by the application.

(8) glutInitDisplayMode (unsigned int mode):-


Request a display with the properties in mode. The value of mode is determined by the logical
OR of options including the colour model and buffering.

(9) glutInitWindowSize (int width, int height):-


Specifies the initial position of the top-left corner of the window in pixels

(10) glutCreateWindow (char *title):-


A window on the display. The string title can be used to label the window. The return value
provides references to the window that can be used when there are multiple windows.

(11) glutMouseFunc(void *f(int button, int state, int x, int y):-


Register the mouse callback function f. The callback function returns the button, the state of
the button after the event and the position of the mouse relative to the top-left corner of the
window.

(12) Void glutKeyboardFunc(void(*func) (void)):-


This function is called every time when you press enter key to resume the game or when you
press ‘b’ or ‘B’ key to go back to the initial screen or when you press esc key to exit from the
application.

(13)glutDisplayFunc (void (*func) (void)):-


Register the display function that is executed when the window needs to be redrawn.

(14) glutSpecialFunc(void(*func)( void)):-


This function is called when you press the special keys in the keyboard like arrow keys,
function keys etc. In our program, the function is invoked when the up arrow or down arrow

Dept., of CSE, CEC 2022-23 7


key is pressed for selecting the options in the main menu and when the left or right arrow key
is pressed for moving the object(car) accordingly.

(15) glut PostReDisplay ( ) :-


Which requests that the display callback be executed after the current callback returns.

(16) Void MouseFunc (void (*func) void)):-


This function is invoked when mouse keys are pressed. This function is used as an alternative
to the previous function i.e., it is used to move the object(car) to right or left in our program
by clicking the left and right button respectively.

(17) glutMainLoop() :-
Cause the program to enter an event-processing loop. It should be the last statement in the
main function.
1.6 Mouse Functions
Right button: controls the below options.
➢ Airplane option: makes a plane fly actress the sky.
➢ Comet option: makes a comet fly across the sky.

Dept., of CSE, CEC 2022-23 8


CHAPTER 2
LITERATURE SURVEY

➢ Computer graphics started with the display of data on hardcopy plotters and cathode ray
tube (CRT) screens soon after the introduction of computers.
➢ Computer graphics today largely interactive, the user controls the contents, structure, and
appearance of objects and of displayed images by using input devices, such as keyboard
mouse, or touch-sensitive panel on the screen. Graphics based user interfaces allow millions
of new users to control simple, low- cost application programs, such as spreadsheets, word
processors, and drawing programs.
➢ OpenGL (Open Graphics Library) is a standard specification defining a cross-language,
cross platform API for writing applications that produce 2D and 3D computer graphics. The
interface consists of over 250 different function calls which can be used to draw complex
three-dimensional scenes from simple primitives. OpenGL was developed by Silicon
Graphics Inc. (SGI) in 1992 and is widely used in CAD, virtual reality, scientific
visualisation, information visualisation, and flight simulation. It is also used in video games,
where it competes with Direct3D on Microsoft Windows platforms (see Direct3D vs.
OpenGL). OpenGL is managed by the non-profit technology consortium, the Khronos Group.
➢ In the 1980s, developing software that could function with a wide range of graphics
hardware was a real challenge. By the early 1990s, Silicon Graphics (SGI) was a leader in 3D
graphics for workstations. SGI's competitors (including Sun Microsystems, Hewlett- Packard
and IBM) were also able. In addition, SGI had a large number of software customers; by
changing to the OpenGL API they planned to keep their customers locked onto SGI (and
IBM) hardware for a few years while market support for OpenGL matured to bring to market
3D hardware, supported by extensions made to the PHIGS standard. In 1992, SGI led the
creation of the OpenGL architectural review board (OpenGL ARB), the group of companies
that would maintain.
➢ OpenGL specification took for years to come. On 17 December 1997, Microsoft and SGI
initiated the Fahrenheit project, which was a joint effort with the goal of unifying the OpenGL
and Direct3D interfaces(and adding a scene-graph API too). In 1998 Hewlett- Packard joined
the project. It initially showed some promise of bringing order to the world of interactive 3D
computer graphics APIs, but on account of financial constraints at SGI, strategic reasons at
Microsoft, and general lack of industry support, it was abandoned in 1999.

Dept., of CSE, CEC 2022-23 9


➢ Many openGL functions are used for rendering and transformation purposes.
Transformation functions like glRotatef (), glTranslate (), glScaled () can be used.
➢ OpenGL provides a powerful but primitive set of rendering command, and all higher-level
drawing must be done in terms of these commands. There are several libraries that allow you
to simplify your programming tasks, including the following:
➢ 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 and rendering surfaces.
➢ OpenGL Utility Toolkit (GLUT) is a window-system-independent toolkit, written by Mark
Kill guard, to hide the complexities of differing window APIs.
➢ To achieve the objective of the project, information related to the light sources is required
with OpenGL we can manipulate the lighting and objects in a scene to create many different
kinds of effects. It explains how to control the lighting in a scene, discusses the OpenGL
conceptual model of lighting, and describes in detail how to set the numerous illumination
parameters to achieve certain effects and this concept is being obtained.
➢ To demonstrate the transformation and lighting, effects, different polygons have to be used.
Polygons are typically drawn by filling in all the pixels enclosed within the boundary, but we
can also draw them as outlined polygons or simply as points at the vertices. This concept is
obtained from.
➢ The properties of a light source like its material, diffuse, emissive, has to mention in the
project. So to design the light source and the objects, a programming guide of an OpenGL is
used.

Dept., of CSE, CEC 2022-23 10


CHAPTER 3
SYSTEM REQUIREMENT SPECIFICATION

3.1 Hardware Requirements


Minimum hardware specification:
➢ Processor: Intel® Pentium® CPU
➢ Memory: 32MB RAM.
➢ Hard Disk: 20GB Hard disk
➢ Interface Device: Mouse, Keyboard, Monitor of Resolution 1920X1080

3.2 Software Requirements:


Minimum software specification:
➢ Operating system: Ubuntu / Windows (10/11)
➢ Programming language:C++
➢ Compiler: Eclipse idle
➢ OpenGL library
➢ Graphics Driver
➢Mouse Driver
➢ Tool Used: OpenGL

Dept., of CSE, CEC 2022-23 11


CHAPTER 4
SYSTEM ANALYSIS AND DESIGN

4.1 System Analysis


In this project we are mainly concentrating on using the keyboard .
❖ Start-up: Click on ‘any key’ and hit ‘enter’ to start the project .
❖ Press 'r' or 'R' to change the signal light to red.
❖ Press 'g' or 'G' to change the signal light to green.
❖ Press 'd' or 'D' to make it a day.
❖ Press 'n' or 'N' to make it night.
❖ Press 't' or 'T' Train arrives at station.
❖ Press RIGHT MOUSE BUTTON to display the menu.
❖ Press LEFT MOUSE BUTTON to quit the program.

4.2 System Design


The main function calls the following functions:
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(1100.0,700.0);
glutInitWindowPosition(0,0);
glutCreateWindow("Traffic Control");
glutDisplayFunc(display);
glutIdleFunc(idle);
glutKeyboardFunc(keyboardFunc);
glutMouseFunc(mouse);
myinit();
c_menu=glutCreateMenu(main_menu);
glutAddMenuEntry("Aeroplane",1);
glutAddMenuEntry("Comet",2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();

Dept., of CSE, CEC 2022-23 12


CHAPTER 5
IMPLEMENTATION

5.1 Description of Implementation Modules

In this project a thirsty crow is created using “OpenGL” functional API by the help of built in
functions present in the Opengl lib. These functions provide us with an efficient way to design
the project. In this chapter we are describing the functionality of our project using these
functions, such as Opengl translation and other geometric transformations.

5.2 List of Implementation Functions


User Defined Functions
void keyboardFunc( unsigned char key ,int x ,int y ):
This function is used to add the keyboard listener in an OpenGL.
Void mouse(int btn,int state,int x,int y):
This function is used to add the mouse listener in an OpenGl.
void myinit(void):
This function initialises OpenGL’s rendering modes.
void display(void):
This function handles the animation and the redrawing of the graphics window
contents.
int main(int argc, char ** argv):
The program begins execution from this function.
void traffic_light():
This function is used to set the traffic signal to red and green through keyboard inputs.
void draw_object():
This function is used to draw the trees, sky, sun, moon, plane, clouds, grass, stars,
comet, tracks, platform, train, railway station.
void idle():
This function is used to perform actions when the signal turns red or green and to
show the comet and plane fly when the option is selected from the menu.

Dept., of CSE, CEC 2022-23 13


5.3 Description of inbuilt functions
main():

The execution of the program starts from the main().

glutInit():

Initialises GLUT. The arguments from main are passed in and can be used by the application.

glutInitWindowSize():

Specifies the initial height and width of the window in pixels.

glutCreateWindow():

Creates the window on the display. The string can be used to label the window.

glutDisplayFunc():

Registers the display function that is executed when the window needs to redraw.

glutMainLoop():

Causes the program to enter an event processing loop.

myinit():

This function is defined to initialise the window parameters.

Dept., of CSE, CEC 2022-23 14


CHAPTER 6
SNAPSHOTS
Fig 6.1 Shows Railway Station when ‘d’ or ‘D’ is pressed

Fig 6.1 Railway Station at day time

Fig 6.2 Shows Railway Station when ‘n’ or ‘N’ is pressed

Fig 6.2 Railway Station at night time

Dept., of CSE, CEC 2022-23 15


Fig 6.3 Shows arrival of train when ‘t’ or ‘T’ is pressed

Fig 6.3 Train arriving at Railway Station

Fig 6.4 Shows train stopping after ‘r’ or ‘R’ is pressed

Fig 6.4 Train Stopped at Railway Station

Dept., of CSE, CEC 2022-23 16


Fig 6.5 Shows train leaving after ‘g’ or ‘G’ is pressed

Fig 6.5 Train leaving Railway Station

Fig 6.6 Shows a comet flying after selection from the menu

Fig 6.6 Comet Flying across the night sky

Dept., of CSE, CEC 2022-23 17


Fig 6.7 Shows aeroplane fly after selection from the menu

Fig 6.7 Aeroplane flying across the sky

Fig 6.8 Shows the menu after right mouse button is clicked

Fig 6.8 Menu for Aeroplane and Comet

Dept., of CSE, CEC 2022-23 18


APPENDIX
Pseudo code
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(0.0,0.0,1.0);
glPointSize(2.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,1100.0,0.0,700.0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
draw_object();
traffic_light();
glFlush();
}
void main_menu(int index)
{
switch(index)
{
case 1:
if(index==1)
{
plane=1; o=n=0.0;
}
break;

case 2:
if(index==2)
{
comet=1; c=0.0;
}
break;
}
}
void mouse(int btn,int state,int x,int y)
{
if(btn==GLUT_LEFT_BUTTON && state==GLUT_UP)exit(0);
}

Dept., of CSE, CEC 2022-23 19


void keyboardFunc( unsigned char key, int x, int y )
{
switch( key )
{
case 'g':
case 'G':
light=1;
break;
case 'r':
case 'R':
light=0;
break;
case 'd':
case 'D':
day=1;
break;
case 'n':
case 'N':
day=0;
break;
case 't':
case 'T':
train=1;
i=0;
break;
};
}
void idle()
{
glClearColor(1.0,1.0,1.0,1.0);

if(light==0 && (i>=0 && i<=1150))


{
i+=SPEED/10;
m+=SPEED/150;
n-=2;
o+=0.2;
c+=2;
}
if(light==0 && (i>=2600 && i<=3000))
{
i+=SPEED/10;
m+=SPEED/150;
Dept., of CSE, CEC 2022-23 20
n-=2;
o+=0.2;
c+=2;
}
if(light==0)
{
i=i;
m+=SPEED/150;
n-=2;
o+=0.2;
c+=2;
}
else
{
i+=SPEED/10;
m+=SPEED/150;
n-=2;
o+=0.2;
c+=2;
}
if(i>3500)
i=0.0;
if(m>1100)
m=0.0;
if( o>75)
{
plane=0;
}
if(c>500)
{
comet=0;
}
glutPostRedisplay();
}
void traffic_light()
{
int l;
if(light==1)
{
for(l=0;l<=20;l++)
{
glColor3f(0.0,0.0,0.0);
draw_circle(1065,475,l);
Dept., of CSE, CEC 2022-23 21
glColor3f(0.0,0.7,0.0);
draw_circle(1065,375,l);
}
}
else
{
for(l=0;l<=20;l++)
{
glColor3f(1.0,0.0,0.0);
draw_circle(1065,475,l);
glColor3f(0.0,0.0,0.0);
draw_circle(1065,375,l);
}
}
}
//plane at day
if(plane==1)
{
glColor3f(1.0,1.0,1.0);
glBegin(GL_POLYGON);
glVertex2f(925+n,625+o);
glVertex2f(950+n,640+o);
glVertex2f(1015+n,640+o);
glVertex2f(1030+n,650+o);
glVertex2f(1050+n,650+o);
glVertex2f(1010+n,625+o);
glEnd();
glColor3f(0.8,0.8,0.8);
glBegin(GL_LINE_LOOP);
glVertex2f(925+n,625+o);
glVertex2f(950+n,640+o);
glVertex2f(1015+n,640+o);
glVertex2f(1030+n,650+o);
glVertex2f(1050+n,650+o);
glVertex2f(1010+n,625+o);
glEnd();
}
//comet at night sky
if(comet==1)
{
for(l=0;l<=7;l++)
{
glColor3f(1.0,1.0,1.0);
Dept., of CSE, CEC 2022-23 22
draw_circle(300+c,675,l);
}
glColor3f(1.0,1.0,1.0);
glBegin(GL_TRIANGLES);
glVertex2f(200+c,675);
glVertex2f(300+c,682);
glVertex2f(300+c,668);
glEnd();
}
//Plane at night sky
if(plane==1)
{
for(l=0;l<=1;l++)
{
glColor3f(1.0,0.0,0.0);
draw_circle(950+n,625+o,l);
glColor3f(1.0,1.0,0.0);
draw_circle(954+n,623+o,l);
}
}

int main(int argc,char ** argv)


{
int c_menu;
printf("Project by CSEMiniProjects.com\n");
printf("--------------------------------------------------------------------------------");
printf(" ARRIVAL AND DEPARTURE OF TRAIN ");
printf("--------------------------------------------------------------------------------");
printf("Press 'r' or 'R' to change the signal light to red. \n\n");
printf("Press 'g' or 'G' to change the signal light to green. \n\n");
printf("Press 'd' or 'D' to make it day. \n\n");
printf("Press 'n' or 'N' to make it night. \n\n");
printf("Press 't' or 'T' Train arrive at station.\n\n");
printf("Press RIGHT MOUSE BUTTON to display menu. \n\n");
printf("Press LEFT MOUSE BUTTON to quit the program. \n\n\n");
printf("Press any key and Hit ENTER.\n");
scanf("%s",&ch);

glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(1100.0,700.0);
glutInitWindowPosition(0,0);
glutCreateWindow("Traffic Control");
glutDisplayFunc(display);
Dept., of CSE, CEC 2022-23 23
glutIdleFunc(idle);
glutKeyboardFunc(keyboardFunc);
glutMouseFunc(mouse);
myinit();
c_menu=glutCreateMenu(main_menu);
glutAddMenuEntry("Aeroplane",1);
glutAddMenuEntry("Comet",2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
return 0;
}

Dept., of CSE, CEC 2022-23 24


CONCLUSION AND FUTURE SCOPE

Conclusion:
OpenGL software was used to develop the “INTERACTION BETWEEN LAYERS OF OSI
MODEL” project which provided various commands to specify objects and operations in
two-dimensional space. The very purpose of developing this project is to exploit the strength
of OpenGL graphic capabilities and to illustrate the character movement.

This project helped me learn a lot about the proper utilisation of various graphics library
functions that are defined in GLUT, GLU and GL. The package can be used for educational
purposes to demonstrate the various curves, area filling algorithm, non-convex polygon and
other OpenGL Primitives.

In this project, there are two modes in it namely day mode and night mode. To make it day
mode and night mode and to display the signal light to train the controls will be provided
from the keyboard and mouse.

When the train approaches the station then the red signal will be displayed then the train will
stop at the railway station and then after displaying the green light, the train will depart from
the station.

Future scope:
The following features were thought of and will be implemented to enhance the project.

➢ More interactive feature addition.

➢ Hardware interface inclusion.

➢ Using an openGL framework

➢ More realistic and advanced graphics can be implemented.

➢ Frame rate can be increased to look more natural.

Dept., of CSE, CEC 2022-23 25


REFERENCES

1. https://timetoprogram.com/train-arrival-departure-cg-mini-project

2. Interactive Computer Graphics A Top-Down Approach with OpenGL - EdwardAngel,


5th

3. Edition, Addison-Wesley, 2008

4. The Official Guide to Learning OpenGL, by Jackie Neider, Tom Davis, Mason Woo
(THE REDBOOK)

5. OpenGL Super Bible by Richard S. Wright, Jr. and MichaelSweet5.

http://www.cs.rutgers.edu/~decarlo/428/glman.html online man pages.

6. OpenGL tutorials http://www.nptel.com

Dept., of CSE, CEC 2022-23 26


DECLARATION

We students of 6th semester BE, Computer Science and Engineering College hereby declare
that project work entitled “Train Station” has been carried out by us at City Engineering
College, Bengaluru and submitted in partial fulfillment of the course requirement for the
award of the degree of Bachelor of Engineering in Computer Science and Engineering of
Visvesvaraya Technological University, Belgaum, during the academic year 2022-2023.

We also declare that, to the best of our knowledge and belief, the work reported here does not
form the part of dissertation on the basis of which a degree or award was conferred on an
earlier occasion on this by any other student.

Date:

Place: Bangalore

JUDAH A SUBRAMANI M

(1CE20CS038) (1CE20CS073)

You might also like