Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 30

3D Car Riding OpenGL Project Computer Graphics Project

CHAPTER 1

INTRODUCTION
Graphics provides one of the natural means of communicating with a computer. Graphics has also
become a key technology for communicating ideas, data and trends in most areas of commerce, science,
engineering and education. So, graphics refers to pictures, sketch of building, flowcharts, control flow
diagrams, bar charts, and pie charts.

Computer graphics is the creation, manipulation and storage of models and images of picture objects
by the aid of computers. This was started with the display of plotters and CRT. Computer graphics is also
defined as the study of techniques to improve the communication between user and machine. Thus, computer
graphics is one of the effective media of communication between machine and user.

Classification:

Computer graphics is broadly classified into three categories:

 Based on type of Object


2 -Dimensional Graphics (Ex. Pixel, line, circle etc...)
3- Dimensional Graphics (Ex. Cube, polyhedron etc...)
 Based on User Interaction
Interactive Computer Graphics
Non-Interactive Computer Graphics
 Based on Application
Business or presentation Graphics
Scientific Graphics
Scaled Drawings
Cartoons, games and art work

Dept. of CSE, RRCE 2020-21 1


3D Car Riding OpenGL Project Computer Graphics Project

1.1 HISTORY
The term computer graphics has been used in a broad sense to describe almost everything on computers that is
not text or sound. Typically, the term computer graphics refers to several different things:

 The representation and manipulation of image data by a computer, the various technologies used to
create and manipulate images.
 The images so produced, and
 The sub-field of computer science which studies methods for digitally synthesizing and manipulating
visual content see study of computer graphics.

The advance in computer graphics was to come from one MIT student, Ivan Sutherland. In 1961
Sutherland created another computer drawing program called Sketchpad. Using a light pen, Sketchpad
allowed one to draw simple shapes on the computer screen, save them and even recall them later. The light
pen itself had a small photoelectric cell in its tip. This cell emitted an electronic pulse whenever it was placed
in front of a computer screen and the screen’s electron gun fired directly at it. By simply timing the electronic
pulse with the current location of the electronic gun, it was easy to pinpoint exactly where the pen was on the
screen at any given moment. Once that was determined, the computer could then draw a cursor at that
location.

These early computer graphics were Vector graphics, composed of thin lines whereas modern day
graphics are Raster based using pixels. The difference between vector graphics and raster graphics can be
illustrated with a shipwrecked sailor. He creates an SOS sign in the sand by arranging rocks in the shape of the
letters’ “SOS”. He also has some brightly colored rope, with which he makes a second “SOS” sign by
arranging the rope in the shapes of the letters. The rock SOS sign is similar to raster graphics. Every pixel has
to be individually accounted for. The rope SOS sign is equivalent to vector graphics. The computer simply
sets the starting point and ending point for the line and perhaps bends it a little between the two end points.

Dept. of CSE, RRCE 2020-21 2


3D Car Riding OpenGL Project Computer Graphics Project

1.2. PIONEERS IN GRAPHIC DESIGN

Charles C Suri

Charles C Suri is a pioneer in computer animation and digital fine art and created the first computer art
in 1964.Csuri was recognized by Smithsonian as the father of digital art and computer animation, and as a
pioneer of computer animation by the Museum of Modern Art (MoMA) and (ACM-SIGGRAPH).

Donald P Greenberg

Donald P Greenberg is a leading innovator in computer graphics. Greenberg has authored hundreds of
articles and served as a teacher and mentor to many prominent computer graphics artists, animators, and
researchers such as Robert L. Cook, Marc Levoy, and Wayne Lytle. Many of his former students have won
academy awards for technical achievements and several have won the SIGGRAPH achievement award.
Greenberg was the founding director of the NSF center for computer graphics and scientific visualization.

Michael Noll

Noll was one of the first researchers to use a digital computer to create artistic patterns and to
formalize the use of random processes in the creation of visual arts. He began creating digital computer art in
1962, making him one of the earliest digital computer artists. In 1965, Noll along with Frieder-Nake and
Georg-Nees were the first to publicly exhibit the computer art. During April 1965, the Howard Wise Gallery
exhibited Noll’s computer art along with random-dot patterns by Bela Julesz.

Dept. of CSE, RRCE 2020-21 3


3D Car Riding OpenGL Project Computer Graphics Project

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 Chromos Group.

In the 1980s, developing software that could function with a wide range of graphics hardware was a
real challenge. By the early 1990s, Silicon Graphics (SGI) was a leader in 3D graphics for workstations. SGI's
competitors (including Sun Microsystems, Hewlett-Packard and IBM) were also able.

In addition, SGI had a large number of software customers; by changing to the OpenGL API they
planned to keep their customers locked onto SGI (and IBM) hardware for a few years while market support
for OpenGL matured to bring to market 3D hardware, supported by extensions made to the PHIGS standard.
In 1992, SGI led the creation of the OpenGL architectural review board (OpenGL ARB), the group of
companies that would maintain and expand the OpenGL specification took for years to come.

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.[Donald D Hearn and M.Pauline Baker, "Computer Graphics with
OpenGL", 3rd Edition]. It initially showed some promise of bringing order to the world of interactive 3D

Dept. of CSE, RRCE 2020-21 4


3D Car Riding OpenGL Project Computer Graphics Project

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.

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. This concept is
being obtained from.

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, RRCE 2020-21 5


3D Car Riding OpenGL Project Computer Graphics Project

CHAPTER 3

PROBLEM DEFINITION
The aim of this project is to create a 3-D/VIRTUAL CAR RIDING. The viewer is allowed to roam around in
the area and see the cars closely and to drive a car and park it in the car park area. The parking area is
surrounded by a number of houses.

First the co-ordinates of the car is calculated and then using the OPENGL PRIMITIVES the car is
constructed. The PRIMITIVES used are:-

1. GL_LINES

2. GL_POLYGON

3. GL_QUADS

4. GL_TRIANGLE

In a similar way the 3D house is constructed.

A display list is constructed for each of these objects. These display lists are used every time a car or house
has to be constructed.

So, to create the 36 cars in the parking lot the “car_display_list “ is called 36 times from within a loop and are
translated each time by suitable values to place them correctly.

Similarly, to construct the houses “house_display_list” is called and are suitably translated, scaled and rotated
to place them properly.

For the movement of camera GluLookAt() function is used . The controls are:-

x- Rotate the car in 'x' direction

y- Rotate the car in 'y' direction

z- Rotate the car in 'z' direction

a- Increase the size of car in 'x' direction

Dept. of CSE, RRCE 2020-21 6


3D Car Riding OpenGL Project Computer Graphics Project

s- Increase the size of car in 'y' direction

q- Increase the size of car in 'z' direction

u- Camera top view

f- Camera side view

left arrow key - Move car in forward direction

right arrow key- Move car in backward direction

esc - Exit from the program

spacebar - Enter the main screen from start screen.

Dept. of CSE, RRCE 2020-21 7


3D Car Riding OpenGL Project Computer Graphics Project

CHAPTER 4

SYSTEM REQUIREMENTS
4.1 SOFTWARE REQUIREMENTS

 Operating System : Windows 7/10//XP


 Language : C/C++
 Compiler : Microsoft visual studio 2010 or Higher version
 OpenGL : library Files and DLL files

4.2 HARDWARE REQUIREMENTS

 Processor : Intel Core


 RAM : 4GB or Higher
 Hard Disk : 20 GB(approx.)
 Monitor : VGA Color Monitor

Dept. of CSE, RRCE 2020-21 8


3D Car Riding OpenGL Project Computer Graphics Project

CHAPTER 5

DESIGN &IMPLEMENTATION

5.1 OPENGL GRAPHICS ARCHECTURE

Figure 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.
 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.
Dept. of CSE, RRCE 2020-21 9
3D Car Riding OpenGL Project Computer Graphics Project

 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 actually 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.

Dept. of CSE, RRCE 2020-21 10


3D Car Riding OpenGL Project Computer Graphics Project

5.2 SOFTWARE DESIGN

START

MAIN ()

INIT ()

DISPLAY ()

MOUSE () KEYBOARD ()

LEFT RIGHT MOVE PROCESS


BUTTON BUTTON CAR () NORMAL
KEYS ()

HOUSE CONTROLS

STOP

Figure 2: Software Design

Dept. of CSE, RRCE 2020-21 11


3D Car Riding OpenGL Project Computer Graphics Project

5.3 SOFTWARE IMPLEMENTATION


5.3.1 KEYBOARD FUNCTION:

KEYBOARD
FUNCTION ()

if (key == 'q')

exit(0); switch (key) {


if(key=='t') case GLUT_KEY_LEFT :
angle -= 0.05f;
gluLookAt(1,190,50,0,0 ,-
10,0.0,1.0,.0); orientMe(angle);break;
if(key=='a') case GLUT_KEY_RIGHT :
angle +=0.05f;
moveMeFlat(4);
orientMe(angle);break;
xxxx=1,yyyy=0;
case GLUT_KEY_UP :
if(key=='s')
moveMeFlat(2);
moveMeFlat(-4);xxxx=1,yyyy=0;
xxxx=0,yyyy=0;break;
if(key=='w')
case GLUT_KEY_DOWN :
moveMeFlat(4); moveMeFlat(- 2);

yyyy=1; xxxx=0,yyyy=0;break; }

xxxx=0;

Dept. of CSE, RRCE 2020-21 12


3D Car Riding OpenGL Project Computer Graphics Project

5.3.2 DISPLAY FUNCTION:

DISPLAY
FUNCTION ()

glColor3f(0.25f, 0.25f, 0.25f);

glBegin(GL_QUADS);

glVertex3f(-100.0f, 0.0f, -100.0f);

glVertex3f(-100.0f, 0.0f, 100.0f);

glVertex3f( 100.0f, 0.0f, 100.0f);

glVertex3f( 100.0f, 0.0f, -100.0f);

glEnd();

for( i = -3; i < 3; i++)

for( j=-3; j < 3; j++) {

glPushMatrix();

glTranslatef((i)*10.0,0,(j) * 10.0);

glColor3ub(a[i],b[j],c[i]);

glCallList(carr_display_list);

glPopMatrix(); }

glTranslatef(-20.0,0.0,0.0);
glCallList(house_display_list);

Dept. of CSE, RRCE 2020-21 13


3D Car Riding OpenGL Project Computer Graphics Project

5.3.3 RESHAPE FUNCTION:

RESHAPE
FUNCTION ()

if(h == 0)

h = 1;

ratio = 1.0f * w / h;
glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glViewport(0, 0, w, h);
gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(x, y, z, x + lx,y + ly,z + lz,


0.0f,1.0f,0.0f);

5.4 PROJECT GOAL:


The aim of this project is to create a 3-D/VIRTUAL CAR RIDING. The viewer is allowed to roam
around in the parking area and see the cars closely and to drive a car and park it in the car park area. The
parking area is surrounded by a number of houses.

5.5 SCOPE :
It is developed in MICROSOFT VISUAL STUDIO 2019. It has been implemented on WINDOWS
platform. The 2-D graphics package designed here provides an interface for the users for handling the
display and manipulation of Ship Exploratory. The Keyboard is the main input device used.

Dept. of CSE, RRCE 2020-21 14


3D Car Riding OpenGL Project Computer Graphics Project

5.6 CONCEPTS AND PRINCIPLES OF OPENGL


The OpenGL model

Figure relationships between an application program, the graphics system, input and output devices,
and the user.

The Graphical Interaction:

The application program has its own internal model. It draws the graphics using the facilities of the
graphics system. The user views the graphics, and uses input devices, such as a mouse, to interact.
Information about the users is sent back to the applications are sent back to the application, which decides
what action to take. Typically, it will make changes to its internal model, which will cause the graphics to be
updated, and so another loop in the interaction cycle begins.

Application model

Application program

Graphics system (OpenGL)

Mouse etc. Display


screenscreen
User

Figure 3: Graphical interaction loop

Dept. of CSE, RRCE 2020-21 15


3D Car Riding OpenGL Project Computer Graphics Project

5.7 OPENGL related libraries


LIBRARIES:

OpenGL provides a powerful but primitive set of rendering command, and all the 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 Kilgard, to
hide the complexities of differing window APIs.

Include Files:

For all OpenGL applications, you want to include the gl.h header file in every file. Almost all OpenGL
applications use GLU, which also requires inclusion of the glu.h header file. So almost every OpenGL source
file begins with:

#include<GL/gl.h>; #include<GL/glu.h>

5.8 WINDOWS MANAGEMENT IN OPENGL


Five routines perform tasks necessary to initialize a window.

 glutInit(int *argc, char **argv) initializes GLUT and processes any command line arguments (for X,
this would be options like –display and -geometry). It should be called before any other GLUT
routine.
 glutInitDisplayMode(unsigned int mode) specifies whether to use an RGBA or color-index color
model. We can also specify whether we want a single or double buffered window. We can use this
routine to indicate the window to have associated depth, stencil or accumulation buffer.
GLUT SINGLE: selects a single-buffered window which is the default if isn’t called;GLUT
DOUBLE: selects a double-buffered window.
 glutInitWindowPosition(intx,inty) specifies the screen location for the upper-left corner of your
window.
Dept. of CSE, RRCE 2020-21 16
3D Car Riding OpenGL Project Computer Graphics Project

 glutInitWindowSize (intwidth,intsize) specifies the size, pixels, of window.


 glutCreateWindow (char *string) creates a window with an OpenGL context. It returns a unique
identifier for the new window.

5.9 CALLBACK FUNCTIONS


All callback function, more often just called a callback, in C function, written by the application
programmer. But there’s one important difference between a callback function and an ordinary C function:
application never calls the callback function directly. Instead, the callback function is called by OpenGL.

The Display Callback:

glutDisplayFunc(void (*func)(void)) is the first and most important event callback function. Whenever
GLUT determines the contains of the window to be redisplayed.

 The callback function registered by glutDisplayFunc() is executed. Therefore we should put all the
routines you need to redraw the scene in the display callback function.
 Void glutDisplayFunc(void(*func)(void));

glutDisplayFunc() registers the name of the callback function to be invoked when OpenGL needs to
redisplay the contents of the window. The application must register a display function – it is not optional.

If your program changes the contents of the window, sometimes you will have to call
glutPostRedisplay(void), which gives glutMainLoop() a nudge to call the registered display callback at its
next opportunity.

The KeyBoard Callback:

 void glutKeyboardFunc(void(*func)(unsigned char key,intx,inty));


 glutKeyboardFunc() registers the application function to call when OpenGL detects a key press
generating an ASCII character. This can only occur when the mouse focus is inside the OpenGL
window. It expects a function func() which returns void, and has three arguments key, x and y. So, it’s
function is:

void keyboard(unsigned char key,intx,inty)

/* called when a key is pressed */

Dept. of CSE, RRCE 2020-21 17


3D Car Riding OpenGL Project Computer Graphics Project

Three values are passed to the callback function: key is the ASCII code of the key pressed; x and y give the
pixel position of the mouse at the time. Inside the keyboard() callback, we look at the value of key. If it’s 27
we call the standard C function exit() to terminate the program cleanly.

The Mouse Callback:

 void glutMouseFunc(void (*func)(intbutton, intstate , intx, inty));

glutMouseFunc() register an application callback function which GLUT will call when the user presses a
mouse button within the window. The following values are passed to the callback function:

 button records which button was pressed, and can be


-GLUT LEFT BUTTON
-GLUT MIDDLE BUTTON
-GLUT RIGHT BUTTON
 state records whether the event was generated by pressing the button (GLUT DOWM), or releasing it
(GLUT UP).
 x,y give the current mouse position in pixels. Note: when using OpenGL with X, the mouse y position
is measured from the top of the window.

Handling Input Events:

You can use these routines to register callback commands that are invoked when specified events occur.

 glutReshapeFunc(void(*func)(intw,inth)) indicates what action should be taken when the window is


resized.
 glutKeyboardFunc(void(*func)(unsignedchar key,intx,inty)) and glutMouseFunc(void(*func)
(intbutton,intstate,intx,ints)) allow you to link a keyboard key or a mouse button with routine that is
invoked when the key or mouse button is pressed or released.
 glutMotionFunc (void (*func) (intx,inty)) registers a routine to call back when the mouse is moved
while a mouse button is also pressed.

Translation

 void glTranslatef(GLfloatx,GLfloaty,GLfloatz);
glTranslatef () creates a matrix M which performs a translation by (x,y,z) and then post-multiplies the
current matrix by M.
Dept. of CSE, RRCE 2020-21 18
3D Car Riding OpenGL Project Computer Graphics Project

Scaling

 void glScalef(GLfloatx,GLfloaty,GLfloatz);
glScalef() creates a matrix M which performs a scale by (x,y,z) and then post-multiplies the current
matrix by M.

Rotation

 void glRotatef(GLfloatangle,GLfloatx,GLfloaty,GLfloatz);
glRotate() creates a matrix M which performs a counter-clockwise rotation of angle in degrees. The
axis about which the rotation occurs in the vector from the origin (0, 0, 0) to the point (x,y,z),and then
post-multiplies the current matrix by M.

Push and Pop Operations:

There are two functions which operate on the current matrix stack:

glPushMatrix()

glPopMatrix()

voidglPushMatrix(void); Pushes the current matrix stack down one level. The matrix on the top of the stack
is copied into the next-to-top position.

void glPopMatrix(void); Pops the current matrix stack, moving each matrix in the stack one position
towards the top of the stack.

The current matrix stack is determined by the most recent call to glMatrixMode().

5.10 RUNNING THE PROGRAM

After all the setup is completed, GLUT programs enter an event processing loop, glutMainLoop().

void glutMainLoop(void) enters the GLUT processing loop, never to return. Registered callback functions
will be called when the corresponding events instigate them.

Dept. of CSE, RRCE 2020-21 19


3D Car Riding OpenGL Project Computer Graphics Project

CHAPTER 6

SNAPSHOTS

6.1: FRONT PAGE:

This is the first page which appears when the program is executed.

6.2 INITIAL SCREEN:

On pressing the “SPACEBAR” key, first screen of the project is as below

Dept. of CSE, RRCE 2020-21 20


3D Car Riding OpenGL Project Computer Graphics Project

6.3: DIFFERENT CAR OPTIONS:

6.4: CAR DRIVING MODE:

Dept. of CSE, RRCE 2020-21 21


3D Car Riding OpenGL Project Computer Graphics Project

6.5: WHEEL EFFECT:

6.6: NIGHT MODE

Dept. of CSE, RRCE 2020-21 22


3D Car Riding OpenGL Project Computer Graphics Project

CHAPTER 7

CONCLUSION
It has been an interesting journey through the development of this project. At the beginning we used our
limited knowledge to implement only the basic features. However, through the months of development, new
issues and bugs led to new ideas which led to newer methods of implementation which, in turn, led to us
learning even more features of the OpenGL and apply more creative and efficient ways to perform the older
functions.

New methods helped us in adding flexibility to the various parts of the program, making the further addition
of newer features easier and less time consuming which, again, led to the possibility of adding even more
features. This sequential chain reaction of progress and ideas has enabled to learn so much through the months
of working on this project and we have done our best to add as many features as we could and provide a user
interface that is easy and intuitive to use.

Before concluding, it is worth mentioning that this project would never have been possible without the
tremendous amount of encouragement by the staff and guides of our department.

We are content with the outcome of this project and are hopeful that it meets the requirements expected and
we wish that it may inspire others to be creative and critical in the field of computer graphics and have a
newfound appreciation for the Open Graphics Library.

FUTURE SCOPE:

Although it isn’t noticeable on a relatively newer and powerful processor, the method of applying the
transforms pixel by pixel is a very taxing process, especially for larger images of 1080p or higher.

A possible feature to implement could be to perform all the transforms using multithreading to split the
workload onto multiple threads, reducing the minimum computational time required between time steps.

• Since Contrast modifies the RGB values instead of HSL, the contrast should be the last thing that
should be changed after changing any brightness or saturation.

• Addition of complete pixel blur in both directions, and several other transforms is also notable.

• Allowing the user to select his own color model from RGB, HSL, HSV etc. to allow more fine tuning
of the Image.

• More efficient memory management techniques to prevent heavy usage of memory.

Dept. of CSE, RRCE 2020-21 23


3D Car Riding OpenGL Project Computer Graphics Project

CHAPTER 8

APPENDIX
void changeSize(int w, int h)

if (h == 0) // Prevent a divide by zero, when window is too

short

// (you cant make a window of zero width).

h = 1;

ratio = 1.0f * w / h; // Reset the coordinate system before modifying

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

glViewport(0, 0, w, h); // Set the viewport to be the entire window

gluPerspective(45, ratio, 1, 1000);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(x, y, z, x + lx, y + ly, z + lz, 0.0f, 1.0f, 0.0f);

void drawcarr()

glTranslatef(.0, 0.8, 0.0);

glEnable(GL_BLEND); //TRANCPARENCY1

Dept. of CSE, RRCE 2020-21 24


3D Car Riding OpenGL Project Computer Graphics Project

glBlendFunc(GL_ONE, GL_ZERO);//TRANCPARENCY2

glBegin(GL_LINE_LOOP);

glVertex3f(-1.12, -.48, 0.7);//a

glVertex3f(-0.86, -.48, 0.7);//b

glVertex3f(-.74, -0.2, 0.7);//c

glVertex3f(-.42, -.2, 0.7);//d

glVertex3f(-0.3, -.48, 0.7);//e

glVertex3f(.81, -0.48, 0.7);//f

glVertex3f(.94, -0.2, 0.7);//g

glVertex3f(1.24, -.2, 0.7);//h

glVertex3f(1.38, -.48, 0.7);//i

glVertex3f(1.52, -.44, 0.7);//j

glVertex3f(1.52, .14, 0.7);//k

glVertex3f(1.14, 0.22, 0.7);//l

glVertex3f(0.76, .22, 0.7);//m

glVertex3f(.52, 0.56, 0.7);//n

glVertex3f(-0.1, 0.6, 0.7);//0

glVertex3f(-1.02, 0.6, 0.7);//p

glVertex3f(-1.2, 0.22, 0.7);//q

glVertex3f(-1.2, -.28, 0.7);//r

glEnd();

glBegin(GL_LINE_LOOP);

glVertex3f(-1.12, -.48, -0.7);//a'

Dept. of CSE, RRCE 2020-21 25


3D Car Riding OpenGL Project Computer Graphics Project

glVertex3f(-0.86, -.48, -0.7);//b'

glVertex3f(-.74, -0.2, -0.7);//c'

glVertex3f(-.42, -.2, -0.7);//d'

glVertex3f(-0.3, -.48, -0.7);//e'

glVertex3f(.81, -0.48, -0.7);//f'

glVertex3f(.94, -0.2, -0.7);//g'

glVertex3f(1.24, -.2, -0.7);//h'

glVertex3f(1.38, -.48, -0.7);//i'

glVertex3f(1.52, -.44, -0.7);//j'

glVertex3f(1.52, .14, -0.7);//k'

glVertex3f(1.14, 0.22, -0.7);//l'

glVertex3f(0.76, .22, -0.7);//m'

glVertex3f(.52, 0.56, -0.7);//n'

glVertex3f(-0.1, 0.6, -0.7);//o'

glVertex3f(-1.02, 0.6, -0.7);//p'

glVertex3f(-1.2, 0.22, -0.7);//q'

glVertex3f(-1.2, -.28, -0.7);//r'

glEnd();

glBegin(GL_LINES);

glVertex3f(-1.12, -.48, 0.7);//a

glVertex3f(-1.12, -.48, -0.7);//a'

glVertex3f(-0.86, -.48, 0.7);//b

glVertex3f(-0.86, -.48, -0.7);//b'

Dept. of CSE, RRCE 2020-21 26


3D Car Riding OpenGL Project Computer Graphics Project

glVertex3f(-.74, -0.2, 0.7);//c

glVertex3f(-.74, -0.2, -0.7);//c'

glVertex3f(-.42, -.2, 0.7);//d

glVertex3f(-.42, -.2, -0.7);//d'

glVertex3f(-0.3, -.48, 0.7);//e

glVertex3f(-0.3, -.48, -0.7);//e'

glVertex3f(.81, -0.48, 0.7);//f

glVertex3f(.81, -0.48, -0.7);//f'

glVertex3f(.94, -0.2, 0.7);//g

glVertex3f(.94, -0.2, -0.7);//g'

glVertex3f(1.24, -.2, 0.7);//h

glVertex3f(1.24, -.2, -0.7);//h'

glVertex3f(1.38, -.48, 0.7);//i

glVertex3f(1.38, -.48, -0.7);//i'

glVertex3f(1.52, -.44, 0.7);//j

glVertex3f(1.52, -.44, -0.7);//j'

glVertex3f(1.52, .14, 0.7);//k

glVertex3f(1.52, .14, -0.7);//k'

glVertex3f(1.14, 0.22, 0.7);//l

glVertex3f(1.14, 0.22, -0.7);//l'

glVertex3f(0.76, .22, 0.7);//m

glVertex3f(0.76, .22, -0.7);//m'

glVertex3f(.52, 0.56, 0.7);//n

Dept. of CSE, RRCE 2020-21 27


3D Car Riding OpenGL Project Computer Graphics Project

glVertex3f(.52, 0.56, -0.7);//n'

glVertex3f(-0.1, 0.6, 0.7);//0

glVertex3f(-0.1, 0.6, -0.7);//o'

glVertex3f(-1.02, 0.6, 0.7);//p

glVertex3f(-1.02, 0.6, -0.7);//p'

glVertex3f(-1.2, 0.22, 0.7);//q

glVertex3f(-1.2, 0.22, -0.7);//q'

glVertex3f(-1.2, -.28, 0.7);//r

glVertex3f(-1.2, -.28, -0.7);//r'

glEnd();

glBegin(GL_POLYGON); // top filling

glVertex3f(-0.1, 0.6, 0.7);//o

glVertex3f(-0.1, 0.6, -0.7);//o'

glVertex3f(-1.02, 0.6, -0.7);//p'

glVertex3f(-1.02, 0.6, 0.7);//p

glEnd();

glBegin(GL_POLYGON);

glVertex3f(-0.1, 0.6, 0.7);//o

glVertex3f(-0.1, 0.6, -0.7);//o'

glVertex3f(.52, 0.56, -0.7);//n'

glVertex3f(.52, 0.56, 0.7);//n

glEnd();

Dept. of CSE, RRCE 2020-21 28


3D Car Riding OpenGL Project Computer Graphics Project

GLuint createDL()

GLuint carrDL;

carrDL = glGenLists(1); // Create the id for the list

glNewList(carrDL, GL_COMPILE); // start list

drawcarr(); // call the function that contains the rendering commands

glEndList(); // endList

return(carrDL);

GLuint createDL2() //******************

GLuint houseDL;

houseDL = glGenLists(1); // Create the id for the list

glNewList(houseDL, GL_COMPILE); // start list

drawhouse(); // call the function that contains the rendering commands

glEndList(); // endList

return(houseDL);

} //**************

void initScene()

glEnable(GL_DEPTH_TEST);

carr_display_list = createDL();

house_display_list = createDL2();} //***********

Dept. of CSE, RRCE 2020-21 29


3D Car Riding OpenGL Project Computer Graphics Project

BIBLIOGRAPHY
[1.] Edward Angel, Interactive Computer Graphics A Top-Down Approach with OpenGL, 5 th Edition
Addison-Wesley,2008, ISBN-10: 0321535863

[2.] Yeshwant Kantekar, Let us C++ BPB Publication, ISBN: 8176561061

[3.] F S Hill, Computer Graphics Using OpenGL Jr. 2nd Edition, Pearson Education, 2001, ISBN 0-. 131-
49670-0

Websites

 http://www.opengl.org/
 www.opengl.org/documentation/
 www.google.com
 http://stackoverflow.com
 www.youtube.com

Dept. of CSE, RRCE 2020-21 30

You might also like