Graphics Project Report
Graphics Project Report
Graphics Project Report
Technology
PROJECT REPORT
Subject Name
COMPUTER GRAPHICS
Project Name
FLOWING FOUNTAIN
Group Members
Shamook Saad (17-ARID-1572)
Talha Malik (17-ARID-1539)
Muhammad Hamza (17-ARID-1513)
Bilal Rafique (17-ARID-1462)
Submitted to: M.NADEEM
TABLE OF CONTENTS
1. INTRODUCTION TO PROJECT
2. CODE
3. OUTPUT PICTURES
4. REFERENCE
INTRODUCTION TO PROJECT:
Everyone likes the fountains, so today I am going to
present OpenGL Projects using c++ on it. In the
perspective of computer graphics creating the
fountain is a uphill task. There is need of many
items in the project design either it's holding the
water, the flow of water and the water reservoir.
Rendering these is tough task to make fountain look
real. Most important point is to take care of rise of
water upward, it's angle of falling in parabolic
fashion.
Some Great Features
There are 2 Page with callback for each help
Page and the Project Page.
View Defined in the Project - Top and Front.
Keyboard Users is added to this Project.
Keyboard Control (Mentioned in Help
Page)
Key Function
n Move Near
a Move Away
u Move Up
d Move Down
t Top View
f Front View
h Open HELP
b Open MENU
CODE:
#include<windows.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdio.h>
#include <string.h>
#include <iostream>
#define PI 3.14152653597689786
#define ESCAPE 27
#define TEXTID 3
unsigned int i;
int flag=0,f=0;
int vflag=0;
GLfloat xt=0.0,yt=0.0,zt=0.0;
GLfloat xangle=0.0,yangle=0.0,zangle=0.0;
GLfloat X[3];
struct SVertex
GLfloat x,y,z;
};
///////////////////////////////fountain///////////////////////////////////
class CDrop
private:
GLfloat time;
SVertex ConstantSpeed;
GLfloat AccFactor;
public:
};
ConstantSpeed = NewSpeed;
AccFactor = NewAccFactor;
}
time = NewTime;
SVertex Position;
time += 0.15;
PositionVertex->x = Position.x;
PositionVertex->z = Position.z;
CDrop * FountainDrops;
SVertex * FountainVertices;
GLint Steps = 6; //a fountain has several steps, each with its own height
void CreateList(void)
ListNum = glGenLists(1);
glNewList(ListNum, GL_COMPILE);
glBegin(GL_QUADS);
//ground quad:
glColor3ub(0,110,0);
glVertex3f(-OuterRadius*10.0,0.0,OuterRadius*10.0);
glVertex3f(-OuterRadius*10.0,0.0,-OuterRadius*10.0);
glVertex3f(OuterRadius*10.0,0.0,-OuterRadius*10.0);
glVertex3f(OuterRadius*10.0,0.0,OuterRadius*10.0);
//stone:
if (j == 1) glColor3f(1.3,0.5,1.2);
if (j == 2) glColor3f(0.4,0.2,0.1);
glVertex3fv(&Vertices[i+NumOfVerticesStone*j].x);
glVertex3fv(&Vertices[i].x);
glVertex3fv(&Vertices[i+1].x);
glVertex3fv(&Vertices[i+NumOfVerticesStone*j+1].x);
glVertex3fv(&Vertices[i+NumOfVerticesStone*j].x);
glVertex3fv(&Vertices[i].x);
glVertex3fv(&Vertices[0].x);
glVertex3fv(&Vertices[NumOfVerticesStone*j].x);
glEnd();
//The "water":
glBegin(GL_POLYGON);
glVertex3fv(&Vertices[i+NumOfVerticesStone].x);
glColor3ub(30,144,255);
glEnd();
glEndList();
void InitFountain(void)
{
SVertex NewSpeed;
GLfloat TimeNeeded;
GLfloat StepAngle; //Angle, which the ray gets out of the fountain with
GLfloat RayAngle; //Angle you see when you look down on the fountain
GLint i,j,k;
* GLfloat(k) / (Steps-1) +
GetRandomFloat(0.2+0.8*(Steps-k-1)/(Steps-1));
//Calculate how many steps are required, that a drop comes out and
falls down again
FountainDrops[i+j*DropsPerRay+k*DropsPerRay*RaysPerStep].SetConstantSpeed ( NewSpeed );
FountainDrops[i+j*DropsPerRay+k*DropsPerRay*RaysPerStep].SetAccFactor (DropAccFactor);
FountainDrops[i+j*DropsPerRay+k*DropsPerRay*RaysPerStep].SetTime(TimeNeeded * i /
DropsPerRay);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer( 3, //x,y,z-components
FountainVertices);
void randcolor()
GLint a,b,c;
a=rand()%101;
b=rand()%101;
c=rand()%101;
X[0]=(GLfloat)a/100.0;
X[1]=(GLfloat)b/100.0;
X[2]=(GLfloat)c/100.0;
//glColor3f(A,B,C);
void DrawFountain(void)
if(flag==0)
glColor3f(1,1,1);
else if(flag==1)
glColor3fv(X);
//randcolor();
else if(flag==2)
glColor3f(0.0,1.0,0.0);
else
glColor3f(0.0,1.0,1.0);
FountainDrops[i].GetNewPosition(&FountainVertices[i]);
glDrawArrays( GL_POINTS,
0,
DropsComplete);
glutPostRedisplay();
}
void colours(int id)
flag=id;
if(flag==1)
randcolor();
glutPostRedisplay();
RaysPerStep=id;
glutPostRedisplay();
Steps=id;
glutPostRedisplay();
glutPostRedisplay();
}
//key board functions
switch ( key )
case 13:
glutPostRedisplay();
if(key=='b'||key=='B')
f=0;
else
f=3;
glutPostRedisplay();
{ f=0;
}
else // funtain page
switch ( key )
case ESCAPE :
exit(0);
break;
glutPostRedisplay();
break;
glutPostRedisplay();
break;
glutPostRedisplay();
break;
vflag=22; // Move up
glutPostRedisplay();
break;
case 'a': case 'A':
glutPostRedisplay();
break;
glutPostRedisplay();
break;
f=0;
glutPostRedisplay();
break;
f=1;
glutPostRedisplay();
break;
default:
break;
}//end of else
{
int i;
glPushMatrix();
glTranslatef(x,y,z);
glScalef(scale,scale,scale);
glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN,s[i]);
// glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,s[i]);
glPopMatrix();
void Display(void)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glClearColor(0,0,100,1.0);
glTranslatef(0.0,0.0,-6.0);
glTranslatef(0.0,-1.3,0.0);
if(vflag==1) //far
zt-=0.06;
glTranslatef(xt,yt,zt);
if(vflag==11) //near
{
zt+=0.06;
glTranslatef(xt,yt,zt);
if(vflag==2) //down
yt -= 0.05;
glTranslatef(xt,yt,zt);
if(vflag==22) //up
yt += 0.05;
glTranslatef(xt,yt,zt);
if(vflag==3) //angular
if(xangle<=80.0)
xangle += 5.0;
if(vflag==33)
{ //angular
if(xangle>=-5)
xangle -= 5.0;
}
glColor3f(1.0,0.0,0.0);
glRotatef(xangle,1.0,0.0,0.0);
vflag=0;
glRotatef(45.0,0.0,1.0,0.0);
glPushMatrix();
glCallList(ListNum);
glPopMatrix();
DrawFountain();
//display menu
void menu1()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glClearColor(0,0,0,0.0);
glTranslatef(0.0,0.0,-6.0);
glTranslatef(0.0,-1.3,0.0);
glColor3f(1.00,0.20,0.10);
glLoadName(TEXTID);
glColor3f(0.6,0.8,0.7);
glColor3f(1.0,0.8,0.4);
DrawTextXY(-1.25,2.1,0.0,0.001," 1 : PROJECT");
DrawTextXY(-1.25,1.5,0.0,0.001," 4 : BACK");
glutSwapBuffers();
void menu2()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glClearColor(0,0,0,1.0);
glTranslatef(0.0,0.0,-6.0);
glTranslatef(0.0,-1.3,0.0);
glColor3f(0.6,0.8,0.7);
glColor3f(1.0,0.8,0.4);
glColor3f(0.9,0.8,0.9);
glColor3f(0.9,0.9,0.8);
glutSwapBuffers();
}
void Dis()
if(f==0)
menu1();
else if(f==1)
menu2();
else
Display();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50.0,(GLdouble)x/(GLdouble)y,0.10,20.0);
glMatrixMode(GL_MODELVIEW);
glPointSize(GLfloat(x)/600.0);
{
//int zxc;
glutInit(&argc, argv);
printf("KeyboardControls\n");
printf("'t'-topview\n");
printf("'d'-movedown\n");
printf("'u'-moveup\n");
printf("'a'-moveaway\n");
printf("'n'-movenear\n");
glutInitWindowSize(1024,768);
glutInitWindowPosition(0,0);
glutCreateWindow("Fountain");
glEnable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
glLineWidth(2.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
InitFountain();
CreateList();
glutDisplayFunc(Dis);
glutReshapeFunc(Reshape);
glutKeyboardFunc(NormalKey);
int sub_menu=glutCreateMenu(colours);
glutAddMenuEntry("RANDOM",1)
glutAddMenuEntry("GREEN",2);
glutAddMenuEntry("BLUE",3);
int sub_menu4=glutCreateMenu(help);
glutAddMenuEntry("KEYBOARD CONTROLS:",0);
glutAddMenuEntry("EXIT",6);
glutCreateMenu(CMain);
glutAddSubMenu("Colors",sub_menu);
glutAddSubMenu("Help",sub_menu4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutIdleFunc(Dis);
glutMainLoop();
return 0;
}
OUTPUT PICTURES:
REFERENCE: https://www.openglprojects.in/2014/04/flowing-fountain-opengl-
projects-using-c.html#gsc.tab=0