0% found this document useful (0 votes)
51 views37 pages

Opengl Report-1.1

Uploaded by

dishagowda2311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views37 pages

Opengl Report-1.1

Uploaded by

dishagowda2311
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

3D LAKESIDE VIEW

Chapter-1
INTRODUCTION

1.1 INTRODUCTION

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.

Using this editor you can draw and paint using the mouse. It can also perform a host of
other functions like drawing lines, circles, polygons and so on. Interactive picture construction
techniques such as basic positioning methods, rubber-band methods, dragging and drawing are
used. Block operations like cut, copy and paste are supported to edit large areas of the workspace
simultaneously. It is user friendly and intuitive to use.
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.
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.

DEPT OF CSE, GMIT 2023-2024 Page 1


3D LAKESIDE VIEW

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 STATEMENT OF PROBLEM


3D Lakeside View is a property designing. The 3D Landscape Architect comes in three
designs for specific purposes: Landscape and Home Design Suite, Landscape Design Deluxe,
and Home Design Deluxe. Landscape Design Deluxe simulates landscape designs, Home Design
Deluxe simulates home designs and Home and Landscape Design Suite is used for both.

3D Landscape Architect was introduced by Broderbund in the 1990s and was a scaled down
version of a professional home design application called Chief Architect, made by Advanced
Relational Technology (ART) Inc. (now renamed to Chief Architect, Inc.). After version 4.0, the
agreement between Broderbund and ART Inc. was terminated, and 3D Landscape Architect 5.0
and later versions are based on a similar professional application called Cad soft Envisioned.

1.3 OBJECTIVE OF THE PROBLEM


The objective of the problem is to implement an 3d lakeside view that comprises of houses, trees,
a lake with a bridge along the sideway and a boat in the lake whose movement is controlled by
the application of Keyboard function.

Keyboard function: -
Pressing ‘r’ key the movement of the 3d lakeside view resumes.
Pressing ‘p’ key the movement of the 3d lakeside view pauses.
Pressing ‘c’ key the boat rotates in clockwise or anti-clockwise directions.

DEPT OF CSE, GMIT 2023-2024 Page 2


3D LAKESIDE VIEW

Chapter-2
LITERATURE SURVEY

Computer graphics started with the display of data on hardcopy plotters and cathode ray
tube (CRT) screens soon after the introduction of computers.

Computer graphics today largely interactive, the user controls the contents, structure, and
appearance of objects and of displayed images by using input devices, such as keyboard, mouse,
or touch-sensitive panel on the screen. Graphics based user interfaces allow millions of new
users to control simple, low-cost application programs, such as spreadsheets, word processors,
and drawing programs.

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 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 (see Direct3D vs. OpenGL). OpenGL is managed by
the non-profit technology consortium, the Khronos Group.

Figure 2.1 Operation Order in the Opengl rendering pipeline

DEPT OF CSE, GMIT 2023-2024 Page 3


3D LAKESIDE VIEW

On 17 December 1997, Microsoft and SGI initiated the Fahrenheit project, which was a joint
effort with the goal of unifying the OpenGL and Direct3D interfaces (and adding a scene-graph
API too). In 1998 Hewlett-Packard joined the project.[4] It initially showed some promise of
bringing order to the world of interactive 3D computer graphics APIs, but on account of financial
constraints at SGI, strategic reasons at Microsoft, and general lack of industry support, it was
abandoned in 1999[8].

Many opengl functions are used for rendering and transformation purposes.
Transformations functions like glRotate (), glTranslate (), glScaled () can be used.

OpenGL provides a powerful but primitive set of rendering command, and all higher-
level drawing must be done in terms of these commands. There are several libraries that allow
you to simplify your programming tasks, including the following:

OpenGL Utility Library (GLU) contains several routines that use lower-level OpenGL
commands to perform such tasks as setting up matrices for specific viewing orientations and
projections and rendering surfaces.

OpenGL Utility Toolkit (GLUT) is a window-system-independent toolkit, written by


Mark Kill guard, to hide the complexities of differing window APIs.

To achieve the objective of the project, information related to the light sources is required
with OpenGL we can manipulate the lighting and objects in a scene to create many different
kinds of effects. It explains how to control the lighting in a scene, discusses the OpenGL
conceptual model of lighting, and describes in detail how to set the numerous illumination
parameters to achieve certain effects. To demonstrate the transformation and lightening, effects,
different polygons have to be used. Polygons are typically drawn by filling in all the pixels
enclosed within the boundary, but we can also draw them as outlined polygons or simply as
points at the vertices. This concept is obtained from.

The properties of a light source like its material, diffuse, emissive, has to mention in the
project. So to design the light source and the objects, programming guide of an OpenGL is used.

DEPT OF CSE, GMIT 2023-2024 Page 4


3D LAKESIDE VIEW

Chapter-3

SYSTEM REQUIREMENTS SPECIFICATION

3.1 HARDWARE REQUIREMENTS

Minimum hardware specification

Processor - Intel Processor 100 MHz / Pentium Processor 100 MHz or Higher Versions.

RAM - 2GB or more.

Hard disk - 50GB or more.

keyboard - QWERTY keyboard

3.2 SOFTWARE REQUIREMENTS

Minimum Software specification

Operating System - windows xp / 7 / 10

Progamming IDE – Codeblocks 12.11

Programming Language – C language

Libraries – Opengl library

DEPT OF CSE, GMIT 2023-2024 Page 5


3D LAKESIDE VIEW

Chapter-4

DESIGN

4.1 EXISTING SYSTEM


Existing system for a graphics is the TC++. This system will support only the 2D graphics. 2D
graphics package being designed should be easy to use and understand. It should provide various
options such as free hand drawing, line drawing, polygon drawing, filled polygons, flood fill,
translation, rotation, scaling, clipping etc. Even though these properties were supported, it was
difficult to render 2D graphics cannot be very difficult to get a 3 Dimensional object. Even the
effects like lighting, shading cannot be provided. So we go for
Codeblocks IDE.

4.2 PROPOSED SYSTEM


To achieve three dimensional effects, open GL software is proposed. It is a software which
provides a graphical interface. It is a interface between application program and graphics
hardware. The advantages are:

2. Open GL is designed as a streamlined.


3. It’s a hardware independent interface i.e it can be implemented on many different
hardware platforms.
4. With open GL we can draw a small set of geometric primitives such as points, lines and
polygons etc.
5. It provides double buffering which is vital in providing transformations.
6. It is event driven software.
7. It provides call back function.

DEPT OF CSE, GMIT 2023-2024 Page 6


3D LAKESIDE VIEW

4.3 Low level design

DEPT OF CSE, GMIT 2023-2024 Page 7


3D LAKESIDE VIEW

Chapter-5
IMPLEMENTATION

5.1 Functions Used


 glColor4f (float, float, float,float) and glColor3f(float, float, float) :- This functions
will set the current drawing color

 glClear( ):-Takes a single argument that is the bitwise OR of several values indicating
which buffer is to be cleared.

 glClearColor ():-Specifies the red, green, blue, and alpha values used by glClear to clear
the color buffers.

 GlLoadIdentity( ):-the current matrix with the identity matrix.

 glMatrixMode(mode):-Sets the current matrix mode, mode can be GL_MODELVIEW,


GL_PROJECTION or GL_TEXTURE.

 Void glutInit (int *argc, char**argv):-Initializes GLUT, the arguments from main are
passed in and can be used by the application.

 Void glutInitDisplayMode (unsigned int mode):-Requests a display with the properties


in mode. The value of mode is determined by the logical OR of options including the
color model and buffering.

 Void glutInitWindowSize (int width, int height):- Specifies the initial position of the
top-left corner of the window in pixels.

 Int glutCreateWindow (char *title):-A window on the display. The string title can be
used to label the window. The return value provides references to the window that can be
used when there are multiple windows.

DEPT OF CSE, GMIT 2023-2024 Page 8


3D LAKESIDE VIEW

 Void glutKeyboardFunc(void(*func) (void)):-This function is called every time when


you press a key on the keyboard. . In our program, this func is invoked when the keys
‘r’, ’p’ and ‘c’ key is pressed for resuming the movement, pausing the movement and
directing the boat in clockwise or anti-clockwise direction.

 Void glMatrixMode(GLenum mode) :-This function is used to determine which matrix


stack (GL_MODELVIEW,GL_PROJECTION,GL_TEXTURE) will be used for matrix
operaton.

 Void glutMainLoop ():- This function Cause the program to enter an event-processing
loop. It should be the last statement in main function.

5.2 Viewing
5.2.1 The viewing transformation

 Void gluLookAt(GLdouble eyex,GLdouble eyey,GLdouble eyez,GLdouble


centerx,GLdouble centery, GLdouble centerz,GLdouble upx, GLdouble upy,
GLdouble upz):-This function defines a viewing transformation based on the position of
the eye,center of the scene and viewers perspective.

5.2.2 Viewing volume clipping

 void glViewport(GLint x, GLint y, GLsizei width, GLsizei height)-This function


defines a pixel rectangle in the window into which the final image is mapped. The (x, y)
parameter specifies the lower-left corner of the viewport, and width and height are the
size of the viewport rectangle. By default, the initial viewport values are (0, 0, winWidth,
winHeight), where winWidth and winHeight are the size of the window.

5.2.3 Modeling transformation

DEPT OF CSE, GMIT 2023-2024 Page 9


3D LAKESIDE VIEW

Translate

 void glTranslate{fd}(TYPEx, TYPE y, TYPEz)-This function multiplies the current


matrix by a matrix that moves (translates) an object by the given x, y, and z values (or
moves the local coordinate system by the same amounts).

Rotate
 void glRotate{fd}(TYPE angle, TYPE x, TYPE y, TYPE z)-This function multiplies
the current matrix by a matrix that rotates an object (or the local coordinate system) in a
counterclockwise direction about the ray from the origin through the point (x, y, z). The
angle parameter specifies the angle of rotation in degrees.

Scale
 void glScale{fd}(TYPEx, TYPEy, TYPEz)-This function Multiplies the current matrix
by a matrix that stretches, shrinks, or reflects an object along the axes. Each x, y, and z
coordinate of every point in the object is multiplied by the corresponding argument x, y,
or z. With the local coordinate system approach, the local coordinate axes are stretched,
shrunk, or reflected by the x, y, and z factors, and the associated object is transformed
with them.

5.2.4 Projection transformation

Perspective projection

 Void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble


far)-This functioncreates a matrix for a symmetric perspective-view frustum and
multiplies the current matrix by it. fovy is the angle of the field of view in the x-z plane;
its value must be in the range [0.0,180.0]. aspect is the aspect ratio of the frustum, its
width divided by its height. near and far values the distances between the viewpoint and
the clipping planes, along the negative z-axis. They should always be positive.

5.2.5 Manipulating the matrix stacks

DEPT OF CSE, GMIT 2023-2024 Page 10


3D LAKESIDE VIEW

 void glPushMatrix(void);-This Function pushes all matrices in the current stack down
one level. The current stack is determined by glMatrixMode(). The topmost matrix is
copied, so its contents are duplicated in both the top and second-from-the-top matrix. If
too many matrices are pushed, an error is generated.

 void glPopMatrix(void);-This Function pops the top matrix off the stack, destroying the
contents of the popped matrix. What was the second-from-the-top matrix becomes the top
matrix. The current stack is determined by glMatrixMode(). If the stack contains a single
matrix, calling glPopMatrix() generates an error.

5.3 OpenGL Lighting function

The OpenGL lighting model considers the lighting to be divided into four independent
components: emissive, ambient, diffuse, and specular. ambient illumination is light that's been
scattered so much by the environment that its direction is impossible to determine - it seems to
come from all directions.The diffuse component is the light that comes from one direction, so it's
brighter if it comes squarely down on a surface than if it barely glances off the surface. Once it
hits a surface, however, it's scattered equally in all directions, so it appears equally bright, no
matter where the eye is located.Specular light comes from a particular direction, and it tends to
bounce off the surface in a preferred direction. A well-collimated laser beam bouncing off a
high-quality mirror produces almost 100 percent specular reflection. Shiny metal or plastic has a
high specular component, and chalk or carpet has almost none. You can think of specularity as
shininess.

Creating light source


The command used to specify all properties of lights is glLight*().

void glLight{if}(GLenum light, GLenum pname, TYPEparam);


void glLight{if}v(GLenum light, GLenum pname, TYPE *param);

The characteristic of the light being set is defined by pname,it mainly specifies
anamed parameter param indicates the values to which the pname characteristic
is set; it's a pointer to a group of values if the vector version is used, or the value
itself if the nonvector version is used.
Examples: -

DEPT OF CSE, GMIT 2023-2024 Page 11


3D LAKESIDE VIEW

GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };


GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };

glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);


glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

Enabling and Disabling lighting


In OpenGL, it is necessary to explicitly enable or disable lighting.

glEnable(GL_LIGHTING);
glDisable(GL_LIGHTING);

Blending, Antialiasing and Fog

"Blending" tells you how to specify a blending function that combines color values from a
source"Antialiasing" explains this relatively subtle technique that alters colors so that the edges
of points,lines, and polygons appear smooth rather than angular and jagged."Fog" describes how
to create the illusion of depth by computing the color values of an objectbased on its distance
from the viewpoint. Thus, objects that are far away appear to fade into the background, just as
they do in real life.

Chapter-6

DEPT OF CSE, GMIT 2023-2024 Page 12


3D LAKESIDE VIEW

SOURCE CODE

#include <windows.h>
#include <GL/glut.h>
typedef GLfloat p2D[2];
GLuint startList;
GLint boatAngle,bouyAngle= 0;
GLfloat boatFlip = 0;
GLfloat waveDistance = 6.0;
int dirFlag = 0;

void init(void)
{
GLfloat mat_diffuse[] = {0.5,0.5,0.2,1.0};
GLfloat mat_specular[] = {0.4, 0.4, 0.6, 1.0};
GLfloat mat_shininess[] ={100.0};
GLfloat light_position[]={-1.0,2.0,4.0,0.0};
GLfloat lmodel_ambient[]={0.7,0.5,0.0,1.0};
GLUquadricObj *qobj;
startList = glGenLists(1);
qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj, GLU_FILL);
gluQuadricNormals(qobj, GLU_SMOOTH);
glNewList(startList, GL_COMPILE);
gluCylinder(qobj, 0.025, 0.025, 1.0, 30, 10);
glEndList();
gluQuadricDrawStyle(qobj, GLU_FILL);
gluQuadricNormals(qobj, GLU_SMOOTH);
glNewList(startList+1, GL_COMPILE);
gluCylinder(qobj, 0.25, 0.25, 1.0, 30, 10);
glEndList();

glClearColor(0.0,0.0,0.0,0.0); /* night background */

DEPT OF CSE, GMIT 2023-2024 Page 13


3D LAKESIDE VIEW

//glClearColor(0.4,0.7,1.0,0.0); /* day background*/

glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient)
;

glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);


glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

glColorMaterial(GL_FRONT, GL_DIFFUSE);

glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);

/*Set up for blending*/


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}

void drawHousem(p2D pos,const GLfloat size) /*main house*/


{
const GLfloat xzSize = (0.5*size) + (0.08*size);
const GLfloat yHeight = (0.5*size);
glPushMatrix();
glTranslatef(pos[0], (0.4*size), pos[1]);
glColor3f(10.0, 0.0, 0.0);
glutSolidCube(size);

// house door
glPushMatrix();
glColor3f(0.0,0.0,0.0);

DEPT OF CSE, GMIT 2023-2024 Page 14


3D LAKESIDE VIEW

glTranslatef(-0.02*size,size/-5.1,size/5.3);
glScalef(-1.4,-2.6,-5.9);
glutSolidCube(size/8.0);
glPopMatrix();

//house chimney
glPushMatrix();
glColor3f(8.0, 0.0, 0.0);
glTranslatef(0.25*size, 0.6*size, 0.0);
glScalef(1.0, 2.0, 1.0);
glutSolidCube(0.2*size);
glPopMatrix();

//draw roof using triangles


glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.0, 0.2);
glNormal3f(1.0, 2.2, 0.0);
glVertex3f(xzSize, yHeight, xzSize);
glColor3f(0.5, 0.5, 0.0);
glVertex3f(xzSize, yHeight, -xzSize);
glColor3f(0.0, 0.0, 0.8);
glVertex3f(0.0, (yHeight+(0.25*size)), 0.0);

glColor3f(0.5, 0.5, 0.0);


glNormal3f(0.0, 2.2, 1.0);
glVertex3f(xzSize, yHeight, xzSize);
glColor3f(0.5, 0.5, 0.0);
glVertex3f(-xzSize, yHeight, xzSize);
glColor3f(0.0, 0.0, 0.8);
glVertex3f(0.0, (yHeight+(0.25*size)), 0.0);

glColor3f(0.5, 0.5, 0.0);


glNormal3f(-1.0, 2.2, 0.0);
glVertex3f(-xzSize, yHeight, xzSize);
glColor3f(0.5, 0.5, 0.0);
DEPT OF CSE, GMIT 2023-2024 Page 15
3D LAKESIDE VIEW

glVertex3f(-xzSize, yHeight, -xzSize);


glColor3f(0.0, 0.0, 0.8);
glVertex3f(0.0, (yHeight+(0.25*size)), 0.0);

glColor3f(0.5, 0.5, 0.0);


glNormal3f(0.0, 2.2, -1.0);
glVertex3f(-xzSize, yHeight, -xzSize);
glColor3f(0.5, 0.5, 0.0);
glVertex3f(xzSize, yHeight, -xzSize);
glColor3f(0.0, 0.0, 0.8);
glVertex3f(0.0, (yHeight+(0.25*size)), 0.0);
glEnd();

//underside of the roof


glBegin(GL_POLYGON);
glColor3f(8.0, 0.0, 0.2);
glVertex3f(xzSize, yHeight, xzSize);
glVertex3f(-xzSize, yHeight, xzSize);
glVertex3f(-xzSize,-yHeight, -xzSize);
glVertex3f(xzSize, yHeight, -xzSize);
glEnd();
glPopMatrix();
}

void drawHouse(p2D pos,const GLfloat size)


{
const GLfloat xzSize = (0.5*size) + (0.075*size);
const GLfloat yHeight = (0.5*size);

glPushMatrix();
glTranslatef(pos[0], (size)/2, pos[1]);
//glColor3f(0.6, 0.1, 0.1);
glutSolidCube(size);

//draw chimney
DEPT OF CSE, GMIT 2023-2024 Page 16
3D LAKESIDE VIEW

glPushMatrix();
glTranslatef(0.25*size, 0.6*size, 0.0);
glScalef(1.0, 2.0, 1.0);
glutSolidCube(0.2*size);
glPopMatrix();

//draw roof using triangles


glBegin(GL_TRIANGLES);
glColor3f(0.0, 0.0, 0.2);
glNormal3f(1.0, 2.2, 0.0);
glVertex3f(xzSize, yHeight, xzSize);
glColor3f(0.5, 0.5, 0.0);
glVertex3f(xzSize, yHeight, -xzSize);
glColor3f(0.0, 0.0, 0.8);
glVertex3f(0.0, (yHeight+(0.25*size)), 0.0);

glColor3f(0.5, 0.5, 0.0);


glNormal3f(0.0, 2.2, 1.0);
glVertex3f(xzSize, yHeight, xzSize);
glColor3f(0.5, 0.5, 0.0);
glVertex3f(-xzSize, yHeight, xzSize);
glColor3f(0.0, 0.0, 0.8);
glVertex3f(0.0, (yHeight+(0.25*size)), 0.0);

glColor3f(0.5, 0.5, 0.0);


glNormal3f(-1.0, 2.2, 0.0);
glVertex3f(-xzSize, yHeight, xzSize);
glColor3f(0.5, 0.5, 0.0);
glVertex3f(-xzSize, yHeight, -xzSize);
glColor3f(0.0, 0.0, 0.8);
glVertex3f(0.0, (yHeight+(0.25*size)), 0.0);

glColor3f(0.5, 0.5, 0.0);


glNormal3f(0.0, 2.2, -1.0);
glVertex3f(-xzSize, yHeight, -xzSize);
DEPT OF CSE, GMIT 2023-2024 Page 17
3D LAKESIDE VIEW

glColor3f(0.5, 0.5, 0.0);


glVertex3f(xzSize, yHeight, -xzSize);
glColor3f(0.0, 0.0, 0.8);
glVertex3f(0.0, (yHeight+(0.25*size)), 0.0);
glEnd();

//underside of the roof


glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 0.2);
glVertex3f(xzSize, yHeight, xzSize);
glVertex3f(-xzSize, yHeight, xzSize);
glVertex3f(-xzSize, yHeight, -xzSize);
glVertex3f(xzSize, yHeight, -xzSize);
glEnd();
glPopMatrix();
}

void Drawlake()
{
//back section
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,8.0);
glNormal3f(0, 1, 0);

glVertex3f(50.0, 0.0, 0.0);


glVertex3f(-50.0, 0.0, 0.0);
glVertex3f(-50.0, 0.0, -50.0);
glVertex3f(50.0, 0.0, -50.0);
glEnd();

//green grass in background


glBegin(GL_POLYGON);
glColor3f(0.0,0.6,0.0);
glNormal3f(0, 1, 0);
glVertex3f(50.0, 0.01, -1.0);
DEPT OF CSE, GMIT 2023-2024 Page 18
3D LAKESIDE VIEW

glVertex3f(-50.0, 0.01, -1.0);


glVertex3f(-50.0, 0.01, -50.0);
glVertex3f(50.0, 0.01, -50.0);
glEnd();

//slanted beach/waterfront
glBegin(GL_POLYGON);
glColor4f(1.0, 1.0, 0.0, 1.0);
glNormal3f(0, 0.6, 0.3);
glVertex3f(50.0, 0.0, 0.0);
glVertex3f(-50.0, 0.0, 0.0);

glColor3f(0.0, 0.0, 0.0);


glVertex3f(-50.0, -6.0, 6.0);
glVertex3f(50.0, -3.0, 6.0);
glEnd();

//draw ocean "floor"


glBegin(GL_POLYGON);
glColor4f(0.7, 0.7, 0.2, 1.0);
glVertex3f(50.0, -0.5, 0.0);
glVertex3f(-50.0, -0.5, 0.0);
glVertex3f(-50.0, -0.5, 6.0);
glVertex3f(50.0, -0.5, 6.0);
glEnd();

//draw water surface - translucent


glBegin(GL_POLYGON);
glColor4f(0.0, 0.2, 1.0, 0.75);
glVertex3f(50.0, -0.1, 0.0);
glVertex3f(-50.0, -0.1, 0.0);
glVertex3f(-50.0, -0.1, 6.0);
glVertex3f(50.0, -0.1, 6.0);
glEnd();
}
DEPT OF CSE, GMIT 2023-2024 Page 19
3D LAKESIDE VIEW

void Drawbridge()
{
//drawing of main top piece
glScalef(1.0, 0.2, 2.0);
glTranslatef(-5.25, 0.5, 0.8);
glColor3f(1.0, 1.0, 1.0);
glutSolidCube(1.0);

//drawing of six legs


glColor4f(0.05, 0.05, 0.0, 1.0);
glPushMatrix();
glTranslatef(0.47, -2.0, 0.5);
glScalef(0.1, 8.0, 0.1);
glutSolidCube(1.0);
glPopMatrix();

glPushMatrix();
glTranslatef(-0.47, -2.0, 0.5);
glScalef(0.1, 8.0, 0.1);
glutSolidCube(1.0);
glPopMatrix();

glPushMatrix();
glTranslatef(0.47, -2.0, 0.0);
glScalef(0.1, 8.0, 0.1);
glutSolidCube(1.0);
glPopMatrix();

glPushMatrix();
glTranslatef(-0.47, -2.0, 0.0);
glScalef(0.1, 8.0, 0.1);
glutSolidCube(1.0);
glPopMatrix();

DEPT OF CSE, GMIT 2023-2024 Page 20


3D LAKESIDE VIEW

glPushMatrix();
glTranslatef(0.47, -2.0, -0.5);
glScalef(0.1, 8.0, 0.1);
glutSolidCube(1.0);
glPopMatrix();

glPushMatrix();
glTranslatef(-0.47, -2.0, -0.5);
glScalef(0.1, 8.0, 0.1);
glutSolidCube(1.0);
glPopMatrix();
}

void DrawTree(p2D coord)


{
glPushMatrix();
glTranslatef(coord[0], 0.9, coord[1]);

//drawing tree trunk in cylinder form


glPushMatrix();
glColor3f(0.5, 0.35, 0.05);
glRotatef(90.0, 1.0, 0.0, 0.0);
glCallList(startList+1);
glPopMatrix();

//drawing upper section of the tree in green color


glColor3f(0.0, 0.6, 0.0);
glTranslatef(0.0, -0.25, 0.0);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glutSolidCone(0.75, 2.0, 20,20);

glTranslatef(0.0, 0.0, 0.5);


glutSolidCone(0.75, 2.0, 20,20);

glTranslatef(0.0, 0.0, 0.5);


DEPT OF CSE, GMIT 2023-2024 Page 21
3D LAKESIDE VIEW

glutSolidCone(0.75, 2.0, 20,20);


glPopMatrix();
}

void DrawWaves()
{
const GLfloat waveHeight = -0.099;
waveDistance = waveDistance-0.8;
if (waveDistance <= 0.25)
waveDistance = 5.0;
glPushMatrix();
glTranslatef(0.0, 0.0, waveDistance);
glBegin(GL_TRIANGLES);
glColor4f(1.0, 1.0, 1.0, 1.0);
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-2.5, waveHeight, 0.0);
glVertex3f(-1.5, waveHeight, 0.0);
glColor4f(0.0, 0.2, 1.0, 0.2); //integrating transparent blue color
glVertex3f(-2.0, waveHeight, 0.25);

glColor4f(1.0, 1.0, 1.0, 1.0);


glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-1.2, waveHeight, 0.0);
glVertex3f(-0.2, waveHeight, 0.0);
glColor4f(0.0, 0.2, 1.0, 0.2);
glVertex3f(-0.7, waveHeight, 0.25);

glColor4f(1.0, 1.0, 1.0, 1.0);


glNormal3f(0.0, 1.0, 0.0);
glVertex3f(0.5, waveHeight, 0.0);
glVertex3f(1.5, waveHeight, 0.0);
glColor4f(0.0, 0.2, 1.0, 0.2);
glVertex3f(1.0, waveHeight, 0.25);
glEnd();
glPopMatrix();
DEPT OF CSE, GMIT 2023-2024 Page 22
3D LAKESIDE VIEW

void DrawBoat()
{
glPushMatrix();
glTranslatef(-0.68, 0.0, 1.9);
glRotatef(boatAngle, 0.0, 1.0, 0.0); //Boat rotation
glTranslatef(1.0, -0.1, 0.0);
glRotatef(boatFlip, 0.0, 1.0, 0.0);

//drawing boat structure


glPushMatrix();
glColor3f(0.0, 0.0, 0.2);
glTranslatef(0.0, 0.3, 0.0);
glScalef(0.7, 8.0, 0.5);
glutSolidCube(0.1);
glPopMatrix();

glPushMatrix();
glColor3f(1.0, 1.0, 1.0);
glTranslatef(0.0, 0.2, 0.0);
glRotatef(-90.0, 1.0, 0.0, 0.0);
glScalef(0.1, 1.0, 1.0);
glutSolidCone(0.3, 0.5, 20, 20);
glPopMatrix();

glColor3f(0.4, 0.2, 0.2);


glPushMatrix();
glScalef(0.5, 0.5, 1.0);
glutSolidCube(0.5);
glPopMatrix();

glPushMatrix();
glTranslatef(0.0, 0.0, 0.25);
glScalef(0.3, 2.0, 2.0);
DEPT OF CSE, GMIT 2023-2024 Page 23
3D LAKESIDE VIEW

glutSolidCube(0.1);
glPopMatrix();

glBegin(GL_TRIANGLES);
glNormal3f(0.0, 1.0, 0.0);
glVertex3f(-0.125, 0.125, -0.25);
glVertex3f(0.125, 0.125, -0.25);
glVertex3f(0.0, 0.125, -0.5);

glNormal3f(-0.1875, -0.1875, -0.03125);


glVertex3f(-0.125, 0.125, -0.25);
glVertex3f(0.0, 0.125, -0.5);
glVertex3f(-0.125, -0.125, -0.25);

glNormal3f(0.1875, -0.1875, -0.03125);


glVertex3f(0.125, 0.125, -0.25);
glVertex3f(0.0, 0.125, -0.5);
glVertex3f(0.125, -0.125, -0.25);

glNormal3f(0.0, -0.5, -0.5);


glVertex3f(0.125, -0.125, -0.25);
glVertex3f(-0.125, -0.125, -0.25);
glVertex3f(0.0, 0.125, -0.5);
glEnd();
glPopMatrix();
}

void Drawmoon()
{
glPushMatrix();
glTranslatef(6.0, 6.8, 0.0);
glColor3f(6.0, 6.0, 6.0);
glutSolidSphere(0.28, 20, 20);

glRotatef(60.0, 0.0,0.0,1.0);
DEPT OF CSE, GMIT 2023-2024 Page 24
3D LAKESIDE VIEW

glPushMatrix();
glTranslatef(-3.0, 2.58, 3.0);
glColor3f(6.0, 6.0, 6.0);
glutSolidSphere(0.021, 20, 20);
glRotatef(60.0, 0.0,0.0,1.0);
glPopMatrix();

glPushMatrix();
glTranslatef(-4.0, 2.58, 2.0);
glColor3f(6.0, 6.0, 6.0);
glutSolidSphere(0.021, 20, 20);
glRotatef(60.0, 0.0,0.0,1.0);
glPopMatrix();
glPushMatrix();
glTranslatef(-3.0, 3.58, 2.0);
glColor3f(6.0, 6.0, 6.0);
glutSolidSphere(0.021, 20, 20);
glRotatef(60.0, 0.0,0.0,1.0);
glPopMatrix();

glPopMatrix();
}

void Display(void)
{
//cordinates form={x,z};
p2D house1 = {-10.0, -8.0};
p2D house2 = {2.3, -8.6};
p2D house3 = {-5.8, -8.3};
p2D house4 = {-15.0, -8.3};

p2D tree1 = {-12.39, -0.75};


p2D tree2 = {9.08, -0.75};

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
DEPT OF CSE, GMIT 2023-2024 Page 25
3D LAKESIDE VIEW

glColor3f(1.0,1.0,8.0);

//drawing houses at specified(p2d positions) positions


glPushMatrix();
glRotatef(-5.0, 4.0, 1.0, 0.0);
glScaled(1.5,1.5,1.5);
drawHousem(house1, 4.2);
glPopMatrix();

glPushMatrix();
glTranslated(8,0,0);
glRotatef(-5.0, 4.0, 1.0, 0.0);
glScaled(1.5,1.5,1.5);
drawHousem(house1, 4.2);
glPopMatrix();

glPushMatrix();
glTranslated(16.5,0,0);
glRotatef(-5.0, 4.0, 1.0, 0.0);
glScaled(1.5,1.5,1.5);
drawHousem(house1, 4.2);
glPopMatrix();

glPushMatrix();
glTranslated(25.5,0,0);
glRotatef(-5.0, 4.0, 1.0, 0.0);
glScaled(1.5,1.5,1.5);
drawHousem(house1, 4.2);
glPopMatrix();

glPushMatrix();
glTranslated(16.5,6,0);
glRotatef(-5.0, 4.0, 1.0, 0.0);
glScaled(1.5,1.5,1.5);
drawHousem(house1, 3.3);
DEPT OF CSE, GMIT 2023-2024 Page 26
3D LAKESIDE VIEW

glPopMatrix();

glPushMatrix();
glTranslated(8,6,0);
glRotatef(-5.0, 4.0, 1.0, 0.0);
glScaled(1.5,1.5,1.5);
drawHousem(house1, 3.3);
glPopMatrix();

glPushMatrix();
glTranslated(0,6,0);
glRotatef(-5.0, 4.0, 1.0, 0.0);
glScaled(1.5,1.5,1.5);
drawHousem(house1, 3.3);
glPopMatrix();

glPushMatrix();
glRotatef(-4.0, 0.0, 1.0, 0.0);
glTranslatef(0.0,9.0, 0.0);
glColor3f(0.0, 0.0, 0.2);
drawHouse(house2, 1);
glPopMatrix();

glPushMatrix();
glRotatef(-3.0, 0.0, 1.0, 0.0);
glTranslatef(0.0,9.0, 0.0);
drawHouse(house3, 1);
glPopMatrix();

glPushMatrix();
glRotatef(-4.0, 0.0, 1.0, 0.0);
glTranslatef(0.0,9.3, 0.0);
drawHouse(house4, 1);
glPopMatrix();

DEPT OF CSE, GMIT 2023-2024 Page 27


3D LAKESIDE VIEW

glPushMatrix();
Drawbridge();
glPopMatrix();

//drawing moon reflection


glPushMatrix();
glColor3f(6.0, 6.0, 6.0);
glTranslatef(4.9, -0.4, 2.0);
glutSolidSphere(0.25, 20, 20);
glPopMatrix();

//drawing trees at specified(p2d positions) positions


DrawTree(tree1);
DrawTree(tree2);

DrawBoat();
Drawmoon();

//drawing 3 stones above the lake


glColor3f(0.0, 0.0, 0.1);
glPushMatrix();
glTranslatef(-4.,-0.1, 5.6);
glScalef(1.0, 0.3, 1.0);
glutSolidSphere(0.28, 20, 20);
glPopMatrix();

glPushMatrix();
glTranslatef(-5, -0.1, 4.6);
glScalef(1.0, 0.3, 1.0);
glutSolidSphere(0.3, 20, 20);
glPopMatrix();

glPushMatrix();
glTranslatef(-4.6, -0.1, 4.0);
glScalef(1.0, 0.3, 1.0);
DEPT OF CSE, GMIT 2023-2024 Page 28
3D LAKESIDE VIEW

glutSolidSphere(0.3, 20, 20);


glPopMatrix();

Drawlake();
DrawWaves();
glutSwapBuffers();
}

void MyReshape(int w,int h)


{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(68.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
gluLookAt(-1.3,2.2,9.8, -1.20,1.5,0.0, 0.0, 0.05, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Display();
}

void clockWise() //rotating boat clockwise


{
boatAngle -= 1%360;
boatFlip = 180.0;
glutPostRedisplay();
}

void aClockWise() //rotating boat anti-clockwise


{
boatAngle += 1%360;
boatFlip = 0.0;
glutPostRedisplay();
}

void Keyboard(unsigned char key, int x, int y)


DEPT OF CSE, GMIT 2023-2024 Page 29
3D LAKESIDE VIEW

{
if (key == 27) //27-ASCII VALUE OF ESCAPE
exit(0);

if (key =='p') //"p" refers to pause all the movement


glutIdleFunc(NULL);

if (key =='r') //"r" refere to resume all the movement


{
if (dirFlag == 0)
glutIdleFunc(aClockWise);
else
glutIdleFunc(clockWise);
}

if (key =='c') //"c" refers to change in the boat movement


clockwise or anticlockwise
{
if (dirFlag == 0)
{
dirFlag = 1;
glutIdleFunc(clockWise);
}
else
{
dirFlag = 0;
glutIdleFunc(aClockWise);
}
}
}

int main(int argc,char** argv)


{
DEPT OF CSE, GMIT 2023-2024 Page 30
3D LAKESIDE VIEW

glutInit(&argc, argv) ;
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPT);
glutInitWindowSize(490,330);
glutInitWindowPosition(100,100);
glutCreateWindow("3D LAKESIDE VIEW");
init();
glutKeyboardFunc(Keyboard);
glutReshapeFunc(MyReshape);
glutDisplayFunc(Display);
glutIdleFunc(aClockWise);
glutFullScreen();
glutMainLoop();
}

Snapshots:-

DEPT OF CSE, GMIT 2023-2024 Page 31


3D LAKESIDE VIEW

1)Initially when the program is executed and the key “p”(pause) is


pressed.

Pause view of the 3d lakeside caused by pressing “p” key

2)When the program is in pause mode and by pressing the key


“r”(resume) the program animation is invoked.
In the resume mode:-
 By pressing key “c” once the boat in the lake rotates clockwise.
 By pressing key “c” twice the boat in the lake rotates anti
clockwise.

Clockwise Rotation Of the boat in the lake

DEPT OF CSE, GMIT 2023-2024 Page 32


3D LAKESIDE VIEW

Anti- Clockwise Rotation Of the boat in the lake

3)Finally by pressing “Esc”(Escape) key the program execution in


terminated.

Termination of the program caused by pressing “Esc” key

DEPT OF CSE, GMIT 2023-2024 Page 33


3D LAKESIDE VIEW

Chapter-7

CONCLUSION AND FUTURE SCOPE

7.1 CONCLUSION
The 3D Lakeside View has been tested under Windows XP,10 and has been found to provide
ease of use and manipulation to the user. The 3D Lakeside View created for the Windows XP,10
operating systems can be used to draw lines, boxes, circles, triangles, and polygons. It has a very
simple and aesthetic user interface.
We found designing and developing it as an interesting learning experience. It helped us to
learn about computer graphics, design of Graphical User Interfaces, interface to the user, user
interaction handling and screen management. The graphics editor provides all and more than the
features that have been detailed in the university syllabus.

7.2 FUTURE ENHANCEMENTS

These are the features that are planned to be supported in the future

* Support for camera view in all the 3-axis.


* Support for more 3d transformations .
* Support for advance texture mapping.
* Support for advance interpolation of colors.

DEPT OF CSE, GMIT 2023-2024 Page 34


3D LAKESIDE VIEW

Chapter-8

BIBLIOGRAPHY
1) Edward Angel’s Interactive Computer Graphics Pearson Education 5th Edition

2) Interactive computer Graphics --A top down approach using open GL--by
Edward Angle

3) Jackie .L. Neider, Mark Warhol, Tom.R.Davis, "OpenGL Red Book", Second
Revised Edition, 2005.

4) Donald D Hearn and M.Pauline Baker, "Computer Graphics with OpenGL",


3rd Edition.

5)www.opengl.org :-provided reference for mapping colors to each objects and


brief explanation of the opengl functions.

6) www.cprogramming.com : - provided references regarding all c functions and


their uses.

7) www.stackoverflow.com :- provided help get rid of all types of error occurred


regarding uses of OpenGL functions.

8) www.lighthouse3d.com : - OpenGL tutorial for implementing the OpenGL


functions in Source code.

Chapter-9
DEPT OF CSE, GMIT 2023-2024 Page 35
3D LAKESIDE VIEW

APPENDIX

9.1 USER MANUAL


Creating the Project

Step 1: To create an empty console project in CodeBlocks, do the following:

1. Create a new project(FileNewProject)


2. In the Project Types: select Glut Project. Then specify the name of the project, select the
location for the project and click OK.
Click the file name of the project in the workspace tab on the left, and double click on the source
button.

Step 2: Add source code in the editor field

1. After adding the source code onto the editor field then,save the file and debug it using
the “Debug” option on the menu.Thus once there are no errors the program is processed for
execution else the errors are first resolved and then execution is done.

Step 3: Executing the program

1.Finally after debugging the program the execution happen by pressing the “build and run”
option in the build menu present on top of the editor window of codeblocks.
Controls:-

 By pressing key ‘p’ the movement of the 3d lakeside view pause.


 By pressing key ‘r’ the movement of the 3d lakeside view resumes.
 By pressing key ‘c’ once the boat in the lake rotates clockwise.
 By pressing key ‘c’ twice the boat in the lake rotates anti-clockwise.

9.2 PERSONAL DETAILS

DEPT OF CSE, GMIT 2023-2024 Page 36


3D LAKESIDE VIEW

NAME: KIRAN KUMAR .M

USN: 1DT14CS039

SEMESTER AND SECTION: 6TH ‘A’ Sec

DEPARTMENT: COMPUTER SCIENCE AND ENGINEERING

COLLEGE: DAYANANDASAGAR ACADEMY OF TECHNOLOGY & MANAGEMENT

EMAIL ID: [email protected]

NAME: CHETHAN.B.S

USN: 1DT14CS028

SEMESTER AND SECTION: 6TH ‘A’ Sec

DEPARTMENT: COMPUTER SCIENCE AND ENGINEERING

COLLEGE: DAYANANDASAGAR ACADEMY OF TECHNOLOGY & MANAGEMENT

EMAIL ID: [email protected]

DEPT OF CSE, GMIT 2023-2024 Page 37

You might also like