You are on page 1of 34

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

BELGAUM- 590014

A CG Mini-Project Report
On

“MOVING BOAT”

A Mini-project report submitted in partial fulfillment of the requirements for


the award of the degree of Bachelor of Engineering in Computer Science and
Engineering of Visvesvaraya Technological University, Belgaum.
Submitted by:
POLISETTI KOWSHITHA(1DT19CS105)
PREETHI S(1DT19CS117)
Under the Guidance of:
Prof. Deepa Shree
Asst. Prof. Dept of CSE
Prof. A.Shalini
Asst. Prof. Dept of CSE

Department of Computer Science and Engineering


(Accredited by NBA, NAAC A+, New Delhi)
DAYANANDA SAGAR ACADEMY OF TECHNOLOGY &
MANAGEMENT
Udayapura, Kanakapura Road, Bangalore
2021-22
DAYANANDA SAGAR ACADEMY OF TECHNOLOGY &
MANAGEMENT
Udayapura, Kanakapura Road, Bangalore

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


(Accredited by NBA, NAAC A+, New Delhi)

CERTIFICATE
This is to certify that the Mini-Project on Computer Graphics and Visualization
(CG) entitled “MOVING BOAT” has been successfully carried out by
POLISETTI KOWSHITHA(1DT19CS105) and PREETHI S(1DT19CS117) a
bonafide students of Dayananda Sagar Academy of Technology and
Management in partial fulfillment of the requirements for the award of degree in
Bachelor of Engineering in Computer Science and Engineering of
Visvesvaraya Technological University, Belgaum during academic 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 in
respect of project work for the said degree.

GUIDE:

Prof. K. Deepa Shree Prof.A.Shalini


Asst.Professor,Dept of CSE Asst. Professor, Dept of CSE

Dr. C. NANDINI
Vice Principal &HOD,Dept of CSE

Examiners:

1:

2: Signature with Date


ACKNOWLEDGEMENT

It gives us immense pleasure to present before you our project titled “MOVING BOAT”.
The joy and satisfaction that accompany the successful completion of any task would be
incomplete without the mention of those who made it possible. We are glad to express
our gratitude towards our prestigious institution DAYANANDA SAGAR ACADEMY
OF TECHNOLOGY AND MANAGEMENT for providing us with utmost knowledge,
encouragement and the maximum facilities in undertaking this project.

We wish to express a sincere thanks to our respected principal Dr. RAVISHANKAR M,


Principal, DSATM for all his support.

We express our deepest gratitude and special thanks to Dr. C. Nandini, Vice Principal &
H.O.D, Dept. Of Computer Science &Engineering, for all her guidance and
encouragement.

We sincerely acknowledge the guidance and constant encouragement of our mini- project
guides, Prof. Deepa Shree Assistant Professor, Dept of CSE and Prof.A.Shalini
Assistant Professor, Dept of CSE

P KOWSHITHA(1DT19CS105)
PREETHI S(1DT19CS117)
ABSTRACT

In today’s world advanced technology, interactive computer graphics has become a


powerful tool for the production of realistic features. Today’s we find computer graphics
used in various areas that include science, engineering, medicine, business, industry, art,
entertainment etc. The main reason for effectiveness of the interactive computer graphics
is the speed with which the user can understand the displayed information.

OBJECTIVES OF THE PROJECT

 Developing the moving boat using computer graphics with OpenGL


 Migration from text editor to OpenGL.
 Implementing certain technical concept like Translation, motion, and use of Idle
Function.

The "MOVING BOAT" is the concept of moving the ship in island with the Keyboard
functions. We can move the ship with Keyboard buttons which can move in the backward
direction or forward direction. The main ship contains the chimney which will give the
fog effect and there are two other boats which is moving continuously in the island. The
boats contain one flag each.

There is another mode which is night mode. We can change the island into night mode by
clicking the “r” letter in the keyboard and to return into morning mode again we have to
click the “r” letter. In our project we have used the advanced functions.
TABLE OF CONTENTS

Chapter No. Chapter Name Page No.

1. Introduction
1.1 About Computer Graphics 1
1.2 About OpenGL 2
1.3 Features of OpenGL 2
1.4 OpenGL Architecture 3
1.5 Overview of the Project 3

2. Requirements
2.1 Software Requirements 4
2.2 Hardware Requirements 4

3. Design
3.1 Initialization 5
3.2 Flowchart 5

4. Implementation
4.1 OpenGL Functions 6
4.2 User defined Functions 8

5. Source Code 9
5.1 Appendix 9

6. Screenshots 24

7. Conclusion and Future work


7.1 Conclusion 27
7.2 Future Enhancement 27
LIST OF FIGURES

FIGURE NO. TOPIC PAGE NO.

Figure 6.1 Main Window 24

Figure 6.2 Main Window 25

Figure 6.3 Main Window 25

Figure 6.4 NightModeWindow 26

Figure 6.5 Normal Window 26


CG Mini-Project MOVING BOAT

CHAPTER 1

INTRODUCTION

1.1 About Computer Graphics


The Computer Graphics is one of the most effective and commonly used methods to
communicate the processed information to the user. It displays the information in the
form of graphics objects such as pictures, charts, graphs and diagram instead of simple
text.
In computer graphics, pictures or graphics objects are presented as a collection of discrete
picture elements called pixels. The pixel is the smallest addressable screen element
Computer graphics today is largely interactive: The user controls the contents structure,
and appearance of objects and their displayed images by using input devices, such as a
keyboard, mouse, or touch-sensitive panel on the screen.
Computer Graphics relies on an internal model of the scene, that is, mathematical
representation suitable for graphical computations. The model describes the 3D shapes,
layout and materials of the scene. This 3D representation then has to be projected to
compute a 2D image from a given viewpoint, this is rendering step. Rendering involves
projecting the objects, handling visibility (which parts of objects are hidden) and
computing their appearance and lighting interactions. Finally, for animated sequence, the
motion of objects has to be specified.
Computer graphics today is largely interactive: The user controls the contents’ structure,
and appearance of objects and their displayed images by using input devices, such as a
keyboard, mouse, or touch-sensitive panel on the screen.

Dept. of CSE, DSATM 2021-2022 Page 1


CG Mini-Project MOVING BOAT

The image processing can be classified as


 Image enhancement.
 Pattern detection and recognition.
 Pattern detection and recognition.

The image enhancement deals with the improvement in the image quality by eliminating
noise or by increasing image contrast. Pattern detection and recognition deals with the
detection and clarification of standard patterns
And finding deviations from these patterns. The optical character recognition (OCR)
technology is a practical example for pattern detection & recognition. Scene analysis
deals with the recognition and reconstruction of 3D model of scene from several 2D
images.

1.2 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 three-dimensional scenes from simple primitives. OpenGL was developed by
Silicon Graphics Inc.
OpenGL's basic operation is to accept primitives such as points, lines and polygons, and
convert them into pixels. This is done by a graphics pipeline known as the OpenGL state
machine.

1.3 Features of OpenGL

 Geometric Primitives allow you to construct mathematical descriptions of objects.


 Viewing and Modelling permits arranging objects in a 3-dimensional scene, move
our camera around space and select the desired vantage point for viewing the
scene to be rendered.
 Materials lighting OpenGL provides commands to compute the color of any point
given the properties of the material and the sources of light in the room.
 Transformations: rotation, scaling, translations, perspectives in 3D, etc. page

Dept. of CSE, DSATM 2021-2022 Page 2


CG Mini-Project MOVING BOAT

1.4 OpenGL Architecture

OpenGL Architecture

This is the most important diagram you will see today, representing the flow of graphical
information, as it is processed d from CPU to the frame buffer.
There are two pipelines of data flow. The upper pipeline is for geometric, vertex-based
primitives. The lower pipeline ne is for pixel-based, image primitives. Texturing
combines the two types of primitives together.

1.5 Overview of the Project

 Computer graphics involves the designing of objects in different forms which are
regular and irregular in shape. The mini project named “MOVING BOAT” is
nothing but moving the main ship using keyboard buttons.
 The island can change the morning mode into night mode by clicking “r” letter in
the keyboard which we explained in the abstract.
 Again it will return into morning mode from night mode by pressing “r” letter.

Dept. of CSE, DSATM 2021-2022 Page 3


CG Mini-Project MOVING BOAT

CHAPTER 2

REQUIREMENTS
We have a wide range of options of languages. From these options we can choose
appropriate platform/ tools and languages for development of the project. Some of these
are as follows: -

Programming Languages: - In programming language we have C++.

Compiler: - GNU GCC compiler/C++ compiler

2.1 SOFTWARE REQUIREMENTS:

Operating system : Windows 2000 or later

Language Tools : OpenGL

Documentation Tool : Visual C++ with OpenGL functions

2.2 HARDWARE SPECIFICATIONS

Processor : Intel Pentium or more

Ram : 128 MB or more

Cache : 512 KB

Hard disk : 16 GB hard disk recommended

Keyboard : Standard 101 key keyboard

Dept. of CSE, DSATM 2021-2022 Page 4


CG Mini-Project MOVING BOAT

CHAPTER 3

DESIGN
Design is the planning that lays the basics for the making of all objects or systems.
This chapter involves designing of various aspects and different stages of project. When
program is made to execute, the output window is displayed first. The flow of operation
from output window is shown in figure.

3.1 Initialization
Initialize the interaction with the windows. Initialize the display mode, double buffer and
depth buffer. Initialize the various keyboard functions for forward and backward
movement of the ship. Initialize the window position and size and create the window to
display the output.

3.2 Flowchart

Flowchart for moving boat program

Dept. of CSE, DSATM 2021-2022 Page 5


CG Mini-Project MOVING BOAT

CHAPTER 4

IMPLEMENTATION

4.1 OpenGL Functions


The various functions used in implementing this project are:
 glutInit(&argc,argv)
This function is used to initialize glut.

 glutInitDisplayMode()
This function is used to initialize a display mode for the screen. It can choose one
of the following constant values as it’s parameters:

▪ GLUT_SINGLE
▪ GLUT_RGB
▪ GLUT_DOUBLE

 glutInitWindowPosition()
This function is used to set the position of the top left corner of the window. It
takes in 2 integer values as input parameters which are the coordinates specified
for the position for the top left corner of the window.

 glutInitWindowSize()
This function is used to specify the size of the created window, inside which the
scene will be generated. It takes in two integer parameters, the width and height of
the window.

 glutCreateWindow()
This function creates the window with the specified dimensions and position and
assigns the string parameter passed to it as the name of the window.
 glutMainLoop()
This function is called at most once in a GLUT program. Once called, this routine
will never return. It will call as necessary, any callbacks required for the program.

Dept. of CSE, DSATM 2021-2022 Page 6


CG Mini-Project MOVING BOAT

 glBegin()
This function is used in drawing the basic primitives like lines, points, polygons
and quads. It takes in a constant value which specifies the primitive to be drawn.
Some of the parameters it can have are-

▪ GL_POLYGON
▪ GL_LINES CG Mini-project – Archery Game
▪ GL_LINE_LOOP
▪ GL_QUADS
▪ GL_QUAD_STRIP

 glClear()
This function is used to clear the contents of the buffer passed as the parameters
to this function, onto the screen.
It takes a constant value as a parameter like:
▪ GL_CLEAR_BUFFER_BIT
▪ GL_DEPTH_BUFFER_BIT

 glClearColor()
This function takes in four floating values:
▪ Red
▪ Green
▪ Blue
▪ Alpha

Based on RGB values, the colour is decided. The Alpha value gives the degree of
transparency of the colour. The values for RGBA will range from 0.0 to 1.0.

 glEnd()
This function works with the glBegin() function. It marks the end of all the
vertices to be used for drawing the primitive.

Dept. of CSE, DSATM 2021-2022 Page 7


CG Mini-Project MOVING BOAT

4.2 Implementation of user-defined functions:

 void circle(float x,float y,double r):


Here the function circle() is used to draw the curves in the cloud and sun it basically uses
OpenGL glVertex() having ‘x’ and ‘y’ attributes specifying ‘x’ and ‘y’ co-ordinate
position respectively.

 void sky():
This function is the back ground for sun and cloud using glBegin(QUADS).we have done
sky the light is indented from sun which is traversed throw sky.

 void drawCloud():
This functions is used to draw the cloud using combinations of circle() function and is
moved using glTranslate() function.

 void drawSun():
Basically this function is used to draw Sun on the Screen by calling circle() function and
we use glColor3f() to give colour to the sun.

 void island():
It is used to generate island.

 void ship(),ship2(),ship3():
This functions is used to draw the fishes using the combination of gl(QUADS)
and gl(TRIANGLES), and gl(POINTS).

 void water(),water2():
This function is used to draw river we have used glBegin(QUADS) up on which incident
refraction takes place in river.

 drawmoon():
It is used to draw moon.

Dept. of CSE, DSATM 2021-2022 Page 8


CG Mini-Project MOVING BOAT

CHAPTER 5
APPENDIX
5.1 SOURCE CODE
#include<windows.h>
#include<GL/glut.h>
#include <stdio.h>
#include <math.h>
#include<cmath>
#include<stdlib.h>
#include<string.h>
int flag=0;
float pos=0,y=0;
int showclouds=0;
float increase=0;
int increase2=0;
int increaseclouds=0;
typedef struct edgebucket{
int ymax;
float xofymin;
float slopeinverse;
}EdgeBucket;
typedef struct edgetabletup{
int countEdgeBucket;
EdgeBucket buckets[maxVer];
}EdgeTableTuple;
EdgeTableTuple EdgeTable[maxHt], ActiveEdgeTuple;
void initEdgeTable(){
int i;
for (i=0; i<maxHt; i++){
EdgeTable[i].countEdgeBucket = 0;
}
ActiveEdgeTuple.countEdgeBucket = 0;
}
void midpoint(int X1,int Y1,int X2,int Y2)
{
int dx=(X2-X1);
int dy=(Y2-Y1);
int d=dy-(dx/2);
int x;
int y;
x=X1;
y=Y1;
glBegin(GL_POINTS);
glVertex2d(x,y);
glPointSize(10);

Dept. of CSE, DSATM 2021-2022 Page 9


CG Mini-Project MOVING BOAT

while(x<X2){
x++;
if(d<0)
d=d+dy;
else{
d+=(dy-dx);
y++;
}
glVertex2d(x,y);
}
glEnd();
}
void insertionSort(EdgeTableTuple *ett){
int i,j;
EdgeBucket temp;

for (i = 1; i < ett->countEdgeBucket; i++){


temp.ymax = ett->buckets[i].ymax;
temp.xofymin = ett->buckets[i].xofymin;
temp.slopeinverse = ett->buckets[i].slopeinverse;
j = i - 1;

while ((temp.xofymin < ett->buckets[j].xofymin) && (j >= 0)){


ett->buckets[j + 1].ymax = ett->buckets[j].ymax;
ett->buckets[j + 1].xofymin = ett->buckets[j].xofymin;
ett->buckets[j + 1].slopeinverse = ett->buckets[j].slopeinverse;
j = j - 1;
}
ett->buckets[j + 1].ymax = temp.ymax;
ett->buckets[j + 1].xofymin = temp.xofymin;
ett->buckets[j + 1].slopeinverse = temp.slopeinverse;
}
}
void storeEdgeInTuple (EdgeTableTuple *receiver,int ym,int xm,float slopInv){
(receiver->buckets[(receiver)->countEdgeBucket]).ymax = ym;
(receiver->buckets[(receiver)->countEdgeBucket]).xofymin = (float)xm;
(receiver->buckets[(receiver)->countEdgeBucket]).slopeinverse = slopInv;
insertionSort(receiver);
(receiver->countEdgeBucket)++;
}
void storeEdgeInTable (int x1,int y1, int x2, int y2){
float m,minv;
int ymaxTS,xwithyminTS, scanline; //ts stands for to store

if (x2==x1){
minv=0.000000;

Dept. of CSE, DSATM 2021-2022 Page 10


CG Mini-Project MOVING BOAT

}
else{
m = ((float)(y2-y1))/((float)(x2-x1));
if (y2==y1)
return;

minv = (float)1.0/m;
}
if (y1>y2){
scanline=y2;
ymaxTS=y1;
xwithyminTS=x2;
}
else{
scanline=y1;
ymaxTS=y2;
xwithyminTS=x1;
}
storeEdgeInTuple(&EdgeTable[scanline],ymaxTS,xwithyminTS,minv);
}
void removeEdgeByYmax(EdgeTableTuple *Tup,int yy){
int i,c;
for (i=0; i< Tup->countEdgeBucket; i++){
if (Tup->buckets[i].ymax == yy){
for ( c = i ; c < Tup->countEdgeBucket -1 ; c++ ){
Tup->buckets[c].ymax =Tup->buckets[c+1].ymax;
Tup->buckets[c].xofymin =Tup->buckets[c+1].xofymin;
Tup->buckets[c].slopeinverse = Tup->buckets[c+1].slopeinverse;
}
Tup->countEdgeBucket--;
i--;
}
}
}
void updatexbyslopeinv(EdgeTableTuple *Tup){
int i;
for (i=0; i<Tup->countEdgeBucket; i++){
(Tup->buckets[i]).xofymin =(Tup->buckets[i]).xofymin + (Tup-
>buckets[i]).slopeinverse;
}
}
void ScanlineFill(float r,float g,float b)
{
int i, j, x1, ymax1, x2, ymax2, FillFlag = 0, coordCount;
for (i=0; i<maxHt; i++){
for (j=0; j<EdgeTable[i].countEdgeBucket; j++){

Dept. of CSE, DSATM 2021-2022 Page 11


CG Mini-Project MOVING BOAT

storeEdgeInTuple(&ActiveEdgeTuple,EdgeTable[i].buckets[j].
ymax,EdgeTable[i].buckets[j].xofymin,
EdgeTable[i].buckets[j].slopeinverse);
}
removeEdgeByYmax(&ActiveEdgeTuple, i);
insertionSort(&ActiveEdgeTuple);
j = 0;
FillFlag = 0;
coordCount = 0;
x1 = -1;
x2 = -1;
ymax1 = -1;
ymax2 = -1;
while (j<ActiveEdgeTuple.countEdgeBucket){
if (coordCount%2==0){
x1 = (int)(ActiveEdgeTuple.buckets[j].xofymin);
ymax1 = ActiveEdgeTuple.buckets[j].ymax;
if (x1==x2)
{
if (((x1==ymax1)&&(x2!=ymax2))||((x1!=ymax1)&&(x2==ymax2))){
x2 = x1;
ymax2 = ymax1;
}
else{
coordCount++;
}
}
else{
coordCount++;
}
}
else{
x2 = (int)ActiveEdgeTuple.buckets[j].xofymin;
ymax2 = ActiveEdgeTuple.buckets[j].ymax;
FillFlag = 0;
if (x1==x2){
if (((x1==ymax1)&&(x2!=ymax2))||((x1!=ymax1)&&(x2==ymax2))){
x1 = x2;
ymax1 = ymax2;
}
else{
coordCount++;
FillFlag = 1;
}
}
else{

Dept. of CSE, DSATM 2021-2022 Page 12


CG Mini-Project MOVING BOAT

coordCount++;
FillFlag = 1;
}
if(FillFlag){
glColor3f(r,g,b);
midpoint(x1,i,x2,i);
}
}
j++;
}
updatexbyslopeinv(&ActiveEdgeTuple);
}
}
void ScanlineFill(float r,float g,float b,float extra)
{
int i, j, x1, ymax1, x2, ymax2, FillFlag = 0, coordCount;
for (i=0; i<maxHt; i++){
for (j=0; j<EdgeTable[i].countEdgeBucket; j++){
storeEdgeInTuple(&ActiveEdgeTuple,EdgeTable[i].buckets[j].
ymax,EdgeTable[i].buckets[j].xofymin,
EdgeTable[i].buckets[j].slopeinverse);
}
removeEdgeByYmax(&ActiveEdgeTuple, i);
insertionSort(&ActiveEdgeTuple);
j = 0;
FillFlag = 0;
coordCount = 0;
x1 = -1;
x2 = -1;
ymax1 = -1;
ymax2 = -1;
while (j<ActiveEdgeTuple.countEdgeBucket){
if (coordCount%2==0){
x1 = (int)(ActiveEdgeTuple.buckets[j].xofymin);
ymax1 = ActiveEdgeTuple.buckets[j].ymax;
if (x1==x2)
{
if (((x1==ymax1)&&(x2!=ymax2))||((x1!=ymax1)&&(x2==ymax2))){
x2 = x1;
ymax2 = ymax1;
}
else{
coordCount++;
}
}
else{

Dept. of CSE, DSATM 2021-2022 Page 13


CG Mini-Project MOVING BOAT

coordCount++;
}
}
else{
x2 = (int)ActiveEdgeTuple.buckets[j].xofymin;
ymax2 = ActiveEdgeTuple.buckets[j].ymax;
FillFlag = 0;
if (x1==x2){
if (((x1==ymax1)&&(x2!=ymax2))||((x1!=ymax1)&&(x2==ymax2))){
x1 = x2;
ymax1 = ymax2;
}
else{
coordCount++;
FillFlag = 1;
}
}
else{
coordCount++;
FillFlag = 1;
}
if(FillFlag){
glColor4f(r,g,b,extra);
midpoint(x1,i,x2,i);
}
}
j++;
}
updatexbyslopeinv(&ActiveEdgeTuple);
}
}
void drawfig(int a[],int sizei)
{
int count = 0,x1,y1,x2,y2;
int n=0;
while(n!=sizei){
count++;
if (count>2){
x1 = x2;
y1 = y2;
count=2;
}
if (count==1){
x1=a[n];
n++;
y1=a[n];

Dept. of CSE, DSATM 2021-2022 Page 14


CG Mini-Project MOVING BOAT

n++;
}
else{
x2=a[n];
n++;
y2=a[n];
n++;
storeEdgeInTable(x1, y1, x2, y2);
}
}
}
void draw(int a[],int n,float r,float g , float b){
initEdgeTable();
drawfig(a,n);
ScanlineFill(r,g,b);
}
void draw(int a[],int n,float r,float g , float b,float extra){
initEdgeTable();
drawfig(a,n);
ScanlineFill(r,g,b,extra);
}
void plot(int x,int y,int X1,int Y1,float r,float g,float b,float alpha){
glColor4f(r,g,b,alpha);
//glColor3f( 0.80, 0.80,0.80);
glBegin(GL_POINTS);
glVertex2i(x+X1,y+Y1);
glEnd();
}
void midpointcircle(int X1,int Y1,int r,float ra, float g, float b,float xtra){
int x=0;
int y=r;
int decision=1-r;
plot(x,y,X1,Y1,ra,g,b,xtra);
plot(-y,x,X1,Y1,ra,g,b,xtra);
plot(-x,-y,X1,Y1,ra,g,b,xtra);
plot(y,-x,X1,Y1,ra,g,b,xtra);
while(y>x){
if(decision<0){
x++;
decision+=2*x+1;
}
else{
y--;
x++;
decision+=2*(x-y)+1;
}

Dept. of CSE, DSATM 2021-2022 Page 15


CG Mini-Project MOVING BOAT

plot(x,y,X1,Y1,ra,g,b,xtra);
plot(x,-y,X1,Y1,ra,g,b,xtra);
plot(-x, y,X1,Y1,ra,g,b,xtra);
plot(-x, -y,X1,Y1,ra,g,b,xtra);
plot(y, x,X1,Y1,ra,g,b,xtra);
plot(-y, x,X1,Y1,ra,g,b,xtra);
plot(y, -x,X1,Y1,ra,g,b,xtra);
plot(-y, -x,X1,Y1,ra,g,b,xtra);
}
}
void drawcloud(){
if(800+increaseclouds>1024)
increaseclouds=0;
int i,j;
for(j=0;j<2;j++)
for(i=50;i>=0;i--){
midpointcircle(150+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(190+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(110+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(140+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(140+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(160+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(160+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
}
for(j=0;j<2;j++)
for(i=50;i>=0;i--){
midpointcircle(50+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(90+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(10+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(40+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(40+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(60+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(60+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
}
for(j=0;j<2;j++)
for(i=50;i>=0;i--){
midpointcircle(550+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(590+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(510+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(540+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(540+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(560+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(560+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
}
for(j=0;j<2;j++)
for(i=50;i>=0;i--){

Dept. of CSE, DSATM 2021-2022 Page 16


CG Mini-Project MOVING BOAT

midpointcircle(650+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);


midpointcircle(690+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(610+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(640+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(640+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(660+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(660+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
}

for(j=0;j<2;j++)
for(i=50;i>=0;i--){
midpointcircle(850+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(890+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(810+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(840+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(840+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(860+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(860+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
}
for(j=0;j<2;j++)
for(i=50;i>=0;i--){
midpointcircle(950+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(990+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(910+j+increaseclouds,800,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(940+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(940+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(960+j+increaseclouds,820,i,0.852941 ,0.852941 ,0.852941,1.0);
midpointcircle(960+j+increaseclouds,780,i,0.852941 ,0.852941 ,0.852941,1.0);
}
}
void drawsun(){
int i,j;
for(j=0;j<2;j++)
for(i=70;i>=0;i--)
midpointcircle(450+j,850,i,1.0,1.0,0.2,1.0);
}
void island(){
int i,j;
for(j=0;j<2;j++)
for(i=70;i>0;i--){
midpointcircle(650+j,520,i,0.0,1.0,0.0,1.0);
midpointcircle(575+j,520,i,0.0,1.0,0.0,1.0);
midpointcircle(725+j,520,i,0.0,1.0,0.0,1.0);
midpointcircle(805+j,520,i,0.0,1.0,0.0,1.0);
midpointcircle(885+j,520,i,0.0,1.0,0.0,1.0);

Dept. of CSE, DSATM 2021-2022 Page 17


CG Mini-Project MOVING BOAT

midpointcircle(980+j,520,i,0.0,1.0,0.0,1.0);
}
int base[] ={500,550,530,560,1024,560,1024,550,500,550};
draw(base,10,0.91,0.76,0.65);

for(j=0;j<2;j++)
for(i=70;i>0;i--){
midpointcircle(25+j,520,i,0.0,1.0,0.0,1.0);
midpointcircle(150+j,520,i,0.0,1.0,0.0,1.0);
midpointcircle(75+j,520,i,0.0,1.0,0.0,1.0);
midpointcircle(225+j,520,i,0.0,1.0,0.0,1.0);
midpointcircle(275+j,520,i,0.0,1.0,0.0,1.0);
}
int base2[] ={0,550,0,560,320,560,350,550,100,550};
draw(base2,10,0.91,0.76,0.65);
}
void ship(int x,int y)
{
if(440+increase2+y>1024){
increase2=0;
}else{
int i,j;
for(j=0;j<2;j++)
for(i=18;i>=0;i--){
midpointcircle(236+x+j,425+increase2,i,0.752941 ,0.752941 ,0.752941 ,1.0);
midpointcircle(233+x+j,430+increase2,i,0.752941 ,0.752941 ,0.752941 ,1.0);
midpointcircle(239+x+j,430+increase2,i,0.752941 ,0.752941 ,0.752941 ,1.0);
if(i-4>0){
midpointcircle(239+x+j,330+increase2,i-4,0.752941 ,0.752941 ,0.752941
,1.0);
midpointcircle(239+x+j,250+increase2,i-4,0.752941 ,0.752941 ,0.752941
,1.0);
}
}
}
if(440+y+increase2>1024){
increase2=0;
}else{
int i,j;
for(j=0;j<2;j++)
for(i=18;i>=0;i--){
midpointcircle(330+x+j,425+increase2,i,0.752941 ,0.752941 ,0.752941 ,1.0);
midpointcircle(333+x+j,430+increase2,i,0.752941 ,0.752941 ,0.752941 ,1.0);
midpointcircle(327+x+j,430+increase2,i,0.752941 ,0.752941 ,0.752941 ,1.0);
if(i-2>0){

Dept. of CSE, DSATM 2021-2022 Page 18


CG Mini-Project MOVING BOAT

midpointcircle(335+x+j,320+increase2,i-2,0.752941 ,0.752941 ,0.752941


,1.0);
midpointcircle(335+x+j,240+increase2,i-2,0.752941 ,0.752941 ,0.752941
,1.0);
}
}
}
if(440+y+increase2>1024){
increase2=0;
}else{
int i,j;
for(j=0;j<2;j++)
for(i=18;i>=0;i--){
midpointcircle(170+x+j,420+increase2,i,0.752941 ,0.752941 ,0.752941
,1.0);
midpointcircle(173+x+j,425+increase2,i,0.752941 ,0.752941 ,0.752941
,1.0);
midpointcircle(167+x+j,425+increase2,i,0.752941 ,0.752941 ,0.752941
,1.0);
if(i-4>0){
midpointcircle(173+x+j,310+increase2,i-4,0.752941 ,0.752941 ,0.752941
,1.0);
midpointcircle(173+x+j,230+increase2,i-4,0.752941 ,0.752941 ,0.752941
,1.0);
}
}
}
int b[] =
{20+x,240+y,20+x,220+y,82+x,140+y,438+x,84+y,584+x,196+y,600+x,220+y,20+x,24
0+y};
draw(b,14,0.30f,0.06f,0.42f);
int c[] =
{70+x,234+y,70+x,256+y,478+x,262+y,478+x,262+y,478+x,222+y,70+x,238+y,70+x,2
34+y};
draw(c,12,0.70f,0.0f,0.0f);
int m[] =
{70+x,235+y,70+x,256+y,478+x,262+y,478+x,262+y,478+x,222+y,70+x,238+y};
draw(m,10,0.70f,0.0f,0.0f);
int d[] = {90+x,258+y,90+x,280+y,466+x,298+y,466+x,262+y};
draw(d,8,1.0f,1.0f,1.0f);
int e[] =
{90+x,258+y,90+x,280+y,466+x,298+y,466+x,262+y,90+x,258+y};
draw(e,10,1.0f,1.0f,1.0f);
int f[] = {102+x,302+y,102+x,280+y,442+x,298+y,442+x,330+y,102+x,302+y};
draw(f,10,0.3f,0.3f,0.3f);
int n[] = {102+x,302+y,102+x,280+y,442+x,298+y,442+x,330+y};

Dept. of CSE, DSATM 2021-2022 Page 19


CG Mini-Project MOVING BOAT

draw(n,8,0.3f,0.3f,0.3f);
int h[] ={442+x,328+y,442+x,298+y,494+x,294+y,494+x,324+y,442+x,328+y};
draw(h,10,0.4f,0.4f,0.4f);
int i[]={466+x,298+y,466+x,262+y,508+x,256+y,508+x,290+y,466+x,298+y};
draw(i,10,0.8f,0.8f,0.8f);
int j[]={478+x,262+y,478+x,222+y,514+x,220+y,514+x,254+y,478+x,262+y};
draw(j,10,0.5,0.0,0.0);
int k[] ={224+x,312+y,224+x,396+y,254+x,396+y,254+x,315+y,224+x,312+y};
draw(k,10,0.2,0.0,0.0);
int l[]={318+x,322+y,318+x,406+y,358+x,406+y,358+x,320+y,318+x,322+y};
draw(l,10,0.2,0.0,0.0);
int g[]={158+x,304+y,158+x,388+y,188+x,388+y,188+x,310+y,158+x,304+y};
draw(g,10,0.2f,0.0f,0.0f);
}
void ship2(int x,int y){
if(150+x > 1024)
increase=0;
int b[] = {20+x,480,50+x,450,150+x,450,180+x,480,20+x,480};
draw(b,10,0.0,0.0,0.0);
int c[] = {95+x,480,95+x,570,105+x,570,105+x,480,95+x,480};
draw(c,10,0.2,0.0,0.0);
int d[] = {105+x,570,150+x,500,105+x,500,105+x,570};
draw(d,8,1.0,1.0,1.0);
}
void ship3(int x,int y){
if (915 + x < 0){
increase=0;
}
int b[] = {990+x,370,970+x,350,870+x,350,850+x,370,990+x,370};
draw(b,10,0.0,0.0,0.0);
int c[] = {915+x,370,915+x,460,925+x,460,925+x,370,915+x,370};
draw(c,10,0.2,0.0,0.0);
int d[] = {915+x,460,850+x,390,915+x,390,915+x,460};
draw(d,8,1.0,1.0,1.0);
}
void water1(){
int b[]= {0,160,80,160,480,100,1024,100,1024,0,0,0,0,160};
draw(b,14,0.196078f,0.196078f,0.8f,1.0f);
}
void water()
{
int b[] = {80,160,1024,160,1024,100,480,100,80,160};
draw(b,10,0.196078f,0.196078f,0.8f,1.0f);
}
void water2(){
int b[]={0,150,0,550,1024,550,1024,150,0,150};

Dept. of CSE, DSATM 2021-2022 Page 20


CG Mini-Project MOVING BOAT

draw(b,10,0.196078f,0.196078f,0.8f,1.0f);
}
void drawmoon(){
int b[]={0,550,0,1024,1024,1024,1024,550,0,550};
draw(b,10,0.0f,0.0f,0.0f,1.0f);
int i,j;
for(j=0;j<2;j++)
for(i=70;i>=0;i--)
midpointcircle(450+j,850,i,1.0,1.0,1.0,1.0);
}
void init()
{
glClearColor( 0.8,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
glLineWidth(3.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,1024,0,1024);

}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
increase+=2.0;
increase2+=10;
increaseclouds+=2;
if(showclouds==1){
drawmoon();
drawcloud();
}
else{
drawsun();
drawcloud();
}
island();
water();
water2();
ship2(increase,y);
ship3(-increase,y);
ship(pos,y);
water1();
glutPostRedisplay();
glFlush();
glutSwapBuffers();
}
void myKeyboardFunc(unsigned char key, int x, int y )

Dept. of CSE, DSATM 2021-2022 Page 21


CG Mini-Project MOVING BOAT

{
switch(key){
case 'r':
{
if(showclouds==1){
showclouds=0;
}
else{
showclouds=1;
}
glutPostRedisplay();
break;
}
case 'm':{
pos+=2;
glutPostRedisplay();
break;
}
};
}
void processSpecialKeys (int key, int mx, int my) {
switch(key){
case GLUT_KEY_LEFT :
pos-=2.0;
glutPostRedisplay();
break;
case GLUT_KEY_RIGHT :
pos+=2.0;
glutPostRedisplay();
break;
case GLUT_KEY_UP :
break;
case GLUT_KEY_DOWN :
break;
default:
break;
}
}
int main(int argc,char ** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(1024,1024);
glutInitWindowPosition(0,0);
glutCreateWindow("Moving Ship");
glutSwapBuffers();

Dept. of CSE, DSATM 2021-2022 Page 22


CG Mini-Project MOVING BOAT

glutDisplayFunc(display);
glutKeyboardFunc(myKeyboardFunc);
glutSpecialFunc(processSpecialKeys);
glEnable(GL_SMOOTH);
init();
glutMainLoop();
return 0;
}

Dept. of CSE, DSATM 2021-2022 Page 23


CG Mini-Project MOVING BOAT

CHAPTER 6

SCREENSHOTS

6.1 Main Window:

Fig 6.1: This figure shows the main content of the program

Dept. of CSE, DSATM 2021-2022 Page 24


CG Mini-Project MOVING BOAT

6.2 Main Window:

Fig 6.2: This figure shows that main ship moved forward by using keyboard button.

6.3 Main Window:

Fig 6.3: This figure shows that main ship moved backward .

Dept. of CSE, DSATM 2021-2022 Page 25


CG Mini-Project MOVING BOAT

6.4 Night Mode Window:

Fig 6.4: This figure shows that island turned into night mode by clicking
of ”r” letter using keyword function .
6.5 Normal Mode Window:

Fig 6.5: This figure shows that island is in morning mode by clicking
“r”letter in the keyboard .

Dept. of CSE, DSATM 2021-2022 Page 26


CG Mini-Project MOVING BOAT

CHAPTER 7

CONCLUSION AND FUTURE ENHANCEMENT

7.1 Conclusion
The moving boat Graphics package has been developed Using OpenGL. The main idea
of the program is to provide a moving the ship through the keyboard interaction, which
includes forward and backward movement of the main ship. Further, we change the
island from morning mode into night mode through the keyboard buttons.

7.2 Future Enhancement

The project has graphical usage where in different functions which can be applicable in
graphical packages are used. The applications developed so far is in its basic working
stage. There can be more enhancements like

 Designing of a movement of boats and moving the clouds in the sky with complex
interior structures.
 By providing keyboard-based interaction to movement of main ship.
 We can also change the island of the mode from morning to night mode and as
well we can change into return mode.

Dept. of CSE, DSATM 2021-2022 Page 27


CG Mini-Project MOVING BOAT

BIBLIOGRAPHY

BOOKS

 Edward Angel: Interactive Computer Graphics A Top-Down Approach with


OpenGL, 5th Edition, Pearson Education, 2008.
 Donald Hearn and Pauline Baker: Computer Graphics- OpenGL Version, 3rd
Edition, Pearson Education, 2008.
 F.S Hill Jr.: Computer Graphics Using OpenGL, 3rd Edition, PHI, 2009.

WEBSITES

 http://www.opengl.org/resources/libraries/glut
 http://www.opengl.ord
 http://en.wikipedia.org/wiki/opengl

Dept. of CSE, DSATM 2021-2022 Page 28

You might also like