#include<stdio.h>
#include<GL/glut.h>
#include<stdlib.h>
GLfloat v[3][24]={{100.0,300.0,350.0,50.0,100.0,120.0,120.0,100.0,260.0,280.0,
280.0,260.0,140.0,160.0,160.0,140.0,180.0,200.0,200.0,180.0,
220.0,240.0,240.0,220.0},{100.0,100.0,200.0,200.0,160.0,
160.0,180.0,180.0,160.0,160.0,180.0,180.0,160.0,160.0,180.0,
180.0,160.0,160.0,180.0,180.0,160.0,160.0,180.0,180.0},
{1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0}};
GLfloat v1[3][16]={{50.0,350.0,350.0,50.0,100.0,300.0,300.0,100.0,125.0,175.0,
175.0,125.0,225.0,275.0,275.0,225.0},{200.0,200.0,210.0,
210.0,210.0,210.0,240.0,240.0,240.0,240.0,310.0,310.0,240.0,
240.0,310.0,310.0},{1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,
1.0,1.0,1.0,1.0,1.0,1.0}};
GLfloat colors[4][3]={{0.0,0.0,1.0},{0.9961,0.9961,0.65625},{1.0,0.0,1.0},
{1.0,.0,1.0}};
static float q,w,e;
static float fq,fw,fe;
static GLfloat wa=0,wb=0,wc=0,ba,bb,bc;
int flag;
void myinit(void)
{
glClearColor(0.506,.7,1,0.0);
glPointSize(2.0);
glLoadIdentity();
glOrtho(0.0,499.0,0.0,499.0,-300.0,300.0);
}
void draw_top_boxes(GLint i,GLint j)
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_POLYGON);
glColor3fv(colors[j]); // to draw the boat
glVertex2f(v1[0][i+0],v1[1][i+0]);
glColor3fv(colors[j+1]);
glVertex2f(v1[0][i+1],v1[1][i+1]);
glColor3fv(colors[j+2]);
glVertex2f(v1[0][i+2],v1[1][i+2]);
glColor3fv(colors[j+3]);
glVertex2f(v1[0][i+3],v1[1][i+3]);
glEnd();
}
void draw_polygon(GLint i)
{
glBegin(GL_POLYGON); // to draw the boat
glColor3f(0.0,0.0,0.0);
glColor3fv(colors[0]);
glVertex2f(v[0][i+0],v[1][i+0]);
glColor3fv(colors[1]);
glVertex2f(v[0][i+1],v[1][i+1]);
glColor3fv(colors[2]);
glVertex2f(v[0][i+2],v[1][i+2]);
glColor3fv(colors[3]);
glVertex2f(v[0][i+3],v[1][i+3]);
glEnd();
}
void draw_boat()
{
draw_polygon(0);
draw_polygon(4);
draw_polygon(8);
draw_polygon(12);
draw_polygon(16);
draw_polygon(20);
draw_top_boxes(0,0);
draw_top_boxes(4,0);
draw_top_boxes(8,0);
draw_top_boxes(12,0);
glFlush();
glPopMatrix();
glPopMatrix();
}
void draw_water()
{
GLfloat i;
GLfloat x=0,y=103,j=0;
GLfloat k;
glPushMatrix();
glTranslatef(wa,wb,wc);
glPushMatrix();
glColor3f(0,0,1);
for(k=y;k>0;k-=6)
{
for(i=1;i<30;i++)
{
glBegin(GL_LINES);
glVertex2f(j,k);
glVertex2f(j+10,k);
glEnd();
j=j+20;
}
j=0;
}
glPopMatrix();
glPopMatrix();
}
void draw_fishes()
{
glPushMatrix();
glTranslatef(fq,12.0,fe);
glPushMatrix();
glColor3f(.99609375,0.2578125,0.2578125);
glBegin(GL_TRIANGLES);
glVertex2f(100,80);
glVertex2f(100,60);
glVertex2f(85,70);
glEnd();
glColor3f(.99609375,0.2578125,0.2578125);
glBegin(GL_TRIANGLES);
glVertex2f(100,70);
glVertex2f(110,75);
glVertex2f(110,65);
glEnd();
glColor3f(0,0,0);
glBegin(GL_POINTS);
glVertex2f(90,71);
glEnd();
glColor3f(.99609375,0.2578125,0.2578125);
glBegin(GL_TRIANGLES);
glVertex2f(200,80);
glVertex2f(200,60);
glVertex2f(185,70);
glEnd();
glColor3f(.99609375,0.2578125,0.2578125);
glBegin(GL_TRIANGLES);
glVertex2f(200,70);
glVertex2f(210,75);
glVertex2f(210,65);
glEnd();
glColor3f(0,0,0);
glBegin(GL_POINTS);
glVertex2f(190,71);
glEnd();
glPopMatrix();
glPopMatrix();
glFlush();
}
void draw_cloud()
{
GLfloat m=100,n=400,o=10;
for(int i=0;i<7;i++)
{
glPushMatrix();
glColor3f(1.0,1.0,1.0);
if(i==1)
glTranslated(125,415,10);
else if(i==3||i==5)
glTranslated(m,n+5,o);
else
glTranslated(m,n,o);
glutSolidSphere(20.0,5000,150);
glPopMatrix();
m+=10;
}
}
void draw_square()
{
glColor3f(0,0.5,0.996);
glBegin(GL_POLYGON);
glVertex2f(0,0);
glVertex2f(1000,0);
glVertex2f(0,300);
glVertex2f(1000,300);
glEnd();
glFlush();
}
void draw_brotate()
{
glPushMatrix();
glColor3f(0.96,0.5,0.25); //to draw body of the bird
glTranslated(300,400,10);
glScalef(3,1,1);
glutSolidSphere(6,50000,15);
glPopMatrix();
glPushMatrix();
glTranslated(323,400,10);
glutSolidSphere(5,50000,15);
glPopMatrix();
glColor3f(0,0,0);
glBegin(GL_POINTS);
glVertex2f(325,401);
glEnd();
glColor3f(0.96,0.5,0.25); //to draw wings
glBegin(GL_LINES);
glVertex2f(294,394);
glVertex2f(286,389);
glEnd();
glBegin(GL_LINES);
glVertex2f(286,389);
glVertex2f(295,391);
glEnd();
glBegin(GL_LINES);
glVertex2f(295,391);
glVertex2f(285,385);
glEnd();
glBegin(GL_LINES);
glVertex2f(285,385);
glVertex2f(309,395);
glEnd();
glBegin(GL_LINES);
glVertex2f(294,406);
glVertex2f(286,411);
glEnd();
glBegin(GL_LINES);
glVertex2f(286,411);
glVertex2f(295,409);
glEnd();
glBegin(GL_LINES);
glVertex2f(295,409);
glVertex2f(285,415);
glEnd();
glBegin(GL_LINES);
glVertex2f(285,415);
glVertex2f(309,406);
glEnd();
glColor3f(0.96,0.5,0.25);
}
void draw_bird()
{
GLfloat x=200,y=400,z=10;
draw_brotate();
glBegin(GL_LINES); //draw legs of the bird
glVertex2f(285,402);
glVertex2f(275,402);
glEnd();
glBegin(GL_LINES);
glVertex2f(285,398);
glVertex2f(275,398);
glEnd();
glBegin(GL_LINES);
glVertex2f(275,402);
glVertex2f(270,405);
glEnd();
glBegin(GL_LINES);
glVertex2f(275,402);
glVertex2f(270,398);
glEnd();
glBegin(GL_LINES);
glVertex2f(275,398);
glVertex2f(273,400);
glEnd();
glBegin(GL_LINES);
glVertex2f(275,398);
glVertex2f(270,395);
glEnd();
glBegin(GL_LINES);
glVertex2f(323,405);
glVertex2f(323,407);
glEnd();
glPushMatrix();
glTranslatef(323,409,10);
glutSolidSphere(2,200,20);
glPopMatrix();
glBegin(GL_TRIANGLES);
glVertex2f(328,400);
glVertex2f(331,397);
glVertex2f(327,398.5);
glEnd();
glFlush();
}
void drawstars()
{
glColor3f(1.0,1.0,1.0);
glBegin(GL_POINTS);
glVertex3f(300.0,400.0,10.0);
glVertex3f(200,400.0,10.0);
glVertex3f(150,450.0,10.0);
glVertex3f(100,470.0,10.0);
glVertex3f(50,450.0,10.0);
glVertex3f(50,350.0,10.0);
glVertex3f(90,365.0,10.0);
glVertex3f(350,450.0,10.0);
glVertex3f(275,470.0,10.0);
glVertex3f(280,430.0,10.0);
glVertex3f(250,400.0,10.0);
glVertex3f(450,450.0,10.0);
glVertex3f(430,430.0,10.0);
glVertex3f(430,470.0,10.0);
glVertex3f(300,450.0,10.0);
glVertex3f(265,380.0,10.0);
glVertex3f(235,450.0,10.0);
glEnd();
}
void draw_all()
{
glClear(GL_COLOR_BUFFER_BIT);
if(flag==0)
{
glDisable(GL_LIGHTING); //immp one
draw_square();
draw_cloud();
glClearColor(0.506,.7,1,0.0);
glTranslatef(q,w,e);
glPushMatrix();
glColor3f(1.0,0.0,0.0);
draw_boat();
draw_fishes();
glPushMatrix();
glColor3f(1.0,1.0,0.0);
glTranslated(400,400,10);
glutSolidSphere(20.0,5000,150);
glPopMatrix();
}
if(flag==1)
{
glDisable(GL_LIGHTING); //imp one
draw_square();
draw_cloud();
glClearColor(0.9960,0.7070,0.3164,0.0);
glTranslatef(q,w,e);
glPushMatrix();
glColor3f(1.0,0.0,0.0);
draw_boat();
draw_fishes();
glPushMatrix();
glColor3f(1.0,1.0,0.0);
glTranslated(400,400,10);
glutSolidSphere(20.0,500,100);
glPopMatrix();
}
if(flag==2)
{
// just try and change values in these arrays, specially the position array
drawstars();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// GLfloat emission[]={0.1,0.1,0.1,0.0};
GLfloat diffuse[] = { 0.40, 0.40,0.40, 1.0 };
GLfloat ambiance[] = { 0.5, 0.5,0.5, 1.0 };
GLfloat specular[] = { 1.3, 1.3,.3, 1.0 };
GLfloat intensity[]={500.0};
GLfloat position[] = { 10,30,-30,1.0 };
glLightfv (GL_LIGHT0, GL_POSITION, position);
glLightfv (GL_LIGHT0, GL_DIFFUSE,diffuse);
glLightfv (GL_LIGHT0, GL_AMBIENT,ambiance);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE);
glLightfv (GL_LIGHT0, GL_SPECULAR,specular);
glLightfv (GL_LIGHT0, GL_INTENSITY,intensity);
glColor3f(0,0.5,0.996);
glBegin(GL_POLYGON);
glVertex2f(0,0);
glVertex2f(1000,0);
glVertex2f(0,150);
glVertex2f(1000,150);
glEnd(); glTranslatef(q,w,e);
glPushMatrix();
glColor3f(1.0,0.0,0.0);
draw_boat();
draw_fishes();
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);
draw_cloud();
glClearColor(0.0,0.0,0.0,0.0);
glPushMatrix();
glColor3f(1.0,1.0,1.0);
glTranslated(400,400,10);
glutSolidSphere(20.0,500,100);
glPopMatrix();
glColor3f(1.0,1.0,1.0);
glBegin(GL_POINTS);
glVertex3f(300.0,400.0,10.0);
glEnd();
}
glPushMatrix();
glTranslatef(ba,bb,bc);
glPushMatrix();
draw_bird();
glPopMatrix();
glPopMatrix();
GLfloat i;
glPushMatrix();
GLfloat x=0,y=100,j=0;
int k;
//draw_water();
q+=25;
fq-=3.5;
if(q>=440.0) //470
q=-390.0; //400
if(fq<=-300) //500
fq=400.0; //400
wa-=1;
if(wa<=(-20))
wa=-0.5;
ba+=6;
if(ba>=500)
ba=-400;
glFlush();
glutSwapBuffers();
}
void display(void)
{
draw_all();
}
void color_menu(int id)
{
switch(id)
{
case 1: flag=0;break;
case 2: flag=1;break;
case 3: flag=2;break;
case 4: exit(0);
break;
}
glutPostRedisplay();
}
void main_menu(int id)
{
switch(id)
{
case 1: break;
case 2:exit(0);break;
glutPostRedisplay();
}
}
int main(int argc,char **argv)
{
int sub_menu;
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
glutInitWindowSize(1000,1000);
glutInitWindowPosition(0,0);
glutCreateWindow("Ship");
sub_menu=glutCreateMenu(color_menu);
glutAddMenuEntry("Morning",1);
glutAddMenuEntry("Evening",2);
glutAddMenuEntry("Night",3);
glutAddMenuEntry("Quit",4);
glutCreateMenu(main_menu);
glutAddSubMenu("View",sub_menu);
glutAddMenuEntry("Quit",2);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutDisplayFunc(display);
glutIdleFunc(display);
myinit();
glutMainLoop();
glFlush();
}