CG Mini Project
CG Mini Project
College Name
Department Name
ANALYSIS REPORT
ON
“FOUNTAIN”
BY
Faculty Name
College Logo
College Name
College Address
Department Name
Certificate
This is to certify that, following students
has completed all the Term Work & Practical Work in the subject COMPUTER GRAPHICS
satisfactorily in the department of First Year Engineering as prescribed by Savitribai Phule
Pune University, in the academic year 2023 -2024.
Date: ___/____/____
ACKNOWLEDGEMENT
With due respect and gratitude I take the opportunity to thank those who have Helped me
directly and indirectly. I convey my sincere thanks to Prof.S.N.Shelke HoD computer Dept.
and Prof. F.A.Shaikh for their help in selecting The mini project topic and support. I thank to
my Mini Project guide Prof.F.A.Shaikh for her guidance, timely Help and valuable
suggestions without which this project would not have been. Possible. Her direction has
always been encouraging as well as inspiring for me. Attempts have been made to minimize
the errors in the report. I would also like to express my appreciation and thanks to all my
friends who Knowingly or unknowingly have assisted and encourage me throughout my hard
Work.
TABLE OF CONTENTS
Introduction
Specification & Requirements
Software Design
Implementation
Code
Snapshots
Conclusion & Future Prospect
References
INTRODUCTION
Computer Graphics is concerned with all aspect of producing pictures or image using
computer. The field began humble almost 50 years ago, with the display of few lines on the
cathode-ray tube(CRT); now, we can create image using computer that are indistinguishable
from photographs from the real objects. We routinely train pilots with simulated airplane,
generating graphical display of the virtual environment in the real time. Feature length
movies made entirely by computer have been successful, both critically and financially;
massive multiplayer game can involve tens of thousands of concurrent participants.
Graphics is created using computers and, more generally, the representation and
manipulation of pictorial data by a computer. The development of computer graphics has
made computers easier to interact with and better for understanding and interpreting many
types of data. Developments in computer graphics have had a profound impact on many types
of media and have revolutionized the animation and video game industry. The phrase
“Computer Graphics” was coined in 1960 by William Fetter, a graphic designer for Boeing.
OpenGL has become a widely accepted standard for developing graphics application.
OpenGL is easy to learn, and it possesses most of the characteristics of other popular
graphics system. It is top-down approach. OpenGL 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.
The interface between the application program and the graphics system can be specified
through that set of function that resides in graphics library.
Graphics Editors can normally be classified as:
2D Graphics Editors.
3D Graphics Editors.
A 3D Graphics Editor is used to draw 3D primitives Rectangles, Circle, polygons, etc and
alter those with operations like cut, copy, paste. These may also contain features like layers
and object precision etc.
3D Graphics Editor should include the following features:
Facilities: Cursor Movement, Editing picture objects.
Good User Interface: GUI / Toolbars / Icon based User Interface.
The applications of computer graphics in some of the major areas are as follows
1. Display of information.
2. Design.
4. User interfaces.
OpenGL is a software interface to graphics hardware. This interface consists of about 150
distinct commands that you use to specify the objects and operations needed to produce
interactive three-dimensional applications.
• Implementing certain technical concept like Translation, motion, and use of Idle .
Application
Keyboard
Graphics
program library Drivers Mouse
(API)
Display
SOFTWARE DESIGN
Movement of a drop:
The movement of a drop contains two factors.
The direction, how the drop gets out of the fountain and the gravity. The position of a
drop is pretty easy to compute if we know, how much time has passed since the drop has
leaved the fountain.
We have to multiplicate the vector of the constant moving (how the drop leaves the
fountain) with the time and then subtract the squared time multiplicated with an acceleration
factor. This acceleration factor contains the weight of a drop and the power of gravity. We
now have to know the direction, how the drop comes out of the fountain, but this is just a bit
calculating with sine and cosine.
IMPLEMENTATION
In GetNewPosition (), we calculate the position and delay of each drop with respect to
the coordinate axes.
Then specify a series of ‘for ‘loops to construct the top and bottom of the stone.
rand () function is used to generate random unique numbers, for each time it is executed.
Create fountain drops and vertices. Declare StepAngle, the angle which the ray gets out of
the fountain and RayAngle, the angle you see when you look down on the fountain. Use sine
() and cosine () functions inside for loops, to calculate the speed of each step in the fountain,
Step 4: [Displaying]
[Keyboard function]
[Display function]
GlPushMatrix (), glPopMatrix () — to push and pop the current matrix stack.
Here we specify the initial display mode, window size and position. Create a new window
where the output is rendered. Create menus to move near, move away, move down, move up
and sub-menus for color, flow, level, and help.
SNAPSHOTS
An attempt has been made to develop an OpenGL package which meets necessary
requirements of the user successfully. Since it is user friendly, it enables the user to interact
efficiently and easily.
The development of the mini project has given us a good exposure to OpenGL by which
we have learnt some of the technique which help in development of animated pictures,
gaming.
Hence it is helpful for us even to take up this field as our career too and develop some
other features in OpenGL and provide as a token of contribution to the graphics world.
• www.OpenGL Redbook.
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
#define PI 3.14152653597689786
#define RandomFactor 2.0
#define ESCAPE 27
#define TEXTID
3 unsigned int i;
int flag=0,f=2;
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];
GLint ListNum;
GLfloat OuterRadius = 2.4;
GLfloat InnerRadius = 2.0;
GLint NumOfVerticesStone = 6;
GLfloat StoneHeight = 0.5;
GLfloat WaterHeight = 0.45;
struct SVertex
{
GLfloat x,y,z;
};
class
CDrop {
private
:
GLfloat time;
SVertex ConstantSpeed;
GLfloat AccFactor;
public:
void SetConstantSpeed (SVertex NewSpeed);
void SetAccFactor(GLfloat NewAccFactor);
void SetTime(GLfloat NewTime); void
GetNewPosition(SVertex * PositionVertex);
}
;
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer( 3,
GL_FLOAT,
0,
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;
}
void DrawFountain(void)
{ if(flag==0)
glColor3f(1,1,1);
else if(flag==1)
glColor3fv(X); else
if(flag==2)
glColor3f(0.0,1.0,0
.0); else
glColor3f(0.0,1.0,1
.0);
glutPostRedisplay
();
} } else if(f==1)
{ if(key=='b'||
key=='B') f=0;
else f=3;
glutPostRedisplay(
);
}
else if(f==2)
{ f=0;
} else { switch ( key ) { case ESCAPE :
printf("Thank You\nAny Suggestions??????\n\n\
n"); exit(0); break; case 't': case 'T':
vflag=3; glutPostRedisplay(); break; case
'f': case 'F': vflag=33; glutPostRedisplay();
break; case 'd': case 'D': vflag=2;
glutPostRedisplay(); break; case 'u': case
'U': vflag=22; glutPostRedisplay(); break;
case 'a': case 'A': vflag=1;
glutPostRedisplay(); break; case 'n': case
'N':
vflag=11;
glutPostRedispla
y(); break;
case 'b': case
'B': f=0;
glutPostRedispla
y(); break;
case 'h': case
'H': f=1;
glutPostRedispla
y(); break;
default:
break; }
}
}
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)
{
zt-=0.06; }
glTranslatef(xt,yt,
zt); if(vflag==11)
{ zt+=0.06; }
glTranslatef(xt,yt,
zt); if(vflag==2)
{ yt -= 0.05; }
glTranslatef(xt,yt,
zt); if(vflag==22)
{ yt += 0.05; }
glTranslatef(xt,yt,
zt); if(vflag==3) {
if(xangle<=80.0)
xangle += 5.0;
} if(vflag==33)
{ 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();
glFlush();
glutSwapBuffers();
} 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);
DrawTextXY(-2.7,3.5,0.0,0.003," FOUNTAIN ");
glColor3f(0.6,0.8,0.7);
DrawTextXY(-1.25,2.4,0.0,0.0014," MENU ");
glColor3f(1.0,0.8,0.4);
DrawTextXY(-1.25,2.1,0.0,0.001," 1 : PROCEED ");
DrawTextXY(-1.25,1.9,0.0,0.001," 2 : HELP ");
DrawTextXY(-1.25,1.7,0.0,0.001," 3 : EXIT
"); DrawTextXY(-1.25,1.5,0.0,0.001," 4 :
BACK"); glFlush(); 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);
DrawTextXY(-2.7,3.5,0.0,0.003," HELP ");
glColor3f(1.0,0.8,0.4);
DrawTextXY(-1.75,2.4,0.0,0.0014," Keyboard Controls : ");
glColor3f(0.9,0.8,0.9);
DrawTextXY(-1.25,2.1,0.0,0.001," Move Near -> N ");
DrawTextXY(-1.25,1.9,0.0,0.001," Move Away -> A ");
DrawTextXY(-1.25,1.5,0.0,0.001," Move Up -> U "); DrawTextXY(-
1.25,1.3,0.0,0.001," Move Down -> D ");
DrawTextXY(-1.25,0.9,0.0,0.001," Top View -> T ");
DrawTextXY(-1.25,0.7,0.0,0.001," Front View -> F ");
DrawTextXY(-1.25,0.3,0.0,0.001," Open HELP -> H "); DrawTextXY(-
1.25,0.1,0.0,0.001," Open MENU -> B "); glColor3f(0.9,0.9,0.8);
DrawTextXY(1,-0.4,0.0,0.001," Press any KEY ...
"); glFlush(); glutSwapBuffers();
} void
cover()
{
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);
DrawTextXY(-1.7,3.5,0.0,0.001," GRAPHICAL IMPLEMENTATION OF ");
glColor3f(0.6,0.8,0.7);
DrawTextXY(-1.75,3,0.0,0.0014," FLOWING FOUNTAIN ");
glColor3f(0.7,0.6,0.1);
DrawTextXY(-3.25,1.5,0.0,0.0007," Submitted by :- ");
glColor3f(1.0,0.5,0.0);
DrawTextXY(-2.5,1.2,0.0,0.001," EATI TIWARI ");
DrawTextXY(1,1.2,0.0,0.001," ESHITA TICKU ");
glColor3f(0.7,0.8,0.6);
DrawTextXY(-2.5,0.95,0.0,0.001," (1CE08CS021) ");
DrawTextXY(1,0.95,0.0,0.001," (1CE08CS022) ");
glColor3f(0.7,0.6,0.1);
DrawTextXY(-1.25,0,0.0,0.0007," Under the guidance of : ");
glColor3f(1.0,0.8,0.4);
DrawTextXY(-1.25,-.2,0.0,0.001," MR MUKESH KAMATH");
DrawTextXY(-1,-.5,0.0,0.0007," Lecturer,Dept. of CSE ");
DrawTextXY(-1,-.7,0.0,0.001," CITY ENGINEERING COLLEGE");
glColor3f(0.3,0.3,0.3);
DrawTextXY(-1,-1,0.0,0.0008," Press any key... ");
glFlush();
glutSwapBuffers();
} void
Dis()
{ if(f==0
)
menu1();
else
if(f==1)
menu2();
else
if(f==2)
cover();
else
Display(
); }
void Reshape(int x, int y)
{
if (y == 0 || x == 0) return;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50.0,(GLdouble)x/
(GLdouble)y,0.10,20.0); glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y); glPointSize(GLfloat(x)/600.0);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
printf("KeyboardControls\n"); printf("'x'-
topview\n"); printf("'d'-movedown\n");
printf("'u'-moveup\n"); printf("'a'-moveaway\
n"); printf("'n'-movenear\n");
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB |
GLUT_DEPTH); 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_menu2=glutCreateMenu(flow);
glutAddMenuEntry("LOW",8);
glutAddMenuEntry("MEDIUM",10);
glutAddMenuEntry("HIGH",20); int
sub_menu3=glutCreateMenu(level);
glutAddMenuEntry("3 LEVELS",3);
glutAddMenuEntry("4 LEVELS",4);
glutAddMenuEntry("5 LEVELS",5); int
sub_menu4=glutCreateMenu(help);
glutAddMenuEntry("KEYBOARD
CONTROLS:",0); glutAddMenuEntry("Move
Near: n",1); glutAddMenuEntry("Move
Away: a",2); glutAddMenuEntry("Move
Down: d",3); glutAddMenuEntry("Move
Up: u",4);
glutAddMenuEntry("Vertical 360:
x",5); glutAddMenuEntry("EXIT",6);
glutCreateMenu(CMain);
glutAddSubMenu("Colors",sub_menu);
glutAddSubMenu("Help",sub_menu4);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutIdleFunc(Dis); glutMainLoop();
return 0;
}
• www.OpenGL Redbook.