1.1 Introduction To Computer Graphics
1.1 Introduction To Computer Graphics
2018
Chapter 1
INTRODUCTION
1.1 Introduction to Computer Graphics
Computer graphics started with the display of data on hardcopy plotters and Cathode Ray Tube (CRT)
screens soon after the Introduction of computers themselves. It has grown to include the Creation,
Storage and Manipulation of Models and Images of objects. These models come from a diverse and
expanding set of fields, and include physical, mathematical, engineering, architectural and even
conceptual structures, natural phenomenon and so on. Computer graphics today is largely interactive:
the user controls the contents, structure, and appearance of objects and of their displayed images by
using input devices, such as a keyboard, mouse, or touch-sensitive panel on the screen. Because of the
close relationship between the input devices and the display, the handling of such devices is included in
the study of computer graphics.
User Interfaces
Word-processing, spreadsheet and desktop-publishing programs are typical applications of such user-
interface techniques.
The common use of graphics is to create 2D and 3D graphs of mathematical, physical and economic
functions, histograms, and bar and pie charts.
In CAD, interactive graphics is used to design components and systems of mechanical, electrical and
electronic devices including structures such as buildings, automobile bodies, aero planes, ship hulls etc.
Computer-produced animated movies are becoming increasing popular for scientific and engineering
visualization. Cartoon characters will increasingly be modeled in the computer as 3D shape descriptions
whose movements are controlled by computer commands.
2D Graphics
These editors are used to draw 2D pictures (line, rectangle, circle and ellipse) alter those with operations
like cut, copy and paste. These may also support features like translation, rotation etc.
3D Graphics
These editors are used to draw 3D pictures (line, rectangle, circle and ellipse).These may also support
features like translation, rotation etc.
#include<GL/glut.h>
OR
#include<GLUT/glut.h>
GLUT is the OpenGL Utility Toolkit, a window system independent toolkit for writing OpenGL
programs. It implements a simple windowing application programming interface (API) for OpenGL.
GLUT makes it considerably easier to learn about and explore OpenGL programming. GLUT provides a
portable API so you can write a single OpenGL program that works across all PC and workstation OS
platforms. GLUT is designed for constructing small to medium sized OpenGL programs. While GLUT
is well-suited to learning OpenGL and developing simple OpenGL applications, GLUT is not a full-
featured toolkit so large applications requiring sophisticated user interfaces are better off using native
window system toolkits. GLUT is simple, easy, and small.The GLUT library has C, C++ (same as C),
FORTRAN, and ADA programming bindings. The GLUT source code distribution is portable to nearly
all OpenGL implementations and platforms. The current version is 3.7. Additional releases of the library
are not anticipated. GLUT is not open source.
Chapter 2
SYSTEM REQUIREMENTS
System requirements are intended to communicate in precise way, the functions that the system must
provide. To reduce ambiguity, they may be written in a structured form of natural language
supplemented by tables and system models.
Memory – 8 GB
Tools : CodeBocks
OpenGL
Chapter 3
IMPLEMENTATION
file_gen is used to check whether high score file already exists. If it does not, it will create. If it does,
it will read data from existing file.
render_header to display the player's name along with a running timer. The timer gets its values
from the clock class, which maintains the time elapsed since the game started in hour, minutes and
seconds.
hiscore_check to determine the position of the player in the highscores list. If he completes the game
in a time lesser than the top 10 players, it implements an insertion sort to insert the player's name and
time into the existing high score list.
write_file is used to write a text file of the current player class. The player class contains details of
the player name and the time he took to complete the game. All these details, along with the pre-existing
records of the highscores are arranged in ascending order of time and are written into a text file.
sub is the display function for the sub window created to display the highscores. This window is
activated when the user chooses the option "highscores" from the menu obtained on right click of the
mouse.
Mouse events:
When mouse event occurs, the ASCII code for the corresponding coordinates that generate the event and
the location of mouse are returned. Mouse callback function is
glutMouseFunc (mouse);
Void mouse (int btn, int state, int x, int y) {
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
begin = x;
}
Menu Entry:
GLUT provides one additional feature, pop_up menus, which we can use with the mouse to create
sophisticated interactive application
glutCreateMenu ();
glutAddMenuEntry ();
glutAttachMenu (GLUT_RIGHT_BUTTON);
Application program
Description
Mouse event
Motion event
3.1 DESIGN:
The flow chart describes how the path travels.
Application
Program
Figure 3.1 under Implementation Chapter explains the Data Flow Diagram.
This includes the flow from application program to handling different events like Mouse event, Motion
event and the Menu list.
frontpage(): this function displays the project name, students name,guide name and also
an input is asked from the user to start the project.
encryption(): the function creates the components required in the process i.e; client side
computer (computer()), destination computer(computer_dest()),the message data
block(message()),cipher block (cipher()),key block(key()).
animation_encryption(): this function is concerned with the speed of the movement of the
key,message and cipher block from client to server computer.
CODE:
#include<windows.h>
#include<stdlib.h>
#include<GL/glut.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#define SCENE 10
enum { FRONTPAGE,ENCRYPTION,EXIT };
void *fonts[] =
GLUT_BITMAP_9_BY_15,
GLUT_BITMAP_TIMES_ROMAN_10,
GLUT_BITMAP_HELVETICA_12,
GLUT_BITMAP_HELVETICA_10,
GLUT_BITMAP_HELVETICA_18,
};
{ int len, i;
glRasterPos2f(x, y);
glutBitmapCharacter(fonts[j], string[i]);
void delay(void)
{ int i,j,k;
for(i=0;i<5000;i++)
for(j=0;j<10000;j++);
for(k=0;k<15000;k++);
void delay1(void)
int i;
for(i=0;i<10000;i++);
void front_page()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
output(320,500,"A",2);
output(130,200,"Guides:Veena",2);
//output(175,180,"Name 1:",2);
//output(175,150,"Name 2:",2);
output(450,200,"By:",3);
output(475,180,"Name 1 : NAUSEEN",2);
output(475,150,"Name 2 : RIDA",2);
output(275,50,"Press S to start",2);
glFlush();
glCallList(SCENE);
glPopMatrix();
glutSwapBuffers();
/* Movement angles */
GLint
movement_angle=0,packet_angle=0,head_angle=0,packet_angle1=0,head_angle1=0,packet_angle2=0,
head_angle2=0,packet_angle3=0,head_angle3=0,packet_angle4=0;
GLdouble mov_speed = 1;
GLint
head_angle4=0,packet_angle5=0,head_angle5=0,packet_angle6=0,head_angle6=0,packet_angle7,hea
d_angle7=0,packet_angle8=40;
/* Movement angles */
GLint
movement_angle1=0,arrow_angle=0,rev_arrow_angle=0,phy_header_angle=0,rev_phy_header_angle
=0,rev_phy_header_angle1=0,phy_header_angle1=0,analog_sig_angle=0,rev_analog_sig_angle = 0;
void animation_encryp(void)
movement_angle = 600;
arrow_angle = 150;
if(arrow_angle==150)
phy_header_angle = 100;
if(phy_header_angle==100)
phy_header_angle1 = 100;
if(phy_header_angle1==100)
analog_sig_angle = 100;
if(analog_sig_angle==100)
movement_angle1 = 420;
if(movement_angle1 ==420)
rev_analog_sig_angle = 100;
if(rev_analog_sig_angle ==100)
rev_phy_header_angle = 200;
if(rev_phy_header_angle ==200)
rev_phy_header_angle1 = 100;
if(rev_phy_header_angle ==200)
rev_arrow_angle = 100;
glutPostRedisplay();
void computer()
glColor3f(0.75,0.85,0.65);//keyboard
glBegin(GL_QUADS);
glVertex2f(55.0,340.0);
glVertex2f(145.0,340.0);
glVertex2f(150.0,350.0);
glVertex2f(60.0,350.0);
glEnd();
glColor3f(0.75,0.85,0.65);//cabinet
glBegin(GL_LINE_LOOP);
glVertex2f(60.0,355.0);
glVertex2f(150.0,355.0);
glVertex2f(150.0,370.0);
glVertex2f(60.0,370.0);
glEnd();
glColor3f(0.75,0.85,0.65);
glBegin(GL_LINE_LOOP);
glVertex2f(75.0,380.0);
glVertex2f(135,380.0);
glVertex2f(135.0,430.0);
glVertex2f(75.0,430.0);
glEnd();
glColor3f(0.7,0.8,0.6);
glBegin(GL_QUADS);
glVertex2f(80.0,385.0);
glVertex2f(130.0,385.0);
glVertex2f(130.0,425.0);
glVertex2f(80.0,425.0);
glEnd();
glColor3f(0.75,0.85,0.65);
glBegin(GL_LINES);
glVertex2f(90.0,370.0);
glVertex2f(90.0,380.0);
glVertex2f(120.0,370.0);
glVertex2f(120.0,380.0);
glEnd();
void computer_dest()
glColor3f(0.75,0.85,0.65);//keyboard
glBegin(GL_QUADS);
glVertex2f(545.0,525.0);
glVertex2f(635.0,525.0);
glVertex2f(640.0,535.0);
glVertex2f(550.0,535.0);
glEnd();
glColor3f(0.75,0.85,0.65);//cabinet
glBegin(GL_LINE_LOOP);
glVertex2f(550.0,540.0);
glVertex2f(640.0,540.0);
glVertex2f(640.0,555.0);
glVertex2f(550.0,555.0);
glEnd();
glColor3f(0.75,0.85,0.65);//cpu
glBegin(GL_LINE_LOOP);
glVertex2f(565.0,565.0);
glVertex2f(625,565.0);
glVertex2f(625.0,615.0);
glVertex2f(565.0,615.0);
glEnd();
glColor3f(0.7,0.8,0.6);//monitor
glBegin(GL_QUADS);
glVertex2f(570.0,570.0);
glVertex2f(620.0,570.0);
glVertex2f(620.0,610.0);
glVertex2f(570.0,610.0);
glEnd();
glColor3f(0.75,0.85,0.65);
glBegin(GL_LINES);
glVertex2f(580.0,555.0);
glVertex2f(580.0,565.0);
glVertex2f(610.0,555.0);
glVertex2f(610.0,565.0);
glEnd();
void cipher()
glColor3f(0.0f,0.0f,1.0f);
glPushMatrix();
glScalef(40,20,.5);
glTranslatef(3,14,0);
glutWireCube(2);
output(-1,0," CIPHER",2);
glPopMatrix();
void message_data()
glColor3f(1.0f,1.0f,0.0f);
glPushMatrix();
glScalef(40,20,.5);
glTranslatef(3,14,0);
glutWireCube(2);
output(-1,0," MESSAGE",2);
glPopMatrix();
void message_key(void)
glColor3f(0.0f,1.0f,0.0f);
glPushMatrix();
glScalef(20,20,.5);
glTranslatef(3,14,0);
glutWireCube(2);
output(-1,0,"KEY",2);
glPopMatrix();
void encryption()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
//glPushMatrix();
// glColor3f(0.25,0.15,0.36);
glColor3f(1.0f,1.0f,1.0f);
//glPopMatrix();
glColor3f(1.0f,1.0f,1.0f);
glPushMatrix();
glTranslatef(-30,200,0);
output(75,440,"Sender",2);
computer();
glPopMatrix();
glColor3f(1.0f,1.0f,1.0f);
glPushMatrix();
output(565,630,"Receiver",2);
computer_dest();
glPopMatrix();
glColor3f(1.0f,1.0f,1.0f);
glPushMatrix();
glScalef(70,40,.5);
glTranslatef(1.5,7,0);
glutWireCube(2);
glPopMatrix();
if(phy_header_angle1!=100)
glPushMatrix();
glTranslatef(0,-phy_header_angle1,0);
glPushMatrix();
glTranslatef(0,-arrow_angle,0);
glTranslatef(0,150,0);
message_data();
glPopMatrix();
glPushMatrix();
glTranslatef(phy_header_angle,0,0);
glTranslatef(-100,0,0);
message_key();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(movement_angle1,0,0);
if(phy_header_angle1==100)
glPushMatrix();
if(movement_angle1>=420)
// glRotatef(180,0,1,0);
glTranslatef(0,rev_analog_sig_angle,0);
glTranslatef(0,-analog_sig_angle,0);
if(rev_analog_sig_angle!=100)
cipher();
glPopMatrix();
glPopMatrix();
glPushMatrix();
glTranslatef(movement_angle1,0,0);
if(phy_header_angle1==100)
glPushMatrix();
glScalef(50,30,.5);
glTranslatef(2.5,2.5,0);
glutWireCube(2);
glPopMatrix();
glPopMatrix();
if(rev_analog_sig_angle==100)
glPushMatrix();
glTranslatef(450,rev_phy_header_angle1,0);
glPushMatrix();
//glTranslatef(0,rev_arrow_angle,0);
//glTranslatef(0,0,0);
message_data();
glPopMatrix();
glPushMatrix();
glTranslatef(rev_phy_header_angle,0,0);
glTranslatef(-10,0,0);
if(rev_phy_header_angle<200)
message_key();
glPopMatrix();
glPopMatrix();
glColor3f(1.0f,1.0f,1.0f);
glPushMatrix();
glTranslatef(450,0,0);
glScalef(70,40,.5);
glTranslatef(1.5,7,0);
glutWireCube(2);//right layer
glPopMatrix();
animation_encryp();
glFlush();
glutSwapBuffers();
void myinit()
glColor3f(1.0,0.0,0.0);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,700.0,0.0,700.0);
void display()
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
front_page();
glFlush();
glutSwapBuffers();
switch(key)
case 'S' :
break;
case 'q':
case 'Q':
exit(0);
glutPostRedisplay();
switch (mode)
case FRONTPAGE:glutDisplayFunc(front_page);
break;
case ENCRYPTION:glutDisplayFunc(encryption);
break;
glutPostRedisplay();
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(1000,700);
glutInitWindowPosition(0,0);
glutCreateWindow("ENCRYPTION");
glutKeyboardFunc(key);
myinit();
glutDisplayFunc(display);
glutCreateMenu(menu);
glutAddMenuEntry("Encryption",ENCRYPTION);
glutAddMenuEntry("Exit", EXIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop();
4. CODE
5. SNAPSHOTS
We successfully implemented the Puzzle Slider game with tiles and frame.
The extra features include Player’s name and a clock that starts at the beginning of the game. Also, a
high score list – Hall Of Fame has been included.
To make the high score list permanent, a text file is running at the back end.
Adding cheat codes like most commercial games, so that the player can enter them and the fully
solved puzzle is displayed. This can also be used to view the effects when a player makes it to the Hall
of Fame.
Give the option of allowing the user to put any image of his choice onto the tiles. This again involves
Texture mapping and image processing.
REFERENCES