Moving Boat Final Report
Moving Boat Final Report
Moving Boat Final Report
BELGAUM- 590014
A CG Mini-Project Report
On
“MOVING BOAT”
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:
Dr. C. NANDINI
Vice Principal &HOD,Dept of CSE
Examiners:
1:
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 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
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
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
CHAPTER 1
INTRODUCTION
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.
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.
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.
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: -
Cache : 512 KB
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
CHAPTER 4
IMPLEMENTATION
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.
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.
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.
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);
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;
if (x2==x1){
minv=0.000000;
}
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++){
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{
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{
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];
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;
}
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--){
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);
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){
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};
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 )
{
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();
glutDisplayFunc(display);
glutKeyboardFunc(myKeyboardFunc);
glutSpecialFunc(processSpecialKeys);
glEnable(GL_SMOOTH);
init();
glutMainLoop();
return 0;
}
CHAPTER 6
SCREENSHOTS
Fig 6.1: This figure shows the main content of the program
Fig 6.2: This figure shows that main ship moved forward by using keyboard button.
Fig 6.3: This figure shows that main ship moved backward .
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 .
CHAPTER 7
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.
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.
BIBLIOGRAPHY
BOOKS
WEBSITES
http://www.opengl.org/resources/libraries/glut
http://www.opengl.ord
http://en.wikipedia.org/wiki/opengl