You are on page 1of 23

VISVESVARAYA TECHNOLOGICAL UNIVERSITY

BELGAVI, KARNATAKA -590 018

A Mini-Project Report on

“Volcanic Eruption”
Submitted in partial fulfillment for the Computer Graphics Laboratory with
Mini-Project (18CSL67) course of Sixth Semester of Bachelor of Engineering
in Computer Science & Engineering during the academic year 2021-22.

By
Team Code: CGP2022-C06
Yashas D 4MH19CS120
Dheemanth Hr 4MH19CS027

: Under the Guidance of :


Prof. Harish H K
Assistant Professor
Department of CS&E
MIT Mysore

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE
Belawadi, S.R. Patna Taluk, Mandya Dist-571477.

Accredited By:

2021-22
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE

~~ CERTIFICATE ~~

Certified that the mini-project work entitled “Volcanic Eruption” is a


bonafide work carried out by Yashas D (4MH19CS120) & Dheemanth Hr
(4MH19CS027) for the Computer Graphics Laboratory with Mini-Project
(18CSL67) of Sixth Semester in Computer Science & Engineering under
Visvesvaraya Technological University, Belgavi during academic year
2021-22.
It is certified that all corrections/suggestions indicated for Internal
Assignment have been incorporated in the report. The report has been
approved as it satisfies the course requirements.

_________________ _________________
Signature of Guide Signature of the HOD

Prof. Harish H K Dr. Shivmurthy R C


Assistant Professor Professor & HOD
Dept. of CS&E Dept. of CS&E
MIT Mysore MIT Mysore

External viva
Name of the Examiners Signature with date

1)………………………………………………………………………………

2) ………………………………………………………………………………
~~~~ ACKNOWLEDGEMENT ~~~~

It is the time to acknowledge all those who have extended their guidance,
inspiration, and their wholehearted co-operation all along our project work.

We are also grateful to Dr. B G Naresh Kumar, principal, MIT Mysore


and Dr. Shivmurthy R C, HOD, CS&E, MIT Mysore for having provided us
academic environment which nurtured our practical skills contributing to the
success of our project. We are also grateful to Prof. Harish H K, for guiding
through the project.

We wish to place a deep sense of gratitude to all Teaching and Non-


Teaching staffs of Computer Science and Engineering Department for whole-
hearted guidance and constant support without which Endeavour would not have
been possible.

Our gratitude will not be complete without thanking our parents and our
friends, who have been a constant source of support and aspirations

Yashas D
Dheemanth Hr
~~~ ABSTRACT ~~~
In this project the main aim is to illustrate the concepts and usage of pre-built
functions in OpenGL. Creating Figures like “VOLCANO” where the idea behind this
project is to display the aquarium with computer graphics. This graphics package is
based on the OpenGL library functions. The programming language used here is C
using OpenGL libraries. In this project, we are demonstrating the screensaver in which
we can toggle between day and night with the pressing of “n” button and “d” button.
In this project we imposed the idea of volcanic eruption and implemented the
same using OpenGL. This is achieved with basic two-dimensional shapes and some
transformation using translations. These translations are achieved with the interaction
of the keyboard. The different shadow effects can easily differentiate between different
figures of the project. User interaction with keyboard helps us easily understand the
before and after scenario of the volcanic eruption.
~~~~~ CONTENTS ~~~~~

1. INTRODUCTION ………………………………...……………… 01
1.1 Aim of the Project …………………………...………….… 01
1.2 Overview of the Project……………….……………...…… 01
1.3 Outcome of the Project……………….….…………...…… 01

2. DESIGN AND IMPLEMENTATION …………...……………... 02


2.1 Algorithm …………………………...…………………….. 02
2.2 Flow Chart …………………………...…………………… 03
2.3 OpenGL API’s Used with Description …………………… 04
2.4 Source Code …………………………...………………..… 06

3. RESULT ANALYSIS ...………………………….………………... 15


3.1 Snap Shots …………………………...……………………. 15
3.2 Discussion ………………………….........................……… 16

4. CONCLUSION AND FUTURE WORK ………...……………….. 17


4.1 Conclusion ………………………….........................……… 17
4.2 Future Enhancement …………………………...……….… 17

5. REFERENCES …….…………………………...………………… 18
Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

CHAPTER - 1

INTRODUCTION
1.1 Aim
The main aim of this project “Volcanic Eruption” demonstrates the working model of
a two-dimensional volcano in day and night with keyboard interaction.

1.2 Overview
This project shows the design in OpenGL. Volcanic Eruption is a natural phenomenon
that occurs in nature. On Earth, volcanoes are most often found where tectonic plates are
diverging or converging, and most are found underwater. Volcanoes often form a hill or
mountain as layers of rock and ash build up from repeated eruptions. They are made of small
pieces of solid lava, called cinder. On land, volcanoes form when one tectonic plate moves
under another. Usually a thin, heavy oceanic plate subducts, or moves under, a thicker
continental plate. When this happens, the ocean plate sinks into the mantle.

1.3 Outcome
Through the OpenGL Programming we are able to demonstrate the working of the
volcano and its eruption. By studying the nature of the volcano in different situations like
day and night. By demonstrating general knowledge and understanding of the hazards
posed by volcanic eruption.

Dept. of CS&E, MIT Mysore 2021-2022 1


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

CHAPTER – 2

DESIGN AND IMPLEMENTATION


2.1 Algorithm

Step 1: Start

Step 2: Register glutDisplayMode.

Step 3: Register WindowSize and WindowPosition.

Step 4: Create window providing “Volcanic Eruption”.

Step 5: Invoke Display Function and with the use of required API’S.

Step 6: Initialize values of x, y, *format to stroke output function providing stroke character.

Step 7: Declare global variables i, j, k, x, y, n1, n2 and initialize their respective value.

Step 8: Construct Hills, trees, clouds, house, water, sun with all properties included using
respective model.

Step 9: Utilize handlekeypress() ,mouse() for user interactions.

Step 10: Invoke doInit() to setup our view perspective.

Step 11: Stop.

Dept. of CS&E, MIT Mysore 2021-2022 2


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

2.2 Flow Chart

Figure 2.2: Flow Chart

Dept. of CS&E, MIT Mysore 2021-2022 3


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

2.3 OpenGL API’s Used and Description


This program is implemented using various OpenGL functions which are shown below.

Various functions used in this program.

GlutInit() interaction between the windowing system


and OPENGL is initiated.

GlutInitDisplayMode() used when double buffering is required and


depth and information is required.

GlutCreateWindow() this opens the OPENGL window and


displays the title at top of the window.

glutInitWindowSize() specifies the size of the window.

glutInitWindowPosition() specifies the position of the window in


screen co-ordinates.

glutKeyboardFunc() handles normal ascii symbols.

glutSpecialFunc() Handles special keyboard keys.

glutReshapeFunc() Sets up the callback function for reshaping


the window.

glutIdleFunc() this handles the processing of the


background.

glutDisplayFunc() this handles redrawing of the window.

glutMainLoop() this starts the main loop, it never returns.

glViewport() used to set up the viewport.

glVertex3fv() used to set up the points or vertices in three


dimensions.

glColor3fv() used to render color to faces.

glFlush() used to flush the pipeline.

glutPostRedisplay() used to trigger an automatic redrawer of the


object.

Dept. of CS&E, MIT Mysore 2021-2022 4


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

glMatrixMode() used to set up the required mode of the


matrix.

glLoadIdentity() used to load or initialize to the identity


matrix.

glTranslatef() used to translate or move the rotation


center from one point to another in three
dimensions.

glRotatef() used to rotate an object through a specified


rotation angle.

glPushMatrix() pushes the current matrix stack down by


one, duplicating the current matrix.

glPopMatrix() the current matrix stack, replacing the


current matrix with the one below it on the
stack. Initially, each of the stacks contains
one matrix, an identity matrix.

glraster3f() The glRasterPos4 function specifies object


coordinates x, y, z, and explicitly.

gltranslatef() The glTranslatef function multiplies the


current matrix by a translation matrix

glutBitmapCharacter() glutBitmapCharacter automatically sets the


OpenGL unpack pixel storage modes

glScaled() The glScaled function produces a general


scaling along the x, y, and z axes

glutStrokeCharacter() glutStrokeCharacter renders a stroke


character using OpenGL.

glSolidCube() The glutSolidCube() function draws a


solid-shaded cube with side-length given
by width

glutSolidSphere () Render a solid or wireframe sphere


respectively.

Table 2.3: OpenGL API’s Used and Description.

Dept. of CS&E, MIT Mysore 2021-2022 5


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

2.4 Source Code


#include<windows.h>

#include<mmsystem.h>

#include<GL\glut.h>

#include <GL/glu.h>

#include<math.h>

#include <stdlib.h>

#include<stdio.h>

#define PI 3.1416

GLint i, j, k,x=0,y=0,speed=0,alt=0,n1=1000,n2=1100,s1=0,s2=1,s3=1;

GLfloat sun_spin=0, sun_x=0, sun_y=0,reduce=10;

GLfloat ax=0,bx=0,cx=0,dx=0,str=500.0,mn=500.0;

GLfloat sr=0.0,sg=0.749,sb=1.0;

GLfloat spin = 0.0;

bool condition=false;

GLfloat position = 0.0f;

GLfloat _move =5.0f;

GLfloat position1 = 0.0f;

GLfloat _move1 =3.0f;

GLfloat position2 = 900.0f;

GLfloat _move2 =3.0f;

Dept. of CS&E, MIT Mysore 2021-2022 6


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

void init(void)

glClearColor(.40, .110, 1.0, 0.0);

glMatrixMode(GL_PROJECTION);

gluOrtho2D(0.0, 1000.0, 0.0, 700.0);

float r(int a){

return x=4,y=8;

float r(int a,int b){

return x=0,y=0;

void updatey(int value) {

y= 8.0f;

glutPostRedisplay();

glutTimerFunc(100, updatey, 0);

void updatex(int value) {

x=4.0f;

glutPostRedisplay();

glutTimerFunc(100, updatex, 0);

void brown_hill()

glColor3f(0.50196, 0.25098, 0.0);

Dept. of CS&E, MIT Mysore 2021-2022 7


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

glPushMatrix();

glTranslatef(0,-220,0);

glScaled(0.8,0.76,0);

glBegin(GL_POLYGON);

glVertex3i(600, 600, 0);

glVertex3i(800, 900, 0);

glVertex3i(900, 650, 0);

glVertex3i(600, 600, 0);

glColor3f(0.50196, 0.25098, 0.0);

glBegin(GL_POLYGON);

glVertex3i(600, 600, 0);

glVertex3i(900, 650, 0);

glVertex3i(1000, 800, 0);

glVertex3i(1100, 620, 0);

glColor3f(0.50196, 0.25098, 0.0);

glBegin(GL_POLYGON);

glVertex3i(1050, 620, 0);

glVertex3i(1200, 800, 0);

glVertex3i(1200, 600, 0);

glPopMatrix();

glEnd();

Dept. of CS&E, MIT Mysore 2021-2022 8


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

void fire(){

glBegin(GL_POLYGON);

glVertex2f(13.5,0.0);

glVertex2f(8,10);

glVertex2f(15,4);

glVertex2f(17, 10);

glVertex2f(19,4);

glVertex2f(26.0,10);

glVertex2f(20.5, 0.0);

glEnd();

/// *** Sun_Model **///

void Sun_Model(){

glPushMatrix();

glTranslatef(600,1100,0);

circle(33);

glPopMatrix();

void update2(int value) {

//position2 -= 5;

if(position2 <-1.3)

position2 -= _move2;

Dept. of CS&E, MIT Mysore 2021-2022 9


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

glutPostRedisplay(); //Notify GLUT that the display has changed

glutTimerFunc(20, update2, 0); //Notify GLUT to call update again in 25


milliseconds

void fire1(){

glColor3f(0.7, 0.0, 0.0);

glPushMatrix();

glTranslatef(63,390,0);

glScaled(y,y,0);

fire();

glPopMatrix();

void display(void)

glClear(GL_COLOR_BUFFER_BIT);

glColor3f(0.0, 0.0, 1.0);

night();

brown_hill();

Sun();

fire1();

fire2();

tree();

hill_volkano();

cloud_three();

cloud_four();

Dept. of CS&E, MIT Mysore 2021-2022 10


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

Windmill_One();

Windmill_Two();

Tilla_Two();

Tilla_Three();

cloud_one();

house2();

Tree_One();

Tree_Two();

Tree_Three();

Tree_Four();

cloud_two();

cloud_five();

cloud_six();

field();

glFlush();

void move_right()

spin = spin +.1;

ax = ax + .05;

bx = bx + .08;

cx = cx + .10;

dx = dx + .15;

if(cx>1000){

cx = -300;

Dept. of CS&E, MIT Mysore 2021-2022 11


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

if(bx>1000){

bx= -400;

if(cx>1000){

cx= -400;

if(dx>1000){

dx= -500;

glutPostRedisplay();

void mouse(int key, int state, int x, int y){

switch (key)

case GLUT_LEFT_BUTTON:

if (state == GLUT_DOWN)

glutIdleFunc(move_right);

break;

case GLUT_MIDDLE_BUTTON:

case GLUT_RIGHT_BUTTON:

if (state == GLUT_DOWN)

glutIdleFunc(NULL);

Dept. of CS&E, MIT Mysore 2021-2022 12


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

break;

default:

break;

void handleKeypress(unsigned char key, int x, int y) {

switch (key) {

case 'f':

r(1);

break;

case 'g':

r(1,1);

break;

case 'n':

updatex();

condition=true;

break;

case 'd':

updatex1();

condition=false;

break;

glutPostRedisplay();

Dept. of CS&E, MIT Mysore 2021-2022 13


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

int main(int argc, char** argv)

glutInit(&argc, argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowPosition(50, 50);

glutInitWindowSize(1800, 900);

glutCreateWindow("Volcanic Eruption");

init();

glutDisplayFunc(display);

glutTimerFunc(20, update, 0);

glutTimerFunc(20, update1, 0);

glutTimerFunc(20, update2, 0);

glutMouseFunc(mouse);

glutKeyboardFunc(handleKeypress);

glutMainLoop();

Dept. of CS&E, MIT Mysore 2021-2022 14


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

CHAPTER – 3

RESULT ANALYSIS
3.1 Snap Shots
General view of volcano.

Fig 3.1 Displays the volcano

Shows the Volcanic Eruption in day.

Fig 3.2 Displays the Volcanic Eruption in Day

Dept. of CS&E, MIT Mysore 2021-2022 15


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

Shows the volcanic eruption in night

Fig 3.3 Displays the Volcanic Eruption in night

3.2 Discussion
1. Fig 3.1: Displays the volcanic mountain with a scene consisting of house, windmill,
clouds, sun, water, and hills.

2. Fig 3.2: Displays the Volcanic Eruption in Day.

• When the user clicks ‘d’ from the keyboard the scene turns to day if it was in night
mode.
• When the user clicks ‘f’ from the keyboard shows the volcanic eruption.
• When the user clicks ‘g’ from the keyboard the eruption disappears.

3. Fig 3.3: Displays the Volcanic Eruption in Night.

• When the user clicks ‘n’ from the keyboard the scene turns to night if it was in day
mode.
• When the user clicks ‘f’ from the keyboard shows the volcanic eruption.
• When the user clicks ‘g’ from the keyboard the eruption disappears.

Dept. of CS&E, MIT Mysore 2021-2022 16


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

CHAPTER – 4

CONCLUSION AND FUTURE ENHANCEMENT


4.1 Conclusion
In conclusion, this project presents a visual implementation of working process of a
Volcano. This project demonstrates how volcanic eruption works. The idea behind the
natural phenomenon of volcanic eruption. This package is very useful for the user since it
provides the basic information about volcanic eruption. This is an interactive project which
has user friendly interaction given through keyboard and mouse. Thus, this project meets
the basic requirements successfully.

4.2 Future Enhancement


The future enhancement that can be made include:

▪ Keyboard interaction can be improvised.

▪ The project can be further developed to change the colour of the objects and also, we can
give the background effect as well.

▪ More abstract view of the volcanic eruption can be made.

Dept. of CS&E, MIT Mysore 2021-2022 17


Volcanic Eruption Computer Graphics Laboratory with Mini-Project [18CSL67]

CHAPTER – 5

REFERENCE
We have obtained information from many resources to design and implement our project
successively. We have acquired most of the knowledge from related websites. The
following are some of the resources:

➢ Text Books: interactive computer graphics a top-down approach -by Edward angel.

➢ computer graphics, principles & practices - foley van dam - Feiner Hughes.

➢ Web References:

http://jerome.jouvie.free.fr/opengl/lessons/lesson3.php

http://google.com

http://opengl.org

Dept. of CS&E, MIT Mysore 2021-2022 18

You might also like