Opengl Report-1.1
Opengl Report-1.1
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:
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.
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.
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.
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.
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.
Chapter-3
Processor - Intel Processor 100 MHz / Pentium Processor 100 MHz or Higher Versions.
Chapter-4
DESIGN
Chapter-5
IMPLEMENTATION
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.
Void glutInit (int *argc, char**argv):-Initializes GLUT, the arguments from main are
passed in and can be used by the application.
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.
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
Translate
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.
Perspective projection
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.
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.
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: -
glEnable(GL_LIGHTING);
glDisable(GL_LIGHTING);
"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
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();
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient)
;
glColorMaterial(GL_FRONT, GL_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
// house door
glPushMatrix();
glColor3f(0.0,0.0,0.0);
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();
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();
void Drawlake()
{
//back section
glBegin(GL_POLYGON);
glColor3f(1.0,1.0,8.0);
glNormal3f(0, 1, 0);
//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);
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);
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();
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 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);
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);
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();
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);
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};
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);
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();
glPushMatrix();
Drawbridge();
glPopMatrix();
DrawBoat();
Drawmoon();
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
Drawlake();
DrawWaves();
glutSwapBuffers();
}
{
if (key == 27) //27-ASCII VALUE OF ESCAPE
exit(0);
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:-
Chapter-7
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.
These are the features that are planned to be supported in the future
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.
Chapter-9
DEPT OF CSE, GMIT 2023-2024 Page 35
3D LAKESIDE VIEW
APPENDIX
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.
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:-
USN: 1DT14CS039
NAME: CHETHAN.B.S
USN: 1DT14CS028