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

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

“JNANA SANGAMA”, BELAGAVI, KARNATAKA, INDIA-590018

A Mini Project Synopsis on


“TRAFFIC SIGNAL SIMULATOR”

For the requirement of 6th Semester B.E in Computer Science & Engineering
For the award of degree of
BACHELOR OF ENGINEERING
IN
COMPUTER SCIENCE AND ENGINEERING

Submitted by
VAMSHA ATTAVAR(1KT20CS090)
VAISHNAVI P GAVADE(1KT20CS089)

Under the guidance of:

Internal Guide Head of the Department


Mr. Lokesh H D Dr. Shantharam Nayak
Assistant Professor Professor & Head
Dept. of CSE, SKIT Dept. of CSE, SKIT

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SRI KRISHNA INSTITUTE OF TECHNOLOGY
Bengaluru-560090
2022-2023
SRI KRISHNA INSTITUTE OF TECHNOLOGY
Hesaraghatta Main Road Bengaluru-560090
Department of Computer Science &Engineering

CERTIFICATE

Certified that the mini project work prescribed in 18CSMP68 entitled “ TRAFFIC SIGNAL
SIMULATOR” carried out by VAMSHA ATTAVAR(1KT20CS090), VAISHNAVI P GAVADE
(1KT20CS089), bonafide students of Sri Krishna Institute of Technology, Bengaluru in partial
fulfilment of the award of Bachelor of Engineering in Computer Science and Engineering of the
Visvesvaraya Technological University, Belagavi during the year 2021-22. It is certified that all
corrections /suggestions indicated for Internal Assessment have been incorporated in the report deposited
in the departmental library. The mini-project report has been approved as it satisfies the academic
requirements with respect to project work prescribed for the said Degree.

………………………… ………………………… ………………………


Signature of the Guide Signature of the HOD Signature of the Principal

Mr. Lokesh H D Dr. Shantharam Nayak Dr. Mahesha K


Assistant professor Professor & HOD Principal
Dept of CSE, SKIT Dept of CSE, SKIT SKIT, Bengaluru

EXTERNAL

Name of Examiner Signature with date

1. ………………………… ………………………

2. ………………………… ………………………
ACKNOWLEDGEMENT

We consider special privilege to express a few words of gratitude and respect to all those
who have guided and inspired us in completing the Mini Project report. The success of the
Mini Project depends largely on the encouragement and guidance of many other. We take this
opportunity to express our gratitude our gratitude to the people who have been instrument in
successful completion of the Mini Project.

We would like to profoundly thank the Management of Sri Krishna Institute of Technology
[SKIT] for providing such a working environment for successful completion of the Mini Project.

We express our sincere thanks to Dr. Mahesha K, Principal of Sri Krishna Institute of
technology, for his courteous comments and valuable suggestions, which enabled the
successful completion of the Mini Project.

We express our gratitude to Dr. Shantharam Nayak, Head of the Department of Computer
Science and Engineering, for his constant support, kind guidance and encouragement.

We express our gratitude to Mr. Lokesh H D, Asst. Professor, Department of Computer


Science and Engineering who inspired using taking up this technical seminar topic.

VAMSHA ATTAVAR(1KT20CS090)
VAISHNAVI P GAVADE(1KT20CS089)

i
ABSTRACT
The Graphics package is aimed at supporting the requirements of the Computer Graphics using
OpenGL functions. The project has been implemented under the Windows environment using
the Microsoft Visual C++ platform, OpenGL and associated functionalities of GLUT (Graphics
Library Utility Toolkit).
Main aim of this Mini Project is to illustrate the concepts and usage of pre-built functions in
OpenGL. Simulation of a traffic signal is being done using computer graphics. The car built
using cubes can be moved using arrow keys and based on traffic signal light the user can obey
the traffic rules. If the car hits other car then accident scene is shown. We have used input
devices like mouse and key board to interact with program .

VAMSHA ATTAVAR (1KT20CS090)


VAISHNAVI P GAVADE (1KT20CS089)

ii
TABLE OF CONTENTS PAGE NO

1. INTRODUCTION

1.1 INTRODUCTION TO COMPUTER GRAPHICS 1

1.2 INTRODUCTION TO OPENGL 2

2. REQUIREMENTS SPECIFICATION

2.1 SOFTWARE REQUIREMENTS 4

2.2 HARDWARE REQUIREMENTS 4

3. SYSTEM DEFINITION

3.1 PROJECT DESCRIPTION 5

3.2 USER DEFINED FUNCTION 5

3.3 DATA FLOW DIAGRAM 7

4. IMPLEMENTATION

4.1 SOURCE CODE 8

5. TESTING AND RESULTS

5.1 DIFFERENT TYPES OF TESTING 22

5.2 TEST CASES 23

6. SNAPSHOTS 24

CONCLUSION & FUTURE SCOPE 26

BIBILOGRAPHY 27
V
(
v
TRAFFIC SIGNAL

CHAPTER 1

INTRODUCTION

1.1 INTRODUCTION TO COMPUTER GRAPHICS


Computer Graphics is concerned with all aspects of producing pictures or images using a
computer. Graphics provides one of the most natural means of communicating within a computer,
since our highly developed 2D and 3D pattern-recognition abilities allow us to perceive and process
pictorial data rapidly and effectively. Interactive computer graphics is the most important means of
producing pictures since the invention of photography and television.

Applications of Computer Graphics


1. Display of information
2. Design
3. Simulation and animation
4. User interfaces

The Graphics Architecture


Graphics Architecture can be made up of seven components:
1. Display processors
2. Pipeline architectures
3. The graphics pipeline
4. Vertex processing
5. Clipping and primitive assembly
6. Rasterization
7. Fragment processing

Dept of CSE, 2022- Page


TRAFFIC SIGNAL

Input

Output
Processor Frame buffer
Device device

Memory
Mouse

Figure 1.1: Components of Graphics Architecture and their


working

1.2 INTRODUCTION TO OPENGL


OpenGL is software used to implement computer graphics. The structure of OpenGL is
similar to that of most modern APIs including Java 3D and DirectX. OpenGL is easy to learn,
compared with other.
APIs are nevertheless powerful. It supports the simple 2D and 3D programs. It also supports the
advanced rendering techniques. OpenGL API explains following 3 components
1. Graphics functions
2. Graphics pipeline and state machines
3. The OpenGL interfaces
There are so many polygon types in OpenGL like triangles, quadrilaterals, strips and fans. There
are 2 control functions, which will explain OpenGL through,
1. Interaction with window system
2. Aspect ratio and view ports

Dept of CSE, 2022- Page


TRAFFIC SIGNAL

GLU

GL
OpenGL Frame Buffer
OpenGL Application
Applicatio Program
n program
GLUT Xlib, Xtk

GLX

Figure 1.2: OpenGL Library organization

Most implementations of OpenGL have a similar order of operations, a series of processing


stages called the OpenGL rendering pipeline. This ordering, as shown in Figure 1.2, is not a strict
rule of how OpenGL is implemented but provides a reliable guide for predicting what OpenGL will
do. The following diagram shows the assembly line approach, which OpenGL takes to process data.
Geometric data (vertices, lines, and polygons) follow the path through the row of boxes that
includes evaluators and per-vertex operations, while pixel data (pixels, images, and bitmaps) are
treated differently for part of the process. Both types of data undergo the same final steps
(Rasterization and per-fragment operations) before the final pixel data is written into the frame
buffer.

Pre vertex operations and


primitive assembly
Vertex data Evaluators

Display
list
Rasterization Per-fragment operation

Pixel operation Texture Frame buffer


assembly
Pixel data

Figure 1.3: OpenGL Order of Operations

Dept of CSE, 2022- Page


TRAFFIC SIGNAL

CHAPTER 2
REQUIREMENTS SPECIFICATION

2.1 SOFTWARE REQUIREMENTS


• Operating system – Windows 10
• Microsoft Visual Studio 2017
• OPENGL library files – GL, GLU, GLUT
• Language used is C/C++

2.2 HARDWARE REQUIREMENTS


• Processor – Pentium Pro
• Memory - 128MB RAM
• 20GB Hard Disk Drive
• Mouse or other pointing device
• Keyboard
• Display device

Dept of CSE, 2022- Page


TRAFFIC SIGNAL

CHAPTER 3
SYSTEM DEFINITION

3.1 PROJECT DESCRIPTION


A traffic signal is used as an instructing device that indicates the road user to act according to the
displayed sign. Following the traffic signal ensures road safety and to make things simple to understand,
these signals have been using a universal colour code. Traffic lights or traffic signals are signalling
devices positioned at road intersections, pedestrian crossings, and other locations to control flows of
traffic.

3.2 USER DEFINED FUNCTIONS

➢ glutInit() : interaction between the windowing system and OPENGL is initiated

➢ glutInitDisplayMode() : used when double buffering is required and depth information


is required

➢ glutCreateWindow() : this opens the OPENGL window and displays the title at top of
the window

➢ glutInitWindowSize() : specifies the size of the window

➢ glutInitWindowPosition() : specifies the position of the window in screen co-ordinates

➢ glutKeyboardFunc() : handles normal ascii symbols

➢ glutSpecialFunc() : handles special keyboard keys

➢ glutReshapeFunc() : sets up the callback function for reshaping the window

➢ glutIdleFunc() : this handles the processing of the background

➢ glutDisplayFunc() : this handles redrawing of the window

➢ glutMainLoop() : this starts the main loop, it never returns

Dept of CSE, 2022- 5


TRAFFIC SIGNAL

➢ glViewport() : used to set up the viewport

➢ glVertex3fv() : used to set up the points or vertices in three dimensions

➢ glColor3fv() : used to render color to faces

➢ glFlush() : used to flush the pipeline

➢ glutPostRedisplay() : used to trigger an automatic redrawal of the object

➢ glMatrixMode() : used to set up the required mode of the matrix

➢ glLoadIdentity() : used to load or initialize to the identity matrix

➢ glTranslatef() : used to translate or move the rotation centre from one point to another
in three dimensions

➢ glRotatef() : used to rotate an object through a specified rotation angle

Dept of CSE, 2022- 6


TRAFFIC SIGNAL

3.3 DATA FLOW DIAGRAM

Figure 3.3: Data and Control Flow

The project starts its execution from the main() function, which in turn calls a function called
display_about() . This function shows an overview of the information about the software. On the screen
mouse and keyboard inputs can be used to execute all the features of this system. The various functions that
can be called from this screen are: display_nuclear_power_plant(), display_operations(), reactions(). Once
any of the above are executed the display_about() is called back or we can quit the window.

Dept of CSE, 2022- 7


TRAFFIC SIGNAL

CHAPTER 4
IMPLEMENTATION

4.1 SOURCE CODE

#include<stdio.h>
#include<gl/glut.h>
void bus();
void road();
void signal();
void car();
void car2();
void bus2();
void mydisplay();
void display();
void frontsreen();
void drawstring();
void setFont();
void myMouse();
void update();
void control();
void helpscreen();
GLint a = 300, b = -300, flag = 0, traffic_regulator = 1, control_keyl, control_keyr;
GLfloat red = 0, blue = 1, green = .3;

GLfloat p = 0, q = 0, r = 0;
//
void* currentfont;

void setFont(void* font)


{
currentfont = font;
}
void drawstring(float x, float y, float z, const char* string)
{
const char* c;
glRasterPos3f(x, y, z);

for (c = string; *c != '\0'; c++)


{
glColor3f(0.0, 0.0, 0.0);
glutBitmapCharacter(currentfont, *c);
}
}

void frontscreen(void)

Pag
Dept of CSE, 2022-
TRAFFIC SIGNAL

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glClearColor(0.5, 1.5, 1.1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 0, 0);
drawstring(450.0, 700.0, 0.0, "vtu");
glColor3f(0.7, 0, 1);
drawstring(330, 650, 0.0, "DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING");
glColor3f(1, 0.5, 0);
drawstring(530, 600, 0.0, "A MINI PROJECT ON");
glColor3f(1, 0, 0);
drawstring(360, 500, 0.0, "GRAPHICAL REPRESENTATION OF TRAFFIC SIGNALS");
glColor3f(1, 0.5, 0);
drawstring(200, 400, 0.0, "SUBMITTED BY:");
glColor3f(0, 0, 0);
drawstring(100, 300, 0.0, "VAMSHA ATTAVAR");
glColor3f(0, 0, 0);
drawstring(100, 240, 0.0, "1KT20CS090");
glColor3f(1, 0.5, 0);

drawstring(543, 100, 0.0, "PRESS ENTER TO START");


glFlush();
}
void helpscreen(){
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0, 1, 0);
drawstring(550.0, 700.0, 0.0, "TIPS");
glColor3f(1, 0, 0);
drawstring(650.0, 700.0, 0.0, "AND");
glColor3f(0, 0, 1);
drawstring(750.0, 700.0, 0.0, "TRICKS");
glColor3f(0.5, 0.1, 0.2);
drawstring(350.0, 640.0, 0.0, "Stop the traffic (Red Light) MOUSE LEFT
CLICK");
glVertex2f(6,2.5);
glVertex2f(6,1.5);
glVertex2f(-6,1.5);
glEnd();
// Horizontal
Stripes
glColor3f(0,0,0);
for(float
x1=0;x1<=100;x1+=0.4){glBegin(
GL_POLYGON); glVertex2f(-
6+x1,2);

Dept of CSE, 2022- 9


TRAFFIC SIGNAL
glVertex2f(-5.8+x1,2); glColor3f(0.5, 0.1, 0.3);
drawstring(350.0, 540.0, 0.0, "Yellow Signal MOUSE RIGHT
BUTTON (HOLD ON)");
glColor3f(0.5, 0.1, 0.4);
drawstring(350.0, 440.0, 0.0, "Green Signal MOUSE RIGHT
BUTTON (RELEASE)");
glColor3f(0.4, 0.1, 0.5);
drawstring(350.0, 340.0, 0.0, "Allow vehicles to MOVE left to right PRESS 'L'");
glColor3f(0.5, 0.1, 0.6);
drawstring(350.0, 240.0, 0.0, "Allow vehicles to MOVE right to left PRESS 'R'");
glColor3f(0.5, 0.1, 0.7);
drawstring(350.0, 140.0, 0.0, "Speed up the vehicles PRESS 'S'");
glColor3f(0.5, 0.1, 0.8);
drawstring(350.0, 90.0, 0.0, "Help PRESS 'H'");
glColor3f(0.5, 0.1, 0.9);
drawstring(350.0, 40.0, 0.0, "Escape PRESS 'ENTER'");
glFlush();void bdg(float x1, float y1)
void control()
{
if (control_keyl != 'l' || control_keyr != 'r')
{
if (control_keyl == 'l')
a = a + 6;
if (control_keyr == 'r')
b = b - 6;
}

void myKeyboard(unsigned char key, int x, int y)

{
switch (key)
{
case 13:
if (flag == 1)
{
flag = 2;
mydisplay();
}
if (flag == 0) //Ascii of 'enter' key is 13
{
flag = 1; mydisplay();
}

Dept of CSE, 2022- 1


TRAFFIC SIGNAL

void cars(float x1,float y1)


{
glPushMatrix();
glScaled(0.3,0.5,0.5);
glTranslatef(x1,y1,0);
glPushMatrix();
glColor3f(1,0,1);
glutSolidCube(1);
glPopMatrix();

//wheel 1
glPushMatrix();
glRotatef(90,1.0f,0.0f,0.0f);
glTranslatef(-0.45,0.15,-0.02);
glScaled(0.15,0.15,0.6);
glColor3f(.5,.5,.5);
glutSolidTorus(1,0.8,20,20);
glPopMatrix();

//wheel 2
glPushMatrix();
glRotatef(90,1.0f,0.0f,0.0f);
glTranslatef(0.35,0.15,-0.02);
glScaled(0.15,0.15,0.6);
glColor3f(.5,.5,.5);
glutSolidTorus(1,0.8,20,20);
glPopMatrix();

//footer cube
glPushMatrix();
glTranslatef(-0.2,0,0);
glScaled(1.5,1,.7);
glColor3f(0,0,1);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
}

void carsv(float x1,float y1)


{
glPushMatrix();
glScaled(0.3,0.5,0.5);
glTranslatef(x1,y1,0);
glRotatef(-90,0,0,1);
glPushMatrix();
glColor3f(1,0,1);

Dept of CSE, 2022- 1


TRAFFIC SIGNAL

glutSolidCube(1);
glPopMatrix();

//wheel 1
glPushMatrix();
glRotatef(90,1.0f,0.0f,0.0f);
glTranslatef(-0.45,0.15,-0.02);
glScaled(0.15,0.15,0.6);
glColor3f(.5,.5,.5);
glutSolidTorus(1,0.8,20,20);
glPopMatrix();

//wheel 2
glPushMatrix();
glRotatef(90,1.0f,0.0f,0.0f);
glTranslatef(0.35,0.15,-0.02);
glScaled(0.15,0.15,0.6);
glColor3f(.5,.5,.5);
glutSolidTorus(1,0.8,20,20);
glPopMatrix();

//footer cube
glPushMatrix();
glTranslatef(-0.2,0,0);
glScaled(1.5,1,.7);
glColor3f(0,0,1);
glutSolidCube(1);
glPopMatrix();
glPopMatrix();
}

void myCar(float x1,float y1)


{
glPushMatrix();
glScaled(0.2,0.6,0.1);
glTranslatef(x1,y1,0);
glPushMatrix();
glColor3f(0,0,1);
glutSolidCube(1);
glPopMatrix();

for(int tx=0;tx<=4;tx++)
{
if(tempx[tx]>=1.8 && tempx[tx]<=3 && green){

}else if(tx==0)

Dept of CSE, 2022- 1


TRAFFIC SIGNAL

{ x[tx]+=0.0
7;
}
else if(tempx[tx]<=tempx[tx-1]+2)
{
}
else x[tx]
+=0.07;

cars(tempx[tx],3.5);
}
// Condition for vertical car
crash for(int ty1=0;ty1<=4;ty1+
+)
{

glScaled(0.2,0.2,0.2);
glutSolidSphere(0.35,30,30);
glPopMatrix();

//green signal
glPushMatrix();
if(green)
glColor3f(0,1,0);
else
glColor3f(0,0,0);
glTranslatef(0.65,2.5,0.9);
glScaled(0.2,0.2,0.2);
glutSolidSphere(0.35,30,30);
glPopMatrix();

//Signal for horizontal cars


//Pole
glPushMatrix();
glTranslatef(-0.65,0.8,0);
glScaled(0.2,0.4,4.5);
glutSolidCube(0.5);
glPopMatrix();

//red signal
glPushMatrix();
if(red)
glColor3f(0,1,0);
else
glColor3f(0,0,0);
glTranslatef(-0.6,0.8,0.7);
glScaled(0.2,0.5,0.5);
glutSolidSphere(0.25,30,30);

Dept of CSE, 2022- 1


TRAFFIC SIGNAL

glPopMatrix
//green signal
glPushMatrix();
if(green)
glColor3f(1,0,0);
else
glColor3f(0,0,0);
glTranslatef(-0.6,0.8,1);
glScaled(0.2,0.5,0.5);
glutSolidSphere(0.25,30,30);
glPopMatrix();

//Garden trees
glPushMatrix();
glTranslatef(2.5,-2.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();

glPushMatrix();
glTranslatef(1.5,-2.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();

glPushMatrix();
glTranslatef(0.5,-2.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();

glPushMatrix();
glTranslatef(2.5,-4.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();

glPushMatrix();
glTranslatef(1.5,-4.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();

Dept of CSE, 2022- 1


TRAFFIC SIGNAL

glPopMatrix

glPushMatrix();
glTranslatef(0.5,-4.8,1);
glRotatef(70,1,0,0);
glScaled(0.4,0.4,0.4);
tree();
glPopMatrix();

glFlush();
glutSwapBuffers();
}

void
i()
{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0,0.5,0.5,0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,1,-1.0,"Submitted By");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-2,0,-1.0,"Student 1");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-2,-1,-1.0,"Student 2");

glEnable(GL_COLOR_MATERIAL);glFlush();
glutSwapBuffers();

void c()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.5,0.0,0.5,0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);

setFont(GLUT_BITMAP_TIMES_ROMAN_24);

Dept of CSE, 2022- 1


TRAFFIC SIGNAL
glColor3f(1,1,1);
glPopMatrix

Dept of CSE, 2022- 1


TRAFFIC SIGNAL

drawstring(-1,2,-1.0,"Press p/P -> Start");


setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,1,-1.0,"USER Car Control keys");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,0,-1.0,"Press w/W -> UP");

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,-1,-1.0,"Press a/A -> LEFT");

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,-2,-1.0,"Press d/D -> RIGHT");

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1,-3,-1.0,"Press s/S -> DOWN");

glEnable(GL_COLOR_MATERIAL);
glFlush();
glutSwapBuffers();
}

void gameOver(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1,1,1,0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-1,0,-1.0,"Accident");

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-1,-1,-1.0,"Press r -> Reset");

glFlush();
glutSwapBuffers();
}

void p()
{
//automate signals

Dept of CSE, 2022- 1


TRAFFIC SIGNAL

if(s1<=10){
if(s1<5){
red=true;
green=false;
s1+=0.006;
}
if(s1>5){
red=false;
green=true;
s1+=0.006;
}
if(s1>=9.5){
s1=0;
}
}

if(crash)
{
gameOver();
}
else{

//if(!stop)
//x+=0.07;
trafic(x[0]);

void P()
{
//x += .07;
trafic(x[0]);
}

void doInit()
{

/* Background and foreground color */


glClearColor(1.0,1.0,1.0,0);
glViewport(0,0,640,480);

/* Select the modelview matrix, which we alter with rotatef() */

Dept of CSE, 2022- 1


TRAFFIC SIGNAL

glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glClearDepth(2.0f);
glEnable(GL_DEPTH_TEST);
glEnable( GL_COLOR_MATERIAL );
glDepthFunc(GL_LEQUAL);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1,1,1,0);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-2,0,-1.0,"A Mini Project on 'TRAFFIC SIGNALS'");

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);
drawstring(-2,-1,-1.0," Press 'I/i' For Students Information");

setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0,0,0);

drawstring(-2,-2,-1.0,"Press 'C/c' For KeyBoard Interaction");

GLfloat mat_ambient[]={0.0f,1.0f,2.0f,1.0f};
GLfloat mat_diffuse[]={0.0f,1.5f,.5f,1.0f};
GLfloat mat_specular[]={5.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);

GLfloat lightIntensity[]={1.7f,1.7f,1.7f,1.0f}; GLfloat


light_position3[]={2.0f,10.0f,3.0f,1.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);

GLfloat lightIntensity1[]={1.7f,1.7f,1.7f,1.0f}; GLfloat


light_position1[]={-2.0f,1.0f,-5.0f,1.0f};
glLightfv(GL_LIGHT1,GL_POSITION,light_position1);
glLightfv(GL_LIGHT1,GL_DIFFUSE,lightIntensity1);
glColor3f(0.0, 0.0, 0.0); //connecting outer line

Dept of CSE, 2022- 1


glBegin(GL_LINES);
glVertex2d(12.0, 5.0); TRAFFIC SIGNAL SIMULATOR
glVertex2d(12.0, 6.2);
glEnd();

glColor3f(0.0, 0.0, 0.0); //connecting outer line


glBegin(GL_LINES);
glVertex2d(7.0, 5.0);
glVertex2d(7.0, 6.7);
glEnd();

glBegin(GL_POLYGON); //drawing a back tyre


glVertex2f(3.0, 2.5);
glVertex2f(3.0, 2.6);
glVertex2f(3.15, 3.1);
glVertex2f(3.2, 3.2);
glVertex2f(3.3, 3.35);
glVertex2f(3.4, 3.4);
glVertex2f(3.5, 3.45);
glVertex2f(3.6, 3.55);
glVertex2f(3.7, 3.6);
glVertex2f(3.8, 3.63);
glVertex2f(4.0, 3.65);
glVertex2f(4.2, 3.7);
glVertex2f(4.4, 3.7);
glVertex2f(4.6, 3.65);
glVertex2f(4.8, 3.55);
glVertex2f(5.0, 3.45);
glVertex2f(5.1, 3.4);
glVertex2f(5.2, 3.25);
glVertex2f(5.3, 3.2);
glVertex2f(5.4, 3.0);
glVertex2f(5.5, 2.5);

glVertex2f(5.45, 2.15);
glVertex2f(5.4, 1.9);
glVertex2f(5.35, 1.8);
glVertex2f(5.2, 1.6);
glVertex2f(5.0, 1.5);
glVertex2f(4.9, 1.4);
glVertex2f(4.7, 1.3);
glVertex2f(4.6, 1.27);
glVertex2f(4.4, 1.25);
glVertex2f(4.0, 1.25);
glVertex2f(3.9, 1.3);
glVertex2f(3.75, 1.35);
glVertex2f(3.6, 1.4);
glVertex2f(3.45, 1.55);
glVertex2f(3.3, 1.7);
glVertex2f(3.2, 1.8);
glVertex2f(3.1, 2.2);
glEnd()
glBegin(GL_POLYGON); //drawing front
tyre glVertex2f(17.0, 2.5);

Dept of CSE, 2022-

2
TRAFFIC SIGNAL

glVertex2f(17.3, 3.35);
glVertex2f(17.4, 3.4);
glVertex2f(17.5, 3.45);
glVertex2f(17.6, 3.55);
glVertex2f(17.7, 3.6);
glVertex2f(17.8, 3.63);
glVertex2f(18.0, 3.65);
glVertex2f(18.2, 3.7);
glVertex2f(18.4, 3.7);
glVertex2f(18.6, 3.65);
glVertex2f(18.8, 3.55);
glVertex2f(19.0, 3.45);
glVertex2f(19.1, 3.4);
glVertex2f(19.2, 3.25);
glVertex2f(19.3, 3.2);
glVertex2f(19.4, 3.0);

glVertex2f(19.5, 2.5);
glVertex2f(19.45, 2.15);
glVertex2f(19.4, 1.9);
glVertex2f(19.35, 1.8);
glVertex2f(19.2, 1.6);
glVertex2f(19.0, 1.5);
glVertex2f(18.9, 1.4);
glVertex2f(18.7, 1.3);
glVertex2f(18.6, 1.27);
glVertex2f(18.4, 1.25);
glVertex2f(18.0, 1.25);
glVertex2f(17.9, 1.3);
glVertex2f(17.75, 1.35);
glVertex2f(17.6, 1.4);
glVertex2f(17.45, 1.55);
glVertex2f(17.3, 1.7);
glVertex2f(17.2, 1.8);
glVertex2f(17.1, 2.2);
glEnd();
glPopMatrix();
}
glBegin(GL_LINES); //connecting outer line
glVertex2d(7.0, 5.0);
glVertex2d(15.0, 5.0);
glEnd();

glColor3f(0.0, 0.0, 0.0); //connecting outer line


glBegin(GL_LINES);
glVertex2d(15.0, 4.0);
glVertex2d(17.0, 4.0);
glEnd();

glColor3f(0.0, 0.0, 0.0); //connecting outer line


glBegin(GL_LINES);
glEnd();

Dept of CSE, 2022-

2
TRAFFIC SIGNAL

void myinit()
{

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 1346.0, 0.0, 728.0);
}

int main(int argc, char* argv[])


{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(1346, 728);
glutInitWindowPosition(0, 0);
glutCreateWindow("Traffic signal");

glutDisplayFunc(mydisplay);
glutKeyboardFunc(myKeyboard);
glutMouseFunc(myMouse);

myinit();
glutMainLoop();
}

Dept of CSE, 2022- 2


TRAFFIC SIGNAL

CHAPTER 5
TESTING AND RESULTS
Testing is the process of evaluating a system or its component(s) with the intent to find whether it
satisfies the specified requirements or not. Testing is executing a system in order to identify any
gaps, errors, or missing requirements in contrary to the actual requirements

5.1 DIFFERENT TYPES OF TESTING


1. Unit Testing
Individual components are tested to ensure that they operate correctly. Each component is tested
independently, without other system components.
.
2. Module Testing
A module is a collection of dependent components such as a object class, an abstract Data type or
some looser collection of procedures and functions. A module related Components, so can be tested
without other system modules.

3. System Testing
This is concerned with finding errors that result from unanticipated interaction between Sub-
system interface problems.

4. Acceptance Testing
The system is tested with data supplied by the system customer rather than simulated test data.

Dept of CSE, 2022- 2


TRAFFIC SIGNAL

5.2 TEST CASES


The test cases provided here test the most important features of the project.

Table 5.2.1: Test Case


Sl
No Test Input Expected Results Observed Results Remarks

1 Right click Menu to be displayed Menu displayed pass


2 Right click Menu to be displayed Menu not displayed fail
Click on Working of power plant must be Working of power plant
3 pass
menu item 1 displayed displayed
Click on Description of power plant to be Description of power plant
4 pass
menu item 2 displayed displayed
Click on Information about internal Information about internal
5 pass
menu item 3 reactions to be displayed reactions displayed
Click on
6 Exit Exit pass
menu item 4

Dept of CSE, 2022- 2


TRAFFIC SIGNAL

CHAPTER 6
SNAPSHOTS

Figure 6.1: Welcome Screen


This is the welcome page of the project .when user right clicks on the screen a menu with options are
displayed.

Figure 6.2: Image of the road

Dept of CSE, 2022- 2


TRAFFIC SIGNAL

Figure 6.2: Image of traffic signal

Dept of CSE, 2022- 2


TRAFFIC SIGNAL

CONCLUSION

Traffic Signal Simulator is designed and implemented using graphics software called OpenGL
which has become widely accepted standard for developing graphic application. Using OpenGL
functions user can create geometric objects and can use translation, rotation and scaling with respect to
the co-ordinate system. The development of the Traffic Signal Simulator has given a good exposure to
OpenGL by which I have learnt some of the techniques. This mini project on <Traffic Signal
Simulator= using OpenGL is a reliable graphics package that provides the user to easily understand
the working of the nuclear power plant.
The user-friendly interface allows the user to interact with it very effectively. So, I conclude on note
that this project has given me a great exposure to the OpenGL and computer graphics. This is very
reliable graphics package supporting various primitive objects like polygon, line loops, etc. Also, color
selection, menu, keyboard and mouse-based interface are included. Transformations like translation,
rotation, scaling is also provided.

Dept of CSE, 2022- 2


TRAFFIC SIGNAL

BIBLIOGRAPHY

References
[1].Donald Hearn & Pauline Baker: Computer Graphics with OpenGL Version,3rd / 4th Edition,
Pearson Education,2011
[2].Edward Angel: Interactive Computer Graphics- A Top Down approach with OpenGL, 5th edition.
Pearson Education,2008
[3].James D Foley, Andries Van Dam, Steven K Feiner, John F Huges Computer graphics
[4].with OpenGL: pearson education
[5].M M Raiker, Computer Graphics using OpenGL, Filip learning/Elsevier
[6].Kelvin Sung, Peter Shirley, Steven Baer : Interactive Computer Graphics, concepts andapplications,
Cengage Learning
[7].www.opengl.org
[8].www.vtupro.blogspot.in
[9].www.opengl.start4all.com

Dept of CSE, 2022- 2

You might also like