1.1 Computer Graphics:: Flowing Fountain

Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

Flowing Fountain

CHAPTER 1

INTRODUCTION

1.1 COMPUTER GRAPHICS:

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.

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.

The graphics in openGL provides a wide variety of built-in function. The computer graphics
remains one of the most exciting and rapidly growing computer fields. It has become a common
element in user interface, data visualization, TV commercials, motion picture and many other
applications. The current trend of computer graphics is to incorporate more physics principles into

Dept. of CSE,CEC 2010-2011 Page 1


Flowing Fountain

3D graphics algorithm to better simulate the complex interactions between objects and lighting
environment.

1.2 OPEN GL (Open Graphics Library):


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.

OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992 and is widely used in CAD,
virtual reality, scientific visualization, information visualization, and flight simulation. It is also
used in video games, where it competes with Direct3D on Microsoft Windows platforms.

The interface between the application program and the graphics system can be specified
through that set of function that resides in graphics library. The specification is called the
APPLICATION PROGRAM INTERFACE (API). The application program sees only the API and
is thus shielded from the details both the hardware and software implementation of graphics
library. The software driver is responsible for interpreting the output of an API and converting
these data to a form that is understood by the particular hardware.

Most of our applications will be designed to access openGL directly through functions in three
libraries. Function in the main GL library have name that begin with the letter gl and stored in the
library. The second is the openGL utility Library (GLU). This

library uses only GL function but contains codes for creating common object and viewing.
Rather then using an different library for each system we used available library called openGL
utility toolkit (GLUT). It used as #include<glut.h>

Dept. of CSE,CEC 2010-2011 Page 2


Flowing Fountain

A graphics editor is a computer program that allows users to compose and edit pictures
interactively on the computer screen and save them in one of many popular “bitmap” or “raster” a
format such as TIFF, JPEG, PNG and GIF.

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.

Computer Graphics is concerned with all aspects of producing pictures or images using a
computer. A particular graphics software system called OpenGL, which has become a widely
accepted standard for developing graphics applications .

The applications of computer graphics in some of the major areas are as follows

1. Display of information.

2. Design.

3. Simulation and Animation.

4. User interfaces.

Dept. of CSE,CEC 2010-2011 Page 3


Flowing Fountain

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.

My project named “FLOWING FOUNTAIN MODEL” uses OpenGL software interface and
develops 2D images. This project uses the techniques like Translation, motion, display list,
transformation techniques, etc.

1.3 PROBLEM SECTION STATEMENT


Computer graphics is no longer a rarity. It is an integral part of all computer user interfaces,
and is indispensable for visualizing 2D; 3D and higher dimensional objects .Creating 3D objects,
rotations and any other manipulations are laborious process with graphics implementation using
text editor. OpenGL provides more features for developing 3D objects with few lines by built in
functions.

The geometric objects are the building blocks of any individual .Thereby developing,
manipulating, applying any transformation, rotation, scaling on them is the major task of any
image development.

Thereby we have put our tiny effort to develop 3D objects and perform different operations on
them by using OpenGL utilities.

1.4 EXISTING SYSTEM

The existing system involves computer graphics. Computer graphics started with the display of
data on hardcopy plotters and cathode ray tube screens soon after the introduction of computer
themselves. It includes the creation, storage and manipulation of models and images of objects.

These models include physical , mathematical , engineering , architectural and so on


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 keyboard,
mouse or touch-sensitive panel on the screen.
Interactive computer graphics is the most important means of producing pictures since the
invention of photography and television.

Dept. of CSE,CEC 2010-2011 Page 4


Flowing Fountain

1.5 PROPOSED SYSTEM

In proposed system, the OpenGL is a graphic software system designed as a streamlined,


hardware-independent interface to be implemented on many different hardware platforms. To
achieve these qualities, no commands for performing windowing tasks or obtaining user input are
included in OpenGL; instead, you must work through whatever windowing system controls the
particular hardware you're using.

OpenGL doesn't provide high-level commands for describing models of three-dimensional


objects. Such commands might allow you to specify relatively complicated shapes such as
automobiles, parts of the body, airplanes, or molecules. With OpenGL, you must build up your
desired model from a small set of geometric primitives - points, lines, and polygons.

Keyboard

Application
Applicatio Graphics
nprogram
program library Drivers Mouse
(API)

Display

Fig1.1: Application programmers model of graphics system

The interface between an application program and a graphics system can be specified through
a set of functions the resides in a graphics library .These specification are called the application
programmer’s interface (API).The application programmer see only the API and is thus shielded
from the details of both the hardware and the

Dept. of CSE,CEC 2010-2011 Page 5


Flowing Fountain

software implementation of the graphics library. The software drivers are responsible for
interpreting the output of the API and converting this data to a form that is understood by the
particular hardware.

1.6 OBJECTIVES OF THE PROJECT

 Developing a package using computer graphics with OpenGL.

 Migration from text editor to OpenGL.

 To show that implementation of Translation is easier with OpenGL.

 Implementing certain technical concept like Translation, motion, and use of Idle
Function.

 How to use Lightning effects used to produce computer animation.

Dept. of CSE,CEC 2010-2011 Page 6


Flowing Fountain

CHAPTER 2

LITERATURE SURVEY

In late 1960’s the development of Free-form curves and surfaces for computer graphics begins.
Free-form curves and surfaces where developed to describe curved 3-D objects without using
polyhedral representations which are bulky and intractable. To get a precise curve with polygons
might require thousands of faces, whereas a curved surface requires much less calculations. The
UNISURF CAD system was created for designing cars which utilized the curve theories.

A research was made, but was never published so designers get most of the credit. The men
were pioneers in Computer Aided Geometric Design (CAGD) for the auto industry, which
replaced the use of hand drawn French-curve templates in design of auto bodies. The curves were
based on Berstein Polynomials which had been developed by the mathematician Berstein much
earlier. Another kind of basic curve predated that was the Hermite Curve developed by the
mathematician C. Hermite. Also in the same era as, Schonenberg, a mathematician at the
University of Wisconsin was working on Mathematical Splines, which would influence the work
of S. Coons at MIT in Splines, Bicubic Surface Patches, Rational Polynomials around 1968. A
surface patch is freeform curved surface defined by two or more curves.

In 1973, designers based their research into Parametric B-Splines on Coon’s work. The main
difference between B-Splines and Bezier curves is the former allows for local control of key
control points and the later has more of a global control system. B-Splines are also faster to
calculate for a computer than cubic polynomial based curves like the Hermite and Bezier.

Riesenfeld’s pioneering development of B-Splines later influenced the E. Catmull’s research at


Utah.

Dept. of CSE,CEC 2010-2011 Page 7


Flowing Fountain

The "FLOWING FOUNTAIN MODEL". It depicts a 3 Dimensional model of a fountain


through which water is continuously flowing out in its idle state. The water gets stored into a small
reservoir. The water flows out through different levels in the fountain, giving it a realistic look.
User can specify these levels as three, four or five at the beginning.
The program starts with a menu on the screen giving you the options as mention below:
o Proceed.
o Help.
o Exit.
The user is provided with an option to change the color of the fountain using the RIGHT
MOUSE BUTTON. The user can view the fountain from different angles including a Top-view
and can also zoom in or zoom out. This can be controlled using a set of specified keys on
keyboard such as ‘N’ and ‘A’ for ZOOM IN and ZOOM OUT, buttons ‘T’ and ‘F’ for TOP and
FRONT VIEW etc. Clicking on the RIGHT MOUSE BUTTON shows a sub menu -'Help' which
displays the keyboard shortcuts for various controls. The third option ‘Exit’ pops out of the
program.
The project is based on Simple window coordinates and using recursive techniques in OpenGL.

Dept. of CSE,CEC 2010-2011 Page 8


Flowing Fountain

CHAPTER 3

SPECIFICATIONS & REQUIREMENTS

3.1 Hardware requirements:


 Pentium or higher processor.
 16 MB or more RAM.
 A standard keyboard, and Microsoft compatible mouse
 VGA monitor.
 If the user wants to save the Created files a secondary storage medium can be
Used.

3.2 Software requirements:


 The graphics package has been designed for OpenGL; hence the machine must
have Eclipse.
 Software installed preferably 6.0 or later versions with mouse driver installed.
 Turbo c Libraries are used and hence a TC version 2 or later is required.

3.3 Development platform: Ubuntu 10.10.

Dept. of CSE,CEC 2010-2011 Page 9


Flowing Fountain

CHAPTER 4

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.

Blending means that a pixel on the screen isn't replaced by another one, but they are "mixed".
Therefore you can use the alpha value of colors, it indicates how much of the color of the
consisting pixel is used for the new color - for antialiasing of points, OpenGL computes this alpha
value.

After calling glEnable(GL_BLEND); you have to tell OpenGL how to use the alpha values. It
isn't specified, that a higher alpha-value means more transparency or something like that. You can
use them as you want. To tell OpenGL _what_ you want, you must use glBlendFunc(). It takes
two parameters, one for the source factor and the second for the destination factor. I used
GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA as parameters. This is quite an often used
combination and affects, that the higher the alpha value, the less transparency of the incoming
fragment

Dept. of CSE,CEC 2010-2011 Page 10


Flowing Fountain

CHAPTER 5

IMPLEMENTATION

Step 1: [To create a fountain]

Declare a class called CDrop.

In GetNewPosition (), we calculate the position and delay of each drop with respect to the co-
ordinate axes.

Step 2: [function createlist ()]

Dynamically allocate memory for the required vertices.

Function glGenLists used to generate a contiguous set of empty display lists.

Then specify a series of ‘for ‘loops to construct the top and bottom of the stone.

Then create a qaudrilateral to represent the ground.

To create water, use the following functions:

GlTranslatef () – is to calculate water and stone height.

rand () function is used to generate random unique numbers, for each time it is executed.

Step 3: [function InitFountain ()]

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

Dept. of CSE,CEC 2010-2011 Page 11


Flowing Fountain

cosine () functions inside for loops, to calculate the speed of each step in the fountain, how many
steps are required, that a drop comes out and falls down again.

Step 4: [Displaying]

[Keyboard function]

Manages operations by various keys pressed on the key board

[Display function]

Renders the program on to the screen.

Uses the following functions:

GlClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)- Indicates the buffers


currently enabled for color writing and also indicates the depth buffer.

GlPushMatrix (), glPopMatrix () — to push and pop the current matrix stack.

DrawTextXY () — used to set the text of the program.

glFlush () — force execution of GL commands in finite time.

GlutSwapBuffers ()-Swap the buffers ->make the result of rendering visible.

[reshape function]

glMatrixMode (GL_PROJECTION) -applies subsequent matrix operations to the projection


matrix stack.

glMatrix

Dept. of CSE,CEC 2010-2011 Page 12


Flowing Fountain

Mode (GL_MODELVIEW)-applies subsequent matrix operations to the model view matrix


stack.

We adjust the viewing volume. We use the whole window for rendering and adjust point size to
window size.

Step 5: [main function]

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.

Dept. of CSE,CEC 2010-2011 Page 13


Flowing Fountain

CHAPTER 6

SNAPSHOTS

Fig 6.1 Start Screen

Dept. of CSE,CEC 2010-2011 Page 14


Flowing Fountain

Fig 6.2 Help Menu

Dept. of CSE,CEC 2010-2011 Page 15


Flowing Fountain

Fig 6.3 Flowing Fountain

Dept. of CSE,CEC 2010-2011 Page 16


Flowing Fountain

CHAPTER 7

CONCLUSION AND FUTURE SCOPE

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.

Dept. of CSE,CEC 2010-2011 Page 17


Flowing Fountain

APPENDIX

#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;

Dept. of CSE,CEC 2010-2011 Page 18


Flowing Fountain

public:
void SetConstantSpeed (SVertex NewSpeed);
void SetAccFactor(GLfloat NewAccFactor);
void SetTime(GLfloat NewTime);
void GetNewPosition(SVertex * PositionVertex);
};

void CDrop::SetConstantSpeed(SVertex NewSpeed)


{
ConstantSpeed = NewSpeed;
}

void CDrop::SetAccFactor (GLfloat NewAccFactor)


{
AccFactor = NewAccFactor;
}

void CDrop::SetTime(GLfloat NewTime)


{
time = NewTime;
}

void CDrop::GetNewPosition(SVertex * PositionVertex)


{
SVertex Position;
time += 0.15;
Position.x = ConstantSpeed.x * time;
Position.y = ConstantSpeed.y * time - AccFactor * time *time;
Position.z = ConstantSpeed.z * time;
PositionVertex->x = Position.x;
PositionVertex->y = Position.y + WaterHeight;
PositionVertex->z = Position.z;
if (Position.y < 0.0)
{
time = time - int(time);
if (time > 0.0) time -= 1.0;
}
}
CDrop * FountainDrops;

Dept. of CSE,CEC 2010-2011 Page 19


Flowing Fountain

SVertex * FountainVertices;
GLint Steps = 4;
GLint RaysPerStep =8;
GLint DropsPerRay = 80;
GLfloat DropsComplete = Steps * RaysPerStep * DropsPerRay;
GLfloat AngleOfDeepestStep = 80;
GLfloat AccFactor = 0.011;
void CreateList(void)
{
SVertex * Vertices = new SVertex[NumOfVerticesStone*3];
ListNum = glGenLists(1);
for (GLint i = 0; i<NumOfVerticesStone; i++)
{
Vertices[i].x = cos(2.0 * PI / NumOfVerticesStone * i) * OuterRadius;
Vertices[i].y = StoneHeight;
Vertices[i].z = sin(2.0 * PI / NumOfVerticesStone * i) * OuterRadius;
}
for (i = 0; i<NumOfVerticesStone; i++)
{
Vertices[i + NumOfVerticesStone*1].x = cos(2.0 * PI / NumOfVerticesStone *
i) * InnerRadius;
Vertices[i + NumOfVerticesStone*1].y = StoneHeight;
Vertices[i + NumOfVerticesStone*1].z = sin(2.0 * PI / NumOfVerticesStone *
i) * InnerRadius;
}
for (i = 0; i<NumOfVerticesStone; i++)
{
Vertices[i + NumOfVerticesStone*2].x = cos(2.0 * PI / NumOfVerticesStone *
i) * OuterRadius;
Vertices[i + NumOfVerticesStone*2].y = 0.0;
Vertices[i + NumOfVerticesStone*2].z = sin(2.0 * PI / NumOfVerticesStone *
i) * OuterRadius;
}
glNewList(ListNum, GL_COMPILE);
glBegin(GL_QUADS);
glColor3ub(0,105,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);

Dept. of CSE,CEC 2010-2011 Page 20


Flowing Fountain

glVertex3f(OuterRadius*10.0,0.0,OuterRadius*10.0);
for (int j = 1; j < 3; j++)
{
if (j == 1) glColor3f(1.3,0.5,1.2);
if (j == 2) glColor3f(0.4,0.2,0.1);
for (i = 0; i<NumOfVerticesStone-1; i++)
{
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();
glTranslatef(0.0,WaterHeight - StoneHeight, 0.0);
glBegin(GL_POLYGON);
for (i = 0; i<NumOfVerticesStone; i++)
{
glVertex3fv(&Vertices[i+NumOfVerticesStone].x);
GLint m1,n1,p1;
m1=rand()%255;
n1=rand()%255;
p1=rand()%255;
glColor3ub(m1,n1,p1);
}
glEnd();
glEndList();
}
GLfloat GetRandomFloat(GLfloat range)
{
return (GLfloat)rand() / (GLfloat)RAND_MAX * range * RandomFactor;
}
void InitFountain(void)
{
FountainDrops = new CDrop [ (int)DropsComplete ];

Dept. of CSE,CEC 2010-2011 Page 21


Flowing Fountain

FountainVertices = new SVertex [ (int)DropsComplete ];


SVertex NewSpeed;
GLfloat DropAccFactor;
GLfloat TimeNeeded;
GLfloat StepAngle;
GLfloat RayAngle;
GLint i,j,k;
for (k = 0; k <Steps; k++)
{
for (j = 0; j < RaysPerStep; j++)
{
for (i = 0; i < DropsPerRay; i++)
{
DropAccFactor = AccFactor + GetRandomFloat(0.0005);
StepAngle = AngleOfDeepestStep + (90.0-AngleOfDeepestStep)
* GLfloat(k) / (Steps-1) + GetRandomFloat(0.2+0.8*(Steps-k-1)/(Steps-1));
NewSpeed.x = cos ( StepAngle * PI / 180.0) * (0.2+0.04*k);
NewSpeed.y = sin ( StepAngle * PI / 180.0) * (0.2+0.04*k);
RayAngle = (GLfloat)j / (GLfloat)RaysPerStep * 360.0;
NewSpeed.z = NewSpeed.x * sin ( RayAngle * PI /180.0);
NewSpeed.x = NewSpeed.x * cos ( RayAngle * PI /180.0);
TimeNeeded = NewSpeed.y/ DropAccFactor;
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,
GL_FLOAT,
0,
FountainVertices);
}
void randcolor()

Dept. of CSE,CEC 2010-2011 Page 22


Flowing Fountain

{
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);

for (int i = 0; i < DropsComplete; i++)


{
FountainDrops[i].GetNewPosition(&FountainVertices[i]);
}
glDrawArrays( GL_POINTS,
0,
DropsComplete);
glutPostRedisplay();
}
void colours(int id)
{
flag=id;
if(flag==1)
randcolor();
glutPostRedisplay();
}
void flow(int id)
{
RaysPerStep=id;

Dept. of CSE,CEC 2010-2011 Page 23


Flowing Fountain

glutPostRedisplay();
}
void level(int id)
{
Steps=id;
glutPostRedisplay();
}
void help(int id)
{
glutPostRedisplay();
}
void CMain(int id)
{
}
void NormalKey(GLubyte key, GLint x, GLint y)
{

if(f==0)
{
switch ( key )
{
case 13:
case '1': f=3; break;
case '2': f=1; break;
case '3':
case '4': case 'b': f=2; break;
case ESCAPE: exit(0);

glutPostRedisplay();
}
}
else if(f==1)
{
if(key=='b'||key=='B')
f=0;
else
f=3;
glutPostRedisplay();
}

Dept. of CSE,CEC 2010-2011 Page 24


Flowing Fountain

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;

Dept. of CSE,CEC 2010-2011 Page 25


Flowing Fountain

glutPostRedisplay();
break;

case 'b': case 'B':


f=0;
glutPostRedisplay();
break;

case 'h': case 'H':


f=1;
glutPostRedisplay();
break;

default:
break;
}
}
}

void DrawTextXY(double x,double y,double z,double scale,char *s)


{
int i;
glPushMatrix();
glTranslatef(x,y,z);
glScalef(scale,scale,scale);
for (i=0;i < strlen(s);i++)
glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN,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)
{

Dept. of CSE,CEC 2010-2011 Page 26


Flowing Fountain

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();

Dept. of CSE,CEC 2010-2011 Page 27


Flowing Fountain

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 ");

Dept. of CSE,CEC 2010-2011 Page 28


Flowing Fountain

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();

Dept. of CSE,CEC 2010-2011 Page 29


Flowing Fountain

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);

Dept. of CSE,CEC 2010-2011 Page 30


Flowing Fountain

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;
}

Dept. of CSE,CEC 2010-2011 Page 31


Flowing Fountain

BIBLIOGRAPHY

 Edward Angel’s Interactive Computer Graphics Pearson Education 5th Edition

WEBSITES

 www.OpenGL Redbook.

 www.OpenGL simple examples.

 www.OpenGL programming guide.

Dept. of CSE,CEC 2010-2011 Page 32

You might also like