Content Project Report
Content Project Report
INTRODUCTION
1.1 Computer Graphics
● Graphics provides one of the most natural means of communicating with a computer,
since our highly developed 2D or 3D pattern-recognition abilities allow us to perceive
and process pictorial data rapidly.
● Computers have become a powerful medium for the rapid and economical production of
pictures.
● Graphics provide a so natural means of communicating with the computer that they have
become widespread.
● Interactive graphics is the most important means of producing pictures since the
invention of photography and television.
● We can make pictures of not only the real world objects but also of abstract objects such
as mathematical surfaces on 4D and of data that have no inherent geometry.
● A computer graphics system is a computer system with all the components of the general
purpose computer system. There are five major elements in system: input devices,
processor, memory, frame buffer, output devices.
OpenGL is the premier environment for developing portable, interactive 2D and 3D graphics
applications. Since its introduction in 1992, OpenGL has become the industry's most widely used
and supported 2D and 3D graphics application programming interface (API), bringing thousands
of applications to a wide variety of computer platforms.
OpenGL fosters innovation and speeds application development by incorporating a broad set of
rendering, texture mapping, special effects, and other powerful visualization functions.
Developers can leverage the power of OpenGL across all popular desktop and workstation
platforms, ensuring wide application deployment.
OpenGL Available Everywhere: Supported on all UNIX® workstations, and shipped standard
with every Windows 95/98/2000/NT and MacOS PC, no other graphics API operates on a wider
range of hardware platforms and software environments.
OpenGL runs on every major operating system including Mac OS, OS/2, UNIX, Windows
95/98, Windows 2000, Windows NT, Linux, Open Step, and BeOS; it also works with every
major windowing system, including Win32, MacOS, Presentation Manager, and X-Window
System. OpenGL is callable from Ada, C, C++, FORTRAN, Python, Perl and Java and offers
complete independence from network protocols and topologies.
2. glClearColor -Specifies the red, green, blue, and alpha values used by glClear to clear
the color buffers.
3. glLoadIdentity
4. glMatrixMode
5. glutCreateWindow
6. glutDisplayFunc
7. glutInit
Initializes the GLUT library and negotiates a session with the window system.
8. glutInitDisplayMode
The initial display mode is used when creating top-level windows, sub windows
and overlays to determine the OpenGL display mode for the to-be-created window or overlay.
Page 3 of 22
9. glutInitWindowPosition
10. glutInitWindowSize
11. glvertex()
12. glutBitmapCharacter
13. glutSwapBuffers
14. glFlush()
15. glEnd()
Page 4 of 22
Chapter-2
REQUIREMENTS SPECIFICATION
Page 5 of 22
Chapter-3
glutKeyboardFunc Function
SYNTAX:
PARAMETERS:
glutMouseFunc Function
SYNTAX:
Page 6 of 22
START
3.2 Architecture:
Character
control
KEYBOARD MOUSE
MOVEMENT
360 lookout
W forward
A left
S backward
D right
Q Increase
angle
Decrease
Z
angle
Page 7 of 22
Chapter-4
IMPLEMENTATION
int diffx=x-lastx; //check the difference between the current x and the last x position
int diffy=y-lasty; //check the difference between the current y and the last y position
lastx=x; //set lastx to the current x position
lasty=y; //set lasty to the current y position
xrot += (float) diffy;
if (xrot >140) xrot -= 140;
if (xrot < -90) xrot += 90; //set the xrot to xrot with the addition of the difference in
the y position
yrot += (float) diffx; //set the xrot to yrot with the addition of the difference in the
x position
}
if (key=='q')
{
xrot += 1;
if (xrot >90) xrot -= 90;
}
if (key=='z')
{
xrot -= 1;
if (xrot < -90) xrot += 90;
}
if (key=='w')
Page 8 of 22
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos += float(sin(yrotrad));
zpos -= float(cos(yrotrad));
ypos -= float(sin(xrotrad));
}
if (key=='s')
{
float xrotrad, yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xrotrad = (xrot / 180 * 3.141592654f);
xpos -= float(sin(yrotrad));
zpos += float(cos(yrotrad));
ypos += float(sin(xrotrad));
}
if (key=='d')
{
float yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xpos += float(cos(yrotrad));
zpos += float(sin(yrotrad));
}
if (key=='a')
{
float yrotrad;
yrotrad = (yrot / 180 * 3.141592654f);
xpos -= float(cos(yrotrad));
zpos -= float(sin(yrotrad));
}
if (key=='1')
{
glTranslatef(xpos,-100,zpos);
glutPostRedisplay();
}
Page 9 of 22
if (key=='2')
{
glTranslated(xpos,-200,zpos);
glFlush();
}
if (key=='3')
{
glTranslated(xpos,-400,zpos);
if (key==27)
{
exit(0);
}
➢ TO DRAW HOUSE:
void house1()
{
//front
glPushMatrix();
glColor3f(0.255,0.250,0.255);
glRotated(0,0,0,0);
glTranslated(0,0,0);
glScaled(80,70,0.5);
glutSolidCube(1);
glPopMatrix();
//back
glPushMatrix();
glColor3f(0.255,0.250,0.255);
glRotated(0,0,0,0);
glTranslated(0,0,60);
Page 10 of 22
glScaled(80,70,0.5);
glutSolidCube(1);
glPopMatrix();
}
void camera_man()
{
//camera and man
glTranslatef(0.0f,-5.0f, (-cRadius/2));//camera position
glRotatef(xrot,1.0,0.0,0.0);//camera rotation angle
glPushMatrix();
glTranslatef(0.0f,-2.0f,-cRadius);
glColor3f(1,1,0);
glScalef(0.9,1.8,1);
glutSolidSphere(1,slices,stacks);//chest
glPopMatrix();
glPushMatrix();
glTranslatef(0.0f,0.7f,-cRadius);
glColor3f(0.870588,0.721569,0.529412);
glScalef(0.8,1.3,0.8);
glutSolidSphere(1,slices,stacks);//head
glPopMatrix();
glPushMatrix();
glTranslatef(-1.2f,-1.3f,-cRadius);
glRotatef(-30,0,0,1);
glColor3f(1,1,0);
glScalef(0.3,1,0.3);
glutSolidSphere(1,slices,stacks);//left upper arm
glPopMatrix();
glPushMatrix();
glTranslatef(-1.5f,-2.9f,-cRadius-0.2);
glRotatef(20,1,0,0);
Page 11 of 22
glColor3f(0.870588,0.721569,0.529412);
glScalef(0.3,1,0.3);
glPushMatrix();
glTranslatef(1.2f,-1.3f,-cRadius);
glRotatef(30,0,0,1);
glColor3f(1,1,0);
glScalef(0.3,1,0.3);
glutSolidSphere(1,slices,stacks);//right upper arm
glPopMatrix();
glPushMatrix();
glTranslatef(1.5f,-2.9f,-cRadius-0.2);
glRotatef(20,1,0,0);
glColor3f(0.870588,0.721569,0.529412);
glScalef(0.3,1,0.3);
glutSolidSphere(1,slices,stacks);//right lower arm
glPopMatrix();
glPushMatrix();
glTranslatef(0.6f,-4.7f,-cRadius);
glRotatef(5,0,0,1);
glColor3f(0,0,1);
glScalef(0.4,1.3,0.3);
glutSolidSphere(1,slices,stacks);//right upper leg
glPopMatrix();
glPushMatrix();
glTranslatef(0.7f,-6.7f,-cRadius);
glRotatef(3,0,0,1);
glColor3f(0,0,1);
glScalef(0.3,1.2,0.27);
glutSolidSphere(1,slices,stacks);//right lower leg
glPopMatrix();
glPushMatrix();
glTranslatef(-0.6f,-4.7f,-cRadius);
glRotatef(-5,0,0,1);
glColor3f(0,0,1);
glScalef(0.4,1.3,0.3);
Page 12 of 22
glutSolidSphere(1,slices,stacks);//left upper leg
glPopMatrix();
glPushMatrix();
glTranslatef(-0.7f,-6.7f,-cRadius);
glRotatef(-3,0,0,1);
glColor3f(0,0,1);
glScalef(0.3,1.2,0.27);
glutSolidSphere(1,slices,stacks);//left lower leg
glPopMatrix();
➢ STARS:
Void stars()
{
glPushMatrix();
glColor3f(0.9,0.91,0.98);
glTranslatef(0,400,330);
glutSolidSphere(4,slices,stacks);
glPopMatrix();
}
➢ MOON:
Void moon()
{
glPushMatrix();
glColor3f(0.9,0.9,0.9);
glTranslatef(500,700,-500);
glutSolidSphere(50,slices,stacks);
Page 13 of 22
glPopMatrix(); }
Chapter-5
SNAPSHOTS
Page 14 of 22
Page 15 of 22
Page 16 of 22
Chapter-6
FUTURE ENHANCEMENT
Page 17 of 22
Chapter-7
CONCLUSION
The Project has been developed as per requirements specified by the Vishweshwaraiah
Technological University as a partial fulfillment of the Computer Graphics Lab for 6 th Semester,
Computer Science and Engineering. All the requirements given have been implemented in the
project.
Page 18 of 22
Chapter-8
REFERENCES
Books:
1.Edward Angel-”Interactive computer Graphics A Top-Down Approach with OpenGL”,5th
edition,Addison-Wesley,2008.
2.“Computer Graphics”:Donald Hearn,M.Pauline Baker”.
Websites:
1.en.wikipedia.org/wiki/OpenGL
2.www.opengl.org/resources/code/samples/redbook
Page 19 of 22
Chapter-9
APPENDIX
Opengl programs can be implemented using codeblocks software. For this purpose any edition of
codeblocks should be installed. The software can be acquired on the net or can be purchased
elsewhere.
First a simple setup must be run for installation. In accordance for the opengl programs to run
correctly some files need to be included in some of the folders of codeblocks after installation.
The procedure to install the glut libraries and dll's (to download it go to
http://reality.sgi.com/opengl/glut3/glut3.html ) is as follows:
1. After downloading the glut.zip file (you should get the latest ver. 3.7) unzip it into a folder
glut.dll
glut32.dll
glut.h
glut.lib
glut32.lib
3. Both glut.dll and glut32.dll must be copied into windows directory (windows or winnt,
depends on if you are using Windows95/98 or Windows NT)
*** The drive must be put where codeblocks was installed instead of the <drive> ***
Page 20 of 22
*** The directory must be put where codeblocks was installed instead of the < codeblocks path>
*** The drive must be put where codeblocks was installed instead of the <drive> ***
*** The directory must be put where d codeblocks was installed instead of the < codeblocks
path>
The procedure that follows shows how to start up an opengl project and setup the setting so as to
compile and run programs. This is assuming that the appropriate files are already downloaded
and installed in the directories as specified in their documentation.
3. Type in the name of the project and where it will be on the hard drive.
5. First thing to be done when the project opens up is to click on the "Project" menu item from
the top.
Page 21 of 22
9.2 Personal Details
NAME: MANOJ V
USN: 1DT14CS045
SEMESTER : 6th Sem
DEPARTMENT: COMPUTER SCIENCE AND ENGINEERING
COLLEGE:DAYANANDA SAGAR ACADEMY OF TECHNOLOGY AND
MANAGEMENT
EMAIL ID: [email protected]
Page 22 of 22