You are on page 1of 33

c c A SCENE OF BUS STOP

c
Chapter 1

INTRODUCTION

OpenGL :

OpenGL provides a set of commands to render a three dimensional scene. That means
you provide the data in an OpenGL-useable form and OpenGL will show this data on the screen
(render it). It is developed by many companies and it is free to use. You can develop OpenGL-
applications without licensing.

OpenGL is a hardware- and system-independent interface. An OpenGL-application will


work on every platform, as long as there is an installed implementation. Because it is system
independent, there are no functions to create windows etc., but there are helper functions for each
platform. A very useful thing is GLUT.

GLUT :

GLUT is a complete API written by Mark Kilgard which lets you create windows and
handle the messages. It exists for several platforms, that means that a program which uses GLUT
can be compiled on many platforms without (or at least with very few) changes in the code.

Use of GLUT:

GLUT provides some routines for the initialization and creating the window (or
fullscreen mode, if you want to). Those functions are called first in a GLUT application. In your
first line you always write g 
 . After this, you must tell GLUT, which display
mode you want ± single or double buffering, color index mode or RGB and so on. This is done
by calling  .

The symbolic constants are connected by a logical OR, so you could use
    !. In later tutorials we will use some more
constants here. After the initialization you call "#$ with the window name as

CS&E., B.I.E.T., Davangere Page 1


c
c c cccc 
c
c
parameter. Display should clear the so called color buffer ± let's say this is the sheet of paper ±
and draw our objects.

You pass the methods by  %& 


, for example  & 
. At the end of the
main function you call  . This function doesn't return, but calls the several
functions passed by  %& 
.

OpenGL Pipeline

. Simplified version of graphics pipeline.

A brief description of the process in the graphics pipeline could be:

1. Evaluation, if necessary, of the polynomial functions which define certain inputs,

like NURBS surfaces, approximating curves and the surface geometry.

2. Vertex operations, transforming and lighting them depending on their material.

Also clipping non visible parts of the scene in order to produce viewing volume.

3. Rasterisation or conversion of the previous information into pixels. The polygons


CS&E., B.I.E.T., Davangere Page 2
c
c c cccc 
c
c
are represented by the appropriate color by means of interpolation algorithms.

4. Per-fragment operations, like updating values depending on incoming and

previously stored depth values, or color combinations, among others.

5. Lastly, fragments are inserted into the Frame buffer

dvantages of OpenGL:

¦c -ith different 3D accelerators, by presenting the programmer To hide the complexities


of interfacing with a single, uniform API.

¦c To hide the differing capabilities of hardware platforms, by requiring that all


implementations support the full OpenGL feature set (using software emulation if
necessary).

General Structure of the program

¦c Section 1: Header files inclusion.

¦c Section 2: Definition of call back function.

¦c Section 3: Main function.

CS&E., B.I.E.T., Davangere Page 3


c
c c cccc 
c
c
Chapter 2

REQUIREMENT SPECIFICTION

Software Requirements
Operating System : -indows
Version of Operating System : -indows XP, -indows NT
Memory : 128MB of RAM
Language : C++
Compiler : Visual C++ 6.0

Hardware Requirements
Hardware Type : Pentium
Version : Pentium 4.0

CS&E., B.I.E.T., Davangere Page 4


c
c c cccc 
c
c
Chapter 3

DESIGN

Control Flow Diagram

Road ();

Bus_stop();
Display function

Bus_move();
Main function

Keyboard function
Man_draw();

Bus_draw();

CreateMenu function

CS&E., B.I.E.T., Davangere Page 5


c
c c cccc 
c
c
Chapter 4

IMPLEMENTTION

HEDER FILES

The <stdio.h> Header File

#include<stdio.h>

It is a standard input/output file. Standard I/O refers to the most usual places where data is either
read from, the keyboard, or written to, the video monitor. Since they are used so much, they are
used as the default I/O devices and do not need to be named in the Input/output instructions.

#include<GL/glut.h>

GL is the fundamental openGL library. It provides functions that are permanent part of OpenGL.
The functions start with characters µgl¶.

GLUT, the GL utility tool kit supports developing and managing menus, and managing events.
The functions start with characters µglut¶.

GLU, the GL Utility Library provides high-level routines to handle certain matrix operations,
drawing of quadric surfaces such as sphere and cylinders. The functions start with characters
µglu¶.

CS&E., B.I.E.T., Davangere Page 6


c
c c cccc 
c
c
MIN FUNCTIONS:

glutInit Function: glutInit is used to initialize the GLUT library.


SYNTAX: 2 c 2
c
 c 2

glutInitWindowSize Functions: glutInit-indowSize set the initial window position and


size respectively.

SYNTAX: c2 c cc 2 c

glutCreateWindow Function: Used for creating a window with a name.

2  
 cc

glutDisplayFunc Function:glutDisplayFunc sets the display callback for the current


window.

SYNTAX: c2  


c


PARAMETERS:

func
The new display callback function.

glutDisplayFunc(display);

glutKeyboardFunc Function: -hen the keyboard event occurs, the ASCII code for the
key that generated the event and the location of the mouse are returned.

SYNTAX:2   


!

The prototype of mykey function is as given below:

"c!2c
 c! cc# ccc

CS&E., B.I.E.T., Davangere Page 7


c
c c cccc 
c
c
glutMainLoop Function: glutMainLoop enters the GLUT event processing loop.

SYNTAX:c2 $% 2 $% 

c
glClearColor Function: The glClearColor function specifies clear values for the color
buffers.
SYNTAX:"c2    cc&%
 cc &%
 c2 &%
 c &%
 cc

PARAMETERS: red, green, glue, alpha.

The red, green, blue and alpha values that glClear uses to clear the color buffers. The default
values are all zero.

CS&E., B.I.E.T., Davangere Page 8


c
c c cccc 
c
c
Chapter 5
SNPSHOT

Initial view from front:This is the initial output screen obtained on executing the program. This
scene, as we can see includes a man waiting at the bus stop and a bus.

Bus at bus stop:This is the snapshot when bus reaches the bus stop. The movement of bus can
be manually done by arrow keys & automatically by enabling timer function.

CS&E., B.I.E.T., Davangere Page 9


c
c c cccc 
c
c
FIG Bus after passing through bus stop
As the bus reaches the stop, man gets into it. -e see from above fig that the man is no
more waiting near stop.

When bus takes right turn


This is the changed view when the bus takes a right turn. It is obtained by right clicking
on the scene and select µoverall view-Right turn¶

CS&E., B.I.E.T., Davangere Page 10


c
c c cccc 
c
c
Chapter 6

CONCLUSION

This project called BUS STOP is an implementation to demonstrate the skills I have
learnt in while executing the graphics laboratory programs. -hile working out with the project, I
came out with various aspects and interesting facts about OpenGL functions & the relevant way
of using those functions.

CS&E., B.I.E.T., Davangere Page 11


c
c c cccc 
c
c
Chapter 7

BIBLIOGRPHY

1.c Interactive computer graphics by Edward angel


2.c Computer Graphics using OpenGL by F.S.Hill & Stephen.M.Kelly
3.c OpenGL graphics through application by Robert -hitrow
4.c OpenGL Bible by Richard -right

CS&E., B.I.E.T., Davangere Page 12


c
c c cccc 
c
c

CS&E., B.I.E.T., Davangere Page 13


c
c c cccc 
c
c

CS&E., B.I.E.T., Davangere Page 14


c
c c cccc 
c
c

Chapter 2

REQUIREMENTS

Software Requirements:

The software requirements are as follows:

¦c An MS-DOS based operating system like -indows 98, -indows 2000 or -indows XP
is the platform required to develop the 2D and 3D graphics applications.
¦c A Visual C/C++ compiler is required for compiling the source code to make the
executable file which can then be directly executed.
¦c A built in graphics library like glut and glut32, and header file like glut.h and also
dynamic link libraries like glut and glut32 are required for creating the 3D layout.

Hardware Requirements:

The hardware requirements are very minimal and the software can run on most of the
machines.
¦c Processor - Intel 486/Pentium processor or above.

CS&E., B.I.E.T., Davangere Page 15


c
c c cccc 
c
c
¦c Processor Speed - 500 MHz or above
¦c RAM - 64MB or above Storage Space - 2 MB or above
¦c Monitor resolution - A color monitor with a minimum resolution of 640*480

CS&E., B.I.E.T., Davangere Page 16


c
c c cccc 
c
c
Chapter 3

DESIGN
The design part of the game deals with how the game has divided and designed
according to the interaction and implementation. Each subsystem provides its own functionalities
independent of the services provided by the other subsystem. Each subsystem then further
divided into modules which explain the subsystem in detail.

The diagram below is used to represent the control relationship between the subsystems,
which is shown below

Relationship diagram

CS&E., B.I.E.T., Davangere Page 17


c
c c cccc 
c
c
User Interface Subsystem
Aim of this subsystem is to provide the user with good interface. This subsystem is
decomposed into following interconnected modules
1.c Introduction module
2.c Score display module
3.c Quit module

Game Subsystem

These modules are most important modules of the project and implement the Rapid-Roll
game.

Different modules involved in this subsystem are as follows,

ëc Play module
ëc Displayscores module
c

Play Module:
This module initializes the variables and data structures used in the game. The data
structures are initialized to represent the initial state of the game.

Displayscore module:
This module helps the for getting the information about the current score of the user
when the game ends.

CS&E., B.I.E.T., Davangere Page 18


c
c c cccc 
c
c
GME STRUCTURE

The game basically consists of a player who has to control the object moving around the
play area in the order specified. The game has six levels based on the speed of movement of
objects on the screen. The level of difficulty increases as the game goes further. The speed of
movement of the objects will increase in the higher rounds. The details of points scoring are
present.

The game consists of a user interface provided by keyboard along with graphical output
consisting of different objects like polygons. Each stage has one or more objects moving around
in the screen. On completing each stage, the player advances to next stage, which is of greater
difficulty, in terms of speed of the movement of the objects.

OVERVIEW OF THE GME

The game begins with a welcome screen and following that will have a menu screen
where in the player can view the rules and how to play information. The inputs to the game are
the name of player and the level number. After the game is loaded the play area will displayed
along with the scoreboard which shows the current players detailed score.

There are three objects rectangles, diamond and thorns which are moving upward. There
are 6 levels in the game with increasing speed of movement of the objects. The objects are filled
with color which helps in identifying the objects clicked so that the order is followed and points
are awarded accordingly. The game starts displaying the player name and level number. The
game enters to higher level automatically. The game ends if crashed and the final score is
displayed. ESC key is used to exit from the game.

CS&E., B.I.E.T., Davangere Page 19


c
c c cccc 
c
c
Chapter 4

IMPLEMENTTION

HEDER FILES

The <stdio.h> Header File

#include<stdio.h>

It is a standard input/output file. Standard I/O refers to the most usual places where data is either
read from, the keyboard, or written to, the video monitor. Since they are used so much, they are
used as the default I/O devices and do not need to be named in the Input/output instructions.

#include<GL/glut.h>

GL is the fundamental openGL library. It provides functions that are permanent part of OpenGL.
The functions start with characters µgl¶.

GLUT, the GL utility tool kit supports developing and managing menus, and managing events.
The functions start with characters µglut¶.

GLU, the GL Utility Library provides high-level routines to handle certain matrix operations,
drawing of quadric surfaces such as sphere and cylinders. The functions start with characters
µglu¶.

CS&E., B.I.E.T., Davangere Page 20


c
c c cccc 
c
c

Library Functions Used:

¦c glClear Function
¦c glColor3f Function
¦c glRasterpos2f Function
¦c glClearColor Function
¦c glutBitmapCharacter Function
¦c glBegin, glEnd Function
¦c glRectf Function
¦c glVertex2f Function
¦c glFlush Function
¦c glPostRedisplay Function
¦c glMatrixMode Function
¦c glLoadIdentity Function
¦c gluOrtho2D Function
Main Functions:
¦c glutInit Function
¦c glutInitWindowSize Functions
¦c glutCreateWindow Function
¦c glutDisplayFunc Function
¦c glutKeyboardFunc Function
¦c glutMouseFunc Function
¦c glutMainLoop Function

CS&E., B.I.E.T., Davangere Page 21


c
c c cccc 
c
c

glColor3f Function:

Sets the current color.

SYNTAX:

c2   '&% c  c&% c2  c&% c c

PARAMETERS:

wc red
The new red value for the current color.

wc green
The new green value for the current color.

glRasterpos2f Function:

This function specify the raster position for pixel operations.

SYNTAX:

c c2 ( )*c


cc cc &% cc# c
cc cc &% ccc
cccccccccccccccccccc c c

PARAMETERS:c

x, y, z, w

The x, y, z, and w object coordinates (if present) for the raster position.

CS&E., B.I.E.T., Davangere Page 22


c
c c cccc 
c
c
glBegin, glEnd Function:

The glBegin and glEnd functions delimit the vertices of a primitive or

a group of like primitives.

SYNTAX:

c2 +2 c2 ,&%cc

PARAMETERS:

mode
The primitive or primitives that will be created from vertices presented between

glBegin and the subsequent glEnd.

GL_POLYGON:

Draws a single, convex polygon. Vertices 1 through N define this polygon.

glRectf Function:

This function draws a rectangle.

SYNTAX:

c2 (
c
cc&% c#- c
cc&% c- c
cc&% c#* c
cc&% c*c


CS&E., B.I.E.T., Davangere Page 23


c
c c cccc 
c
c
PARAMETERS:

wc x1, y1

One vertex of a rectangle.

wc x2, y2

The opposite vertex of the rectangle

glVertex2f Function:

Specifies a vertex.

SYNTAX:

c2 " #*&% c# c&% cc

PARAMETERS:

wc x
Specifies the x-coordinate of a vertex.
wc y
Specifies the y-coordinate of a vertex.

glVertex2f(-3.0,3.0);

glClear Function:

The glClear function clears buffers to preset values.

SYNTAX:

2   c&%  c!c

CS&E., B.I.E.T., Davangere Page 24


c
c c cccc 
c
c
PARAMETERS:

mask
Bitwise OR operators of masks that indicate the buffers to be cleared. The four
masks are as follows.

Value Meaning

GL_COLOR_BUFFER_BIT The buffers enabled for color writing.

GL_DEPTH_BUFFER_BIT The depth buffer.

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glLoadIdentity Function:

The glLoadIdentity function replaces the current matrix with the identity matrix.

SYNTAX:

c2 %c

PARAMETERS:

This function has no parameters.

glLoadIdentity();

glMatrixMode Function:

The glMatrixMode function specifies which matrix is the current matrix.

SYNTAX:

c2 $ #$&%cc

CS&E., B.I.E.T., Davangere Page 25


c
c c cccc 
c
c
PARAMETERS:

mode
wc glMatrixMode(GL_MODELVIE-);
wc glMatrixMode(GL_PROJECTION);

glFlush Function:
Forces any buffered OpenGL commands to execute.
SYNTAX:
2   ccc

glutBitmapCharacter Function:
It renders the character with ASCII code char at the current raster position using the
raster font given by font.
SYNTAX:

cc2 +   
 ccc cc
 cc

PARAMETERS:

wc GLUT_BITMAP_TIMES_ROMAN_10
wc GLUT_BITMAP_TIMES_ROMAN_8_BY_13

glPostRedisplay Function:
It request that the display callback be executed after current callback return.

gluOrtho2D:

The gluOrtho2D function defines a 2-D orthographic projection matrix.

CS&E., B.I.E.T., Davangere Page 26


c
c c cccc 
c
c

SYNTAX:

"c2 .  *cc

c c &% cc  c

c c &% cc 2  c

c c &% c  c

c c &% c c

ccccccccc

PARAMETERS:

wc left, right

The coordinates for the left and right vertical clipping planes.

wc bottom, top

The coordinates for the bottom and top horizontal clipping planes.

MIN FUNCTIONS:

glutInit Function:
glutInit is used to initialize the GLUT library.

SYNTAX:

2 c 2
c
 c 2c

CS&E., B.I.E.T., Davangere Page 27


c
c c cccc 
c
c
glutInitWindowSize Functions:

glutInit-indowSize set the initial window position and size respectively.

SYNTAX:

c2 c cc 2 c c

glutCreateWindow Function:

Used for creating a window with a name.

2  
 cc

glutDisplayFunc Function:

glutDisplayFunc sets the display callback for the current window.

SYNTAX:

c2  


c
c

PARAMETERS:

func
The new display callback function.

glutDisplayFunc(display);
glutKeyboardFunc Function:

-hen the keyboard event occurs, the ASCII code for the key that generated the event and
the location of the mouse are returned.

SYNTAX:

2   
!c

CS&E., B.I.E.T., Davangere Page 28


c
c c cccc 
c
c
The prototype of mykey function is as given below:

"c!2c
 c! cc# ccc

glutMainLoop Function:

glutMainLoop enters the GLUT event processing loop.

SYNTAX:

c2 $% c

2 $% c
c
glClearColor Function:
The glClearColor function specifies clear values for the color buffers.
SYNTAX:

"c2    ccc


c &%
 cc c
c &%
 cc2 c
c &%
 cc c
c &%
 cccc
ccccccccccccccccccccccccccccccc
PARAMETERS: red, green, glue, alpha.

The red, green, blue and alpha values that glClear uses to clear the color buffers. The default
values are all zero.

CS&E., B.I.E.T., Davangere Page 29


c
c c cccc 
c
c
Chapter 5

SNPSHOTS

CS&E., B.I.E.T., Davangere Page 30


c
c c cccc 
c
c

CS&E., B.I.E.T., Davangere Page 31


c
c c cccc 
c
c
Chapter 6

CONCLUSION

-e started out with the intention of designing a simple game with the objective that the
object should avoid obstacles in its way. -ith little experience in programming projects such as
this, we ended up learning many things.

The game Rapid-Roll that we have designed currently has features such as
increase/decrease speed, menus, lighting in 6 levels of game play. Adding more levels is simple
and we intend to do so in the future. This project has all the features which makes for a small
Graphics project. The code is open source and the user is free to alter it for feature enhancement.

Further enhancements we wish to include are


¦c More levels
¦c 3D objects and 3D view
¦c Choice of objects to choose from to play the game
¦c More realistic simulation of objects.

-hile designing this project we learnt a lot of things like the software engineering
techniques required to code a project, debugging skills required to remove the bugs from a code
and also learnt how to optimize a code so that it runs on lower end machines as well.

-e thus conclude by saying that we are extremely happy we got a chance to design a
project such as this and are looking forward to designing more such projects in the future.

CS&E., B.I.E.T., Davangere Page 32


c
c c cccc 
c
c

Chapter 9

BIBLIOGRPHY

V 
wc Edward Angel: Interactive Computer Graphics A TOP DO-N APPROACH with opengl,
second edition, Addison -esley,2000

wc F.S.Hill,Jr: Computer Graphics Using OpenGL,2nd Edition.

-    

wc www.opengl.org/resources/code/samples/sig99/advanced99/notes/notes.html
wc www.wikipedia.org

CS&E., B.I.E.T., Davangere Page 33


c

You might also like