1.1 Computer Graphics: Water Cycle

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

WATER CYCLE 2021-2022

CHAPTER 1

INTRODUCTION

1.1 Computer Graphics

Graphics provides one of the most natural means of communicating with a


computer, since our highly developed 2D and 3D pattern recognition abilities allow us
to perceive and process pictorial data rapidly and efficiently. Interactive computer
graphics is the most important means of producing pictures since the invention of
photography and television. It has the added advantage that, with the computer, we
can make pictures not only of concrete real-world objects but also of abstract,
synthetic objects, such as mathematical surfaces and of data that have no inherent
geometry, such as survey results.

1.2 OpenGL

OpenGL (Open Graphics Library) 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 3D 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 direct 3D on Microsoft Windows
Platforms. OpenGL is managed by the nonprofit technology consortium, the Khronos
group Inc.
OpenGL serves two main purposes:
➢ To hide the complexities of interfacing with different 3D accelerators,
by presenting programmer with a single, uniform API
➢ To hide the differing capabilities of hardware platforms, by requiring
that all implementations support the full OpenGL feature set.
Department of Computer Science & Engineering, JITD Page 1
WATER CYCLE 2021-2022

OpenGL has historically been influential on the development of 3D accelerator,


promoting a base level of functionality that is now common in consumer level
hardware:
➢ Rasterized points, lines and polygons are basic primitives.
➢ A transform and lighting pipeline.
➢ Z buffering.
➢ Texture Mapping.
➢ Alpha Blending.

1.2.1 OpenGL Graphics Architecture:

Figure 1.1 Opengl Graphics Architecture

Display Lists:

All data, whether it describes geometry or pixels, can be saved in a display list for
current or later use. When a display list is executed, the retained data is sent from the
display list just as if it were sent by the application in immediate mode.

Department of Computer Science & Engineering, JITD Page 2


WATER CYCLE 2021-2022

➢ Evaluators: All geometric primitives are eventually described by


vertices. Parametric curves and surfaces may be initially described by control points
and polynomial functions called basis functions.

➢ Per Vertex Operations: For vertex data, next is the "per-vertex


operations" stage, which converts the vertices into primitives. Some vertex data are
transformed by 4 x 4 floating-point matrices. Spatial coordinates are projected from a
position in the 3D world to a position on your screen.

➢ Primitive Assembly: Clipping, a major part of primitive assembly, is


the elimination of portions of geometry which fall outside a half space, defined by a
plane.

➢ Pixel Operation: While geometric data takes one path through the
OpenGL rendering pipeline, pixel data takes a different route. Pixels from an array in
system memory are first unpacked from one of a variety of formats into the proper
number of components. Next the data is scaled, biased, and processed by a pixel map.
The results are clamped and then either written into texture memory or sent to the
rasterization step.

➢ Rasterization: Rasterization is the conversion of both geometric and


pixel data into fragments. Each fragment square corresponds to a pixel in the
framebuffer. Color and depth values are assigned for each fragment square.

➢ Fragment Operations: Before values are stored into the framebuffer,


a series of operations are performed that may alter or even throw out fragments. All
these operations can be enabled or disabled.

Department of Computer Science & Engineering, JITD Page 3


WATER CYCLE 2021-2022

1.3 Project Goal


The aim of this project is to show the shadow implementation using OPENGL
which include Movement, Light properties also transformation operations like
translation, rotation, scaling etc. on objects. The package must also have a user-
friendly interface.

1.4 Scope
It is developed in Visual Studio 2022. It has been implemented on
WINDOWS platform. The 3-D graphics package designed here provides an
interface for the users for handling the display and manipulation of Celestial
Exploratory. The Keyboard is the main input device used.

Department of Computer Science & Engineering, JITD Page 4


CHAPTER 2

LITERATURE SURVEY

WATER CYCLE:
The land – atmosphere interaction through exchanges of energy, water, momentum
between the land surface and atmosphere is well understood. The land surface
characteristics such as the Albio, roughness, and land cover/land use can have an
impact on the water cycle. However, in the water cycle, the role of aerosols is not
taken into account. Aerosols play an important role in many areas including human
health, atmospheric reactions, the radiation and precipitation.
Increases in aerosol concentration and changes in their composition may
affect the Earth’s climate and water supply. Aerosols have direct and indirect effects
on the Earth’s climate system by reducing the amount of solar radiation that reaches
the surface and changing the properties of clouds. On the one hand, as aerosols
increase, the surface temperature may cool due to its direct effect.
On the other hand, owing to the indirect effect, as aerosols concentration
increases, it may decrease the rainfall through increasing the small CCN which can
reduce the collision rate. In this way, changing aerosols in the atmosphere can
change the frequency of cloud occurrence, cloud thickness, and rainfall amounts.
In some sense, the increase of aerosols can change the frequency of heavy
rainfall. Likewise, in the hydrologic cycle, the land surface features especially the
soil moisture and vegetation variation can affect the aerosols formation through
changing the secondary organic aerosols.
Conceptually, these potential feedbacks are well known; however, the
processes controlling each step in this coupled system are highly uncertain. The
importance of these processes to the hydrologic cycle is unknown.
Much work has been done to understand the formation of anthropogenic
aerosols including the measurements, the laboratory experiments and model
simulations. While progress has been made in understanding the direct input for
aerosols, the contribution of secondary organic aerosols is also very important for
understanding the aerosols and hydrologic cycle.

Page 5
First, a large parent organic is oxidized to produce products with vapor
pressures significantly lower than that of the parent. These products can partition
between the gas and aerosol phases via condensation and nucleation (Griffin et al.,
2002). The secondary aerosols are formed by the reaction of volatile organic
compounds with the principle atmospheric oxidizing agents (i.e., ozone, no3
radicals).
So, the volatile organic compounds (VOCs) including anthropogenic and
biogenic types are important for the formation of secondary organic aerosols.
Greenberg et al. (1999) found over 90% of the total VOCs entering the atmosphere
are biogenic. Biogenic VOCs (BVOCs) from the vegetation can regulate the
atmosphere trace gas composition, in which, isoprene is the primary VOC emitted
from trees in different locations.
The total flux of biogenic nonmethane volatile organic compounds
(NMVOCs) in North America is comprised primarily of isoprene (35%) (Guenther
et al., 2000). And there are 98% of the total annual natural NMVOCs emissions are
emitted by vegetation. The emission inventories are very important in determining
the flux of BVOCs. Not only different vegetations can emit different fractions of
BVOCs, but also the same vegetation in different locations can emit different
fractions of BVOCs due to different climate conditions and soil types.
The aerosols from the oxidization of BVOCs have been investigated showing
their importance for the formation of secondary organic aerosols (Koch et al., 2000).
But estimates of the biogenic aerosols from the oxidization of BVOCs are not well
understood due to the large potential sources and complex processes. Understanding
the secondary organic aerosols is one of most important questions to understand
water cycle in the atmosphere and land surface.
The feedback mechanism between the anthropogenic and secondary organic
aerosols and hydrologic cycle is an important issue for climate prediction and air
forecasting.

Page 6
CHAPTER 3

REQUIREMENTS SPECIFICATIONS

3.1 HARDWARE REQUIREMENTS:


• 128 MB of RAM, 256 MB recommended.
• 110 MB of hard disk space required; 40 MB additional hard disk space
required for installation (150 MB total).
3.2 SOFTWARE REQUIREMENTS:
This water cycle simulator has been designed for WINDOWS. OpenGL
libraries are used and hence the CODE BLOCKS version 17.12 is required.

Development Platform: Windows 10

Language: C/C++
Tool: CODE BLOCKS 17.12

Library: OpenGL

Page 7
CHAPTER 4
SYSTEM DESIGN

The project “WATER CYCLE” is meant as a source of recreation where one


can sit in front of the computer and can enjoy the view of the water/hydrological
cycle.
In science, a model is a representation of an idea, an object, a process or a system.
Models are often used when it is difficult to see or experience the real thing. Although
we live in the middle of the water cycle, it is difficult for students to see aspects of it in
action because they either happen underground or involve invisible processes
(transpiration and evaporation) and gravity – a non-contact force.
This chapter documents a detailed description of the implementation of our project.
We have incorporated several inbuilt OpenGL functions in this project. The
following code snippet enables the easy rendering of solid sphere with different
colors and makes them to rotate and translate.
{
…………….
glRotatef(s…….);
glTranslatef(………);
glRotatef(………..);
glColor3f(…………);
glutSolidSphere(……..);
……………………
}
The header files used are:
1. #include<stdlib.h>: This is C library function for standard input and output.
2. #include<GL/glut.h>: This header is included to read the glut.h, gl.h and glu.h.

Page 8
3. #include<math.h>: This is a C library function for performing certain
mathematical operations.
In the Init () we have made use of the following functions:
1. glClearColor (. . .): Whenever we wish to draw a new frame, the window
must be cleared by using the 4-dimensional (RGBA)color system. The above
function must be enabled to make the window on screen solid and white.
2. glshadeModel (. . .): To enable the smooth shading we must set the shade
as follows
glShadeModel (GL_SMOOTH);
3. glEnable(. . .): The Z-buffer is one of the buffers that make up the frame
buffer.The depth buffer must be cleared whenever we wish to redraw the
display.This is done as follows
glEnable(GL_DEPTH_TEST);
4. glMaterial(. . .): We can specify different material properties for the front
and back faces of a surface through the following functions
glMaterialfv(GLenum face, GLenum type,GLfloat *pointer_to_array);
glMaterialfv(GLenum face,GLenum type,GLfloat value);
5. glLight(. . .): This function is used to enable a light source.The following
function specifies the required vector and scalar parameters to enable a light
source.
glLightfv(GLenum source,GLenum parameter,GLfloat*pointer_to_arrary))
glLightf(GLenum source,GLenum parameter,GLfloat value)
6. glColorMaterial(. . .): This function is used to change a single material
property.
myinit();
Here we initialize the color buffer, set the point size and set window co-
ordinate values.
display ();
This function creates and translates all the objects in a specified locatioN in
a particular order.

Page 9
Translated (. . .);
In this function the variables are components of displacement vector.
glutPostRedisplay ();
It ensures that display will be drawn only once each time program goes
through the event loop.
glutMainLoop ();
This function whose execution will cause the program to begin an event
processing loop.

Page 10
WATER CYCLE 2021-2022

CHAPTER 5

IMPLEMENTATION

Step 1: The required texture image must first be converted into a TGA format image
which is used by the tgaload function.

Step 2: The TGA format image is then stored in the desired location and then it is
provided to the program to perform the required operations to display the texture.

OpenGL Functions Used:


This project is developed using Microsoft Visual Studio 2022 and this project is
implemented by making extensive use of library functions offered by graphics package
of OpenGL, a summary of those functions follows:

5.1 glBegin() :

Specifies the primitives that will be created from vertices presented


between glBegin and subsequent glEnd.. GL_POLYGON, GL_LINE_LOOP
etc.

5.2 glEnd(void) :

It ends the list of vertices.

5.3 glPushMatrix() :

void glPushMatrix (void)

glPushMatrix pushes the current matrix stack down by one level, duplicating
the current matrix.

Department of Computer Science & Engineering, JITD Page 15

Page 11
WATER CYCLE 2021-2022

5.4 glPopMatrix() :

void glPopMatrix (void)

glPopMatrix pops the top matrix off the stack, destroying the contents of the
popped matrix. Initially, each of the stacks contains one matrix, an identity matrix.

5.5 glTranslate() :

void glTranslate(GLdouble x, GLdouble y, GLdouble z )

Translation is an operation that displaces points by a fixed distance in a given direction.


Parameters x, y, z specify the x, y, and z coordinates of a translation vector. Multiplies
current matrix by a matrix that translates an object by the given x, y and z-values.

5.6 glClear() :

void glClear(GLbitfield mask)

glClear takes a single argument that is the bitwise or of several values


indicating which buffer is to be cleared. GL_COLOR_BUFFER_BIT,
GL_DEPTH_BUFFER_BIT, GL_ACCUM_ BUFFER_BIT, and
GL_STENCIL_BUFFER_BIT. Clears the specified buffers to their current clearing
values.

5.7 glClearColor() :

void glClearColor(GLclampf red, GLclampf green, GLclampf blue,


GLclampf alpha)

Sets the current clearing color for use in clearing color buffers in RGBA mode. The
red, green, blue, and alpha values are clamped if necessary to the range [0,1]. The
default clearing color is (0, 0, 0, 0), which is black.

Department of Computer Science & Engineering, JITD Page 16

Page 12
WATER CYCLE 2021-2022

5.8 glMatrixMode() :

void glMatrixMode(GLenum mode)

It accepts three values GL_MODELVIEW, GL_PROJECTION and


GL_TEXTURE. It specifies which matrix is the current matrix. Subsequent
transformation commands affect the specified matrix.

5.9 glutInitWindowPosition() :

void glutInitWindowPosition(int x, int y);

This API will request the windows created to have an initial position. The arguments x,
y indicates the location of a corner of the window, relative to the entire display.

5.10 glLoadIdentity() :

void glLoadIdentity(void);

It replaces the current matrix with the identity matrix.

5.11 glutInitWindowSize() :

void glutInitWindowSize(int width, int height);

The API requests windows created to have an initial size. The arguments width and
height indicate the window’s size (in pixels). The initial window size and position are
hints and may be overridden by other requests.

5.12 glutInitDisplayMode():

void glutInitDisplayMode(unsigned int mode );

Specifies the display mode, normally the bitwise OR-ing of GLUT display mode bit
masks. This API specifies a display mode (such as RGBA or color-index, or single or
double-buffered) for windows.

Department of Computer Science & Engineering, JITD Page 17

Page 13
WATER CYCLE 2021-2022

5.13 glutSwapBuffers() :

void glutSwapBuffers(void);

Performs a buffer swap on the layer in use for the current window.
Specifically, glutSwapBuffers promotes the contents of the back buffer of the layer in
use of the current window to become the contents of the front buffer. The contents of
the back buffer then become undefined. The update typically takes place during the
vertical retrace of the monitor, rather than immediately after glutSwapBuffers is called.

An implicit glFlush is done by glutSwapBuffers before it returns. Subsequent


OpenGL commands can be issued immediately after calling glutSwapBuffers, but are
not executed until the buffer exchange is completed.

5.14 glutCreateWindow() :

int glutCreateWindow(char *name);

The parameter name specifies any name for window and is enclosed in double
quotes. This opens a window with the set characteristics like display mode, width,
height, and so on. The string name will appear in the title bar of the window system.
The value returned is a unique integer identifier for the window. This identifier can be
used for controlling and rendering to multiple windows from the same application.

5.15 glutDisplayFunc() :

void glutDisplayFunc(void (*func)(void))

Specifies the new display callback function. The API specifies the function
that’s called whenever the contents of the window need to be redrawn. All the routines
need to be redraw the scene are put in display callback function.

Department of Computer Science & Engineering, JITD Page 18

Page 14
WATER CYCLE 2021-2022

5.16 glVertex3f

void glVertex3f(GLfloatx,GLfloat y,GLfloat);

x Specifies the x-coordinate of a vertex.

y Specifies the y-coordinate of a vertex.

z Specifies the z-coordinate of a vertex.

The glVertex function commands are used within glBegin/glEnd pairs to


specify point, line, and polygon vertices. The current color, normal, and texture
coordinates are associated with the vertex when glVertex is called. When only x and y
are specified, z defaults to 0.0 and w defaults to 1.0. When x, y, and z are specified, w
defaults to 1.0.

5.17 glColor3f

void glColor3f(GLfloat red, GLfloat green, GLfloat blue);

5.18 glGenTextures():

void glGenTexture (GLsizei n, GLuint textures);

PARAMETERS:

n : Specifies the number of texture names to be generated.

Textures : Specifies an array in which the generated texture names are stored.

glGenTextures returns n texture names in textures. There is no guarantee that the names
form a contiguous set of integers; however, it is guaranteed that none of the returned
names was in use immediately before the call to glGenTextures.

Department of Computer Science & Engineering, JITD Page 19

Page 15
WATER CYCLE 2021-2022

5.19 glBindTexture():

void glBindTexture (GLenum target, GLuint texture);

PARAMETERS:

target: Specifies the target to which the texture is bound. Must be one
of GL_TEXTURE_1D,
GL_TEXTURE_2D, GL_TEXTURE_3D, GL_TEXTURE_1D_ARRAY, GL_TEXTUR
E_2D_ARRAY,
GL_TEXTURE_RECTANGLE, GL_TEXTURE_CUBE_MAP, GL_TEXTURE_CUBE
_MAP_ARRAY,
GL_TEXTURE_BUFFER, GL_TEXTURE_2D_MULTISAMPLE or GL_TEXTURE_2
D_MULTISAMPLE_ARRAY.

texture: Specifies the name of a texture.

5.20 glutInit():

glutInit(int *argcp, char **argv);

PARAMETERS:

argcp : A pointer to the program's unmodified argc variable from main. Upon return, the
value pointed to by argcp will be updated, because glutInit extracts any command line
options intended for the GLUT library.

argv : The program's unmodified argv variable from main. Like argcp, the data for argv
will be updated because glutInit extracts any command line options understood by the
GLUT library.

glutInit(&argc,argv);

glutInit is used to initialize the GLUT library.

Department of Computer Science & Engineering, JITD Page 20

Page 16
WATER CYCLE 2021-2022

5.21 glutMainLoop ():

void glutMainLoop (void);


glutMainLoop ();

glutMainLoop enters the GLUT event


processing loop.

5.22 glLightfv():

void glLightfv(GLenum light, GLenum pname, GLfloat *params);

The glLightfv function returns light source parameter values.

PARAMETERS:

Light: The identifier of a light. The number of possible lights depends on the
implementation, but at least eight lights are supported. They are identified by symbolic
names of the form GL_LIGHTi where i is a value: 0 to GL_MAX_LIGHTS - 1.

Pname: A light source parameter for light. The following symbolic names are accepted:

GL_DIFFUSE: The params parameter contains four integer or floating-point values that
specify the diffuse RGBA intensity of the light. Integer values are mapped linearly such
that the most positive represent able value maps to 1.0, and the most negative represent
able value maps to 1.0. Floating-point values are mapped directly. Neither integer nor
floating-point values are clamped. The default diffuse intensity is (0.0, 0.0, 0.0, 1.0) for
all lights other than light zero. The default diffuse intensity of light zero is (1.0, 1.0, 1.0, 1.0).
GL_SPECULAR: The params parameter contains four integer or floating-point values
that specify the specular RGBA intensity of the light. Integer values are mapped linearly
such that the most positive represent able value maps to 1.0, and the most negative
represent able value maps to 1.0. Floating-point values are mapped directly. Neither
integer nor floating-point values are clamped. The default specular intensity is (0.0, 0.0,
0.0, 1.0) for all lights other than light zero. The default specular intensity of light zero is
(1.0, 1.0, 1.0, 1.0).

Department of Computer Science & Engineering, JITD Page 21

Page 17
WATER CYCLE 2021-2022

GL_AMBIENT: The params contains four integer or floating-point values that specify
the ambient RA intensity of the light. Integer values are mapped linearly such that the
most positive represent able value maps to 1.0, and the most negative representable value
maps to -1.0 . Floating-point values are mapped directly. Neither integer nor floating-
point values are clamped. The initial ambient light intensity is (0,0, 0, 1).

5.23 glEnable():

void glEnable(GLenum cap);

Ex: glEnable(GL_CULL_FACE);

PARAMETERS:

cap: A symbolic constant indicating an OpenGL capability.

The glEnable enables OpenGL capabilities.

5.24 glDisable():

void glDisable (GLenum cap);

Ex: glDisable (GL_CULL_FACE);

PARAMETERS:

cap: Specifies a symbolic constant indicating a GL capability.

The glDisable disables OpenGL capabilities.

Department of Computer Science & Engineering, JITD Page 22

Page 18
WATER CYCLE 2021-2022

5.25 gluNewQuadric():

GLUquadric* gluNewQuadric(void);

Performs a buffer swap on the layer in use for the current window.
Specifically, glutSwapBuffers promotes the contents of the back buffer of the layer in
use of the current window to become the contents of the front buffer. The contents of the
back buffer then become undefined. The update typically takes place during the vertical
retrace of the monitor, rather than immediately after glutSwapBuffers is called.

An implicit glFlush is done by glutSwapBuffers before it returns. Subsequent OpenGL


commands can be issued immediately after calling glutSwapBuffers, but are not executed
until the buffer exchange is completed.

If the layer in use is not double buffered, glutSwapBuffers has no effect.

5.26 gluQuadricNormals():

void gluQuadricNormals (GLUquadric* quad, GLenum normal);

PARAMETERS:

Quad: Specifies the quadrics object (created with gluNewQuadric).

Normal: Specifies the quadrics object (created with gluNewQuadric).

gluQuadricNormals specifies what kind of normal are desired for quadrics rendered
with quad. The legal values are as follows:

GLU_NONE: No normals are generated.

GLU_FLAT: One normal is generated for every facet of a quadric.

GLU_SMOOTH: One normal is generated for every vertex of a quadric. This is the initial
value.

Department of Computer Science & Engineering, JITD Page 23

Page 19
WATER CYCLE 2021-2022

5.27 gluQuadricTexture():

void gluQuadricTexture (GLUquadric* quad, GLboolean texture);

PARAMETERS:

Quad: Specifies the quadrics object (created with gluNewQuadric).

Texture : Specifies a flag indicating if texture coordinates should be generated.

gluQuadricTexture specifies if texture coordinates should be generated for quadrics


rendered with quad. If the value of texture is GLU_TRUE, then texture coordinates are
generated, and if texture is GLU_FALSE, they are not. The initial value is GLU_FALSE.

The way texture coordinates are generated depends upon the specific quadric rendered.

5.28 gluLookAt():

void gluLookAt (GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ,

GLdouble centerX, GLdouble centerY, GLdouble centerZ,

GLdouble upX, GLdouble upY, GLdouble upZ);

PARAMETERS:

eyeX, eyeY, eyeZ : Specifies the position of the eye point.

centerX, centerY, centerZ : Specifies the position of the reference point.

upX, upY, upZ : Specifies the direction of the up vector.

gluLookAt creates a viewing matrix derived from an eye point, a reference point
indicating the center of the scene, and an UP vector.

Department of Computer Science & Engineering, JITD Page 24

Page 20
WATER CYCLE 2021-2022

5.29 gluSphere():

void gluSphere(GLUquadric* quad, GLdouble radius, GLint slices, GLint


stacks);

PARAMETERS:

Quad: Specifies the quadrics object (created with gluNewQuadric).

Radius: Specifies the radius of the sphere.

Slices: Specifies the number of subdivisions around the z axis (similar to lines of
longitude).

Stacks: Specifies the number of subdivisions along the z axis (similar to lines of latitude).

gluSphere draws a sphere of the given radius centered around the origin. The sphere is
subdivided around the z axis into slices and along the z axis into stacks (similar to lines of
longitude and latitude).

5.30 glViewport():

void glViewport (GLint x, GLint y, GLsizei width, GLsizei height);

PARAMETERS:

x,y : Specify the lower left corner of the viewport rectangle, in pixels. The initial
value is (0,0).

width, height : Specify the width and height of the viewport. When a GL context is first
attached to a window, width and height are set to the dimensions of that window.

Department of Computer Science & Engineering, JITD Page 25

Page 21
WATER CYCLE 2021-2022

5.31 glFrustum():

void glFrustum(GL double left, GLdouble right,

GLdouble bottom, GLdouble top,

GLdouble nearVal, GLdouble farVal);

PARAMETERS:

left, right: Specify the coordinates for the left and right vertical clipping planes.

bottom, top: Specify the coordinates for the bottom and top horizontal clipping planes.

nearVal, farVal: Specify the distances to the near and far depth clipping planes. Both
distances must be positive. glFrustum describes a perspective matrix that produces a
perspective projection.

5.32 glutTimerFunc():

void glutTimerFunc(unsigned int msecs, void (*func)(int value), value);

glutTimerFunc registers the timer callback func to be triggered in at least msecs


milliseconds. The value parameter to the timer callback will be the value of the value
parameter to glutTimerFunc. Multiple timer callbacks at same or differing times may be
registered simultaneously.

The number of milliseconds is a lower bound on the time before the callback is generated.
GLUT attempts to deliver the timer callback as soon as possible after the expiration of the
callback's time interval.

There is no support for canceling a registered callback. Instead, ignore a callback based
on its value parameter when it is triggered.

Department of Computer Science & Engineering, JITD Page 26

Page 22
WATER CYCLE 2021-2022

5.33 glCreateMenu():

int glutCreateMenu (void (*func) (int value));


PARAMETERS:

func: The callback function for the menu that is called when a menu entry from the menu
is selected. The value passed to the callback is determined by the value for the selected
menu entry.

glutCreateMenu creates a new pop-up menu and returns a unique small integer identifier.
The range of allocated identifiers starts at one. The menu identifier range is separate from
the window identifier range. Implicitly, the current menu is set to the newly created
menu. This menu identifier can be used when calling glutSetMenu.

When the menu callback is called because a menu entry is selected for the menu,
the current menu will be implicitly set to the menu with the selected entry before the
callback is made.

5.34 glutAddMenuEntry():

void glutAddMenuEntry (char *name, int value);

PARAMETERS:

name: ASCII character string to display in the menu entry.

value: Value to return to the menu’s callback function if the menu entry is selected.

glutAddMenuEntry adds a menu entry to the bottom of the current menu. The
string name will be displayed for the newly added menu entry. If the menu entry is
selected by the user, the menu's callback will be called passing value as the callback's
parameter.

Department of Computer Science & Engineering, JITD Page 27

Page 23
WATER CYCLE 2021-2022

5.35 glutAddSubMenu():

void glutAddSubMenu (char *name, int menu);

PARAMETERS:

Name: ASCII character string to display in the menu item from which to cascade the sub-
menu.

Menu: Identifier of the menu to cascade from this sub-menu menu item.

glutAddSubMenu adds a sub-menu trigger to the bottom of the current menu. The
string name will be displayed for the newly added sub-menu trigger. If the sub-menu
trigger is entered, the sub-menu numbered menu will be cascaded, allowing sub-menu
menu items to be selected.

5.36 glutAttachMenu ():

void glutAttachMenu (int button);

PARAMETERS:

Button: The button to attach a menu or detach a menu.

glutAttachMenu attaches a mouse button for the current window to the identifier of
the current menu. By attaching a menu identifier to a button, the named menu will be
popped up when the user presses the specified button. button should be one
of GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON,
and GLUT_RIGHT_BUTTON. Note that the menu is attached to the button by identifier,
not by reference.

Department of Computer Science & Engineering, JITD Page 28

Page 24
WATER CYCLE 2021-2022

5.37 glutReshapeFunc():

void glutReshapeFunc (void (*func) (int width, int height));

PARAMETERS:

Func: The new reshape callback function.

glutReshapeFunc sets the reshape callback for the current window. The reshape callback
is triggered when a window is reshaped. A reshape callback is also triggered immediately
before a window's first display callback after a window is created or whenever an overlay
for the window is established. The width and height parameters of the callback specify
the new window size in pixels. Before the callback, the current window is set to the
window that has been reshaped.

If a reshape callback is not registered for a window or NULL is passed


to glutReshapeFunc (to deregister a previously registered callback), the default reshape
callback is used. This default callback will simply call glViewport(0,0,width,height) on
the normal plane (and on the overlay if one exists).

If an overlay is established for the window, a single reshape callback is generated. It is the
callback's responsibility to update both the normal plane and overlay for the window
(changing the layer in use as necessary).

When a top-level window is reshaped, subwindows are not reshaped. It is up to the GLUT
program to manage the size and positions of subwindows within a top-level window.
Still, reshape callbacks will be triggered for subwindows when their size is changed
using glutReshapeWindow.

Department of Computer Science & Engineering, JITD Page 29

Page 25
WATER CYCLE 2021-2022

5.38 glutKeyboardFunc():

void glutKeyboardFunc (void (*func) (unsigned char key, int x, int y));

PARAMETERS:

Func: The new keyboard callback function.

glutKeyboardFunc sets the keyboard callback for the current window. When a user
types into the window, each key press generating an ASCII character will generate a
keyboard callback. The key callback parameter is the generated ASCII character. The
state of modifier keys such as Shift cannot be determined directly; their only effect will
be on the returned ASCII data. The x and y callback parameters indicate the mouse
location in window relative coordinates when the key was pressed. When a new
window is created, no keyboard callback is initially registered, and ASCII key strokes
in the window are ignored. Passing NULL to glutKeyboardFunc disables the
generation of keyboard callbacks.

5.39 glutPostRedisplay ():

void glutPostRedisplay (void);

Mark the normal plane of current window as needing to be redisplayed. The next iteration
through glutMainLoop, the window's display callback will be called to redisplay the
window's normal plane. Multiple calls to glutPostRedisplay before the next display
callback opportunity generates only a single redisplay callback. glutPostRedisplay may be
called within a window's display or overlay display callback to re-mark that window for
redisplay.

Logically, normal plane damage notification for a window is treated as


a glutPostRedisplay on the damaged window.

Department of Computer Science & Engineering, JITD Page 30

Page 26
IMPLEMENTATION CODE:

// =========== MODEL & ANIMATION CONFIG ==============

#include<windows.h>
#include<GL/glut.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#define pi 3.14159

int id=0,start=-1,quit=0,r=0,s=0,rv=0,g=0,mb=0,z=0,f2=0,f3=0,g1=0,g2=0;
float c=0,d=0,f=0,f1=0,i=0,j=0,k=50,n=0,l,m;
float arrow_flag=0,river_flag=0,exitflag=0,fflag=0,move=0,fflag1=0;
void *currentfont;
static GLfloat translate[]={0.0,0.0,0.0,0.0,0.0};
void grass3(void);

void carrow(void);
void carrowf(void);
void cloud(void);
void cloud1(void);
void condensation(void);
void display(void);
void evaporation(void);

void grass1(void);
void grass2(void);
void ground(void);
void groundwater(void);
void gwater(void);
void hill(void);
void inst(void);
void lake(void);
void land(void);
void movcloud(void);
void movfish(void);
void precipitation(void);
void rain1(void);
void rain2(void);

Page 27
void river(void);
void runoff(void);
void sarrow(void);
void sarrowf(void);
void scene1(void);
void scene2(void);
void scene3(void);
void scene4(void);
void sea(void);
void sky(void);
void snow(void);
void sun(float,float,float);
void sunrays(void);
void tarrow(void);
void tarrowf(void);
void transpiration(void);
void tree(void);
void warrow(void);
void warrowf(void);

void setfont(void *font)


{
currentfont=font;
}

void drawstring(float x,float y,float z,char *str)


{
int i,len;
len=strlen(str);
glRasterPos3f(x,y,z);
for(i=0;i<len;i++)
glutBitmapCharacter(currentfont,(int)str[i]);
}

void inst(void)
{
glClearColor(0.686274,0.933333,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glClearColor(0.960784,0.870588,0.690196,1.0);
setfont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(0.690196,0.188235,0.376471);
drawstring(110.0,380.0,0.0,"DEPARTMENT OF COMPUTER SCIENCE AND
ENGINEERING");
drawstring(160.0,350.0,0.0,"DSATM ENGINEERING");
drawstring(200.0,320.0,0.0,"MINI PROJECT ON");

Page 28
glColor3f(0.803921,0.3607843,0.3607843);
drawstring(208.0,300.0,0.0,"WATER CYCLE");
glColor3f(0.690196,0.188235,0.376471);
drawstring(205.0,280.0,0.0,"SUBMITTED BY");
glColor3f(0.803921,0.3607843,0.3607843);
drawstring(45.0,250.0,0.0,"PRABHU DEVAR");
drawstring(320.0,250.0,0.0,"VIDYA SHREE BS");
drawstring(45.0,230.0,0.0,"1DT15CS415");
drawstring(320.0,230.0,0.0,"1DT15CS422");
glColor3f(1.0,.0,0.0);
setfont(GLUT_BITMAP_TIMES_ROMAN_24);
drawstring(195.0,205.0,0.0,"GUIDED BY");
drawstring(190.0,190.0,0.0,"RAGHU ");
glColor3f(0.0,0.0,1.0);
setfont(GLUT_BITMAP_HELVETICA_18);
drawstring(180.0,170.0,0.0,"THE WATER CYCLE");

drawstring(10.0,150.0,0.0,"The Water cycle describes the continuous movement of water on,


above and below the surface of the Earth. It is");
drawstring(10.0,140.0,0.0,"also known as Hydrologic circle.");
drawstring(10.0,125.0,0.0,"It is made up of 4 physical processes:");
drawstring(10.0,100.0,0.0,"EVAPORATION:Click 'e' to view the Evaporation process.");
drawstring(10.0,80.0,0.0,"CONDENSATION:Click 'c' to view the Condensation process.");
drawstring(10.0,60.0,0.0,"PRECIPITATION:Click 'r' to view the Precipitation process.");
drawstring(10.0,40.0,0.0,"SURFACE RUNOFF & INFILTRATION:Click 's' to view the
Infiltration process.");
glColor3f(0.580392,0.0,0.827451);
setfont(GLUT_BITMAP_HELVETICA_18);
drawstring(180.0,20.0,0.0,"Right Click to continue");
glFlush();
glutSwapBuffers();
}

void scene1()
{
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
sun(60.0,280.0,25.0);
land();
hill();
lake();
tree();
ground();
sea();

Page 29
glPushMatrix();
if(arrow_flag==1)
{
sunrays();
sarrowf();
}
glPopMatrix();
sky();
glutPostRedisplay();
glFlush();
}

void scene2()
{
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
hill();
sun(60.0,280.0,25.0);

land();
lake();
ground();
sea();
tree();
gwater();

cloud();
evaporation();
carrowf();
tarrowf();
transpiration();
sky();
}

void scene3()
{
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
hill();
sun(60.0,280.0,25.0);
land();
lake();
ground();
tree();
sea();

Page 30
gwater();

condensation();
movcloud();
cloud();
sky();
}

void scene4()
{
glClearColor(1.0,1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
snow();
if(r==1)
rain2();
else
rain1();
precipitation();
hill();
if(river_flag==1)
{
river();
runoff();
warrowf();
groundwater();
gwater();
}
sun(60.0,280.0,25.0);
land();
lake();
ground();
tree();
sea();

cloud1();
sky();
}

void sun(float h,float k,float r)


{
glColor3f(1.0,0.647059,0.0);
glBegin(GL_POLYGON);
for(i=0;i<=360;i+=1)
glVertex3f(h+r*cos(i*(float)pi/180),k+r*sin(i*(float)pi/180),0.0);
glEnd();

Page 31
glFlush();
}

void land()
{
glColor3f(0.0,1.0,0.0);
glBegin(GL_POLYGON);
glColor3f(0.960784,0.870589,0.701961);
glVertex2f(325.0,57.5);
glVertex2f(287.5,65.0);
glVertex2f(275.0,75.0);
glVertex2f(245.0,95.0);
glVertex2f(211.0,107.5);
glVertex2f(175.0,125.0);

glColor3f(0.0,1.0,0.0);

glVertex2f(187.5,125.0);
glVertex2f(200.0,127.5);
glVertex2f(205.0,129.0);
glVertex2f(215.0,131.0);
glVertex2f(225.0,133.5);
glVertex2f(230.0,134.5);
glVertex2f(232.5,135.5);
glVertex2f(235.0,137.0);
glVertex2f(240.0,139.0);
glVertex2f(250.0,140.0);
glVertex2f(252.5,140.0);
glVertex2f(255.0,142.0);
glVertex2f(257.5,142.0);
glVertex2f(260.0,142.0);
glVertex2f(262.5,143.0);
glVertex2f(265.0,143.0);
glVertex2f(270.5,143.0);
glVertex2f(272.5,143.0);
glVertex2f(275.0,143.0);
glVertex2f(282.5,145.0);
glVertex2f(285.0,145.0);
glVertex2f(290.0,144.0);
glVertex2f(295.0,143.0);
glVertex2f(300.0,143.0);
glVertex2f(320.0,143.0);
glVertex2f(325.5,145.0);
glVertex2f(327.5,146.5);
glVertex2f(330.0,147.5);

Page 32
glVertex2f(332.5,148.0);
glVertex2f(335.5,148.0);
glVertex2f(337.5,148.0);
glVertex2f(342.5,150.0);
glVertex2f(345.0,153.5);
glVertex2f(350.5,155.0);
glVertex2f(355.5,157.0);
glVertex2f(360.5,165.0);
glVertex2f(365.5,161.5);
glVertex2f(371.0,155.5);
glVertex2f(378.0,154.0);
glVertex2f(386.0,153.0);
glVertex2f(392.5,155.0);
glVertex2f(399.0,162.5);
glVertex2f(437.0,178.7);
glVertex2f(500.0,187.0);
glVertex2f(500.0,70.0);
glVertex2f(500.0,65.0);
glEnd();
glFlush();
}

void hill()
{
glPushMatrix();
glScaled(1.2,1.8,0);
glRotated(350,0.5,0,1);

glTranslated(-90,-25,0);

glPushMatrix();
glColor3f(0.737255,0.560784,0.560784);
glBegin(GL_POLYGON); //first hill
glVertex2f(500.0,187.5);
glVertex2f(497.5,190.0);
glVertex2f(495.0,200.0);
glVertex2f(492.5,205.0);
glVertex2f(490.0,210.0);
glVertex2f(485.0,215.0);
glVertex2f(482.5,220.0);
glVertex2f(480.0,225.0);
glVertex2f(477.5,230.0);
glVertex2f(475.0,235.0);
glVertex2f(470.0,230.0);
glVertex2f(465.0,220.0);

Page 33
glVertex2f(462.5,210.0);
glVertex2f(460.0,200.0);
glVertex2f(455.5,190.0);
glVertex2f(452.0,185.0);
glVertex2f(450.0,182.5);
glVertex2f(448.0,180.0);
glVertex2f(445.0,178.0);
glVertex2f(437.5,178.0);
glVertex2f(437.4,178.0);
glVertex2f(437.3,178.1);
glVertex2f(437.1,178.3);
glVertex2f(437.0,178.7);
glEnd();
glPopMatrix();
glFlush();
glPushMatrix();
glColor3f(0.737255,0.560784,0.560784);
glBegin(GL_POLYGON); //second hill
glVertex2f(437.9,178.7);
glVertex2f(435.2,179.0);
glVertex2f(433.0,181.0);
glVertex2f(431.6,185.0);
glVertex2f(429.5,188.0);
glVertex2f(427.0,190.0);
glVertex2f(425.0,195.0);
glVertex2f(423.5,200.3);
glVertex2f(422.0,205.0);
glVertex2f(421.0,207.5);
glVertex2f(420.0,210.5);
glVertex2f(419.0,207.5);
glVertex2f(418.0,205.0);
glVertex2f(416.7,200.3);
glVertex2f(414.5,190.0);
glVertex2f(412.5,185.0);
glVertex2f(410.6,180.0);
glVertex2f(405.5,170.0);
glVertex2f(400.5,168.0);
glVertex2f(399.0,162.5);
glEnd();
glPopMatrix();
glFlush();
}

Page 34
int main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glutInitWindowSize(1000,1000);
glutCreateWindow("WATER CYCLE");
init();
glutDisplayFunc(display);
glutMouseFunc(mouse);
glutKeyboardFunc(keys);
glutPostRedisplay();
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND); //for transparency
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glutMainLoop();
}

Page 35
CHAPTER 6
SNAPSHOTS

IMAGE 1 :

FIG 6.1 : Environment where the water cycle takes place

IMAGE 2:

FIG 6.2: Process of evaporation from sea and transpiration from plants/trees

Page 36
IMAGE 3:

FIG 6.3 : Process of condensation taking place in the clouds

IMAGE 4:

FIG 6.4 : Process of precipitation/raining on the land

Page 37
IMAGE 5:

FIG 6.5 : Filtration/seeping of rainwater into the ground

Page 38
CHAPTER 7
CONCLUSION

We developed a suitable graphics package to implement the skills learnt in


theory classes and the exercises indicated in practical classes using OpenGL. We
were able to develop a sophisticated WATER CYCLE using OpenGL.
The following are the some of the features:
• Different Models of polygons are implemented.
• Can be used for the awareness of conservation of water.
• The different cycles of water are shown in the project .

SCOPE OF IMPROVEMENT:
Though the package that is designed here does not include complex
OpenGL package, we intend to improve this by including extra features like
lighting effects. Changing the background color adding alarms. We do this
with an aim to attract more people to use our package.

Page 39
BIBLIOGRAPHY

BOOK REFERENCES:

1. Edward Angel: Interactive Computer Graphics: A Top-Down Approach with 5th


Edition, Addison-wesley,2008.
2. James D Foley, Andries Van Dam, Steven K Feiner, Jhon F Hughes: - Computer
Graphics, Addison-Wesley 1997.
3. Yashavanth Kanetkar,” Graphics under opengl”, Published by BPB Publications.
4. Athul P.Godse, “Computer Graphics", Technical Publications Pune, 2nd Revised
Edition.
5. James D.Foley, Andries Van Dam, Sreven K.Fiener, John F.Huges, “ Computer
Graphics Principle & Practice” Published by Pearson Education pvt.ltd, 2nd Edition.

WEBSITE REFERENCES:

[1] - https://www.khronos.org/opengl/wiki/Getting_Started
[2] - https://www.opengl.org/sdk/docs/tutorials/OGLSamples/
[3] - https://www.geeksforgeeks.org/getting-started-with-opengl/
[4] - https://www.khronos.org/opengl/wiki//Code_Resources
[5] - http://www.lighthouse3d.com/tutorials/glut-tutorial/
[6] - http://code-blocks.blogspot.in/2014/12/bresenhams-circle-drawing-algorithm.html
[7] - https://github.com/sprintr/opengl-examples/blob/master/OpenGL-Menu.cpp

Page 40

You might also like