Title | Flag Hoisting CG project using Open GL Report |
---|---|
Author | Adnan Shaikh |
Course | Bachelor of engineering |
Institution | Visvesvaraya Technological University |
Pages | 37 |
File Size | 380.8 KB |
File Type | |
Total Downloads | 9 |
Total Views | 34 |
CONTENTS 1 Abstract SL particulars PAGE 2 System Specifications 3 Introduction to OpenGL 5 Implementation 6 Interaction 7 Source Code 8 Output 9 Conclusion 10 Bibliography Abstract The main objective of this project is to show graphically hoisting of a Flag. In this project we have 3 people, a f...
FLAG HOISTING
CONTENTS
SL.NO 1 2 3 5
particulars Abstract System Specifications Introduction to OpenGL Implementation
PAGE.NO 2 3 4 7
6
Interaction
9
7
Source Code
10
8
Output
36
9
Conclusion
38
10
Bibliography
39
1 Dept. of Computer Science & Engineering.
FLAG HOISTING Abstract The main objective of this project is to show graphically hoisting of a Flag. In this project we have 3 people, a flag pole and sun. All these objects are drawn using the basic primitive functions provided in OpenGL. At the beginning flag is down, which is hoisted by a person (first among the three) who walk toward the pole . The person approaches the flagpost and host the flag, which is shown in good animation. Flag go up and waves out. There is “Vande Matharam” written in right side as flag waves.
System specifications 2 Dept. of Computer Science & Engineering.
FLAG HOISTING
SOFTWARE REQUIREMENTS :
MICROSOFT VISUAL C++
OPENGL
HARDWARE REQUIREMENT :
GRAPHICS SYSTEM, Pentium P4 with 256 of Ram(Min)
Introduction to openGL As a software interface for graphics hardware, OpenGL's main purpose is to 3 Dept. of Computer Science & Engineering.
FLAG HOISTING render two- and three-dimensional objects into a frame buffer. These objects are described as sequences of vertices or pixels. OpenGL performs several processing steps on this data to convert it to pixels to form the final desired image in the frame buffer.
OpenGL Fundamentals This section explains some of the concepts inherent in OpenGL. Primitives and Commands OpenGL draws primitives—points, line segments, or polygons—subject to several selectable modes. You can control modes independently of each other; that is, setting one mode doesn't affect whether other modes are set .Primitives are specified, modes are set, and other OpenGL operations are described by issuing commands in the form of function calls. Primitives are defined by a group of one or more vertices. A vertex defines a point, an endpoint of a line, or a corner of a polygon where two edges meet. Data is associated with a vertex, and each vertex and its associated data are processed independently, in order, and in the same way. The type of clipping depends on which primitive the group of vertices represents. Commands are always processed in the order in which they are received, although there may be an indeterminate delay before a command takes effect. This means that each primitive is drawn completely before any subsequent command takes effect. It also means that state-querying commands return data that's consistent with complete execution of all previously issued OpenGL commands.
Basic OpenGL Operation The figure shown below gives an abstract, high-level block diagram of how OpenGL processes data. In the diagram, commands enter from the left and proceed through what can be thought of as a processing pipeline. Some commands specify geometric objects to be drawn, and others control how the 4 Dept. of Computer Science & Engineering.
FLAG HOISTING objects are handled during the various processing stages. Figure . OpenGL Block Diagram
As shown by the first block in the diagram, rather than having all commands proceed immediately through the pipeline, you can choose to accumulate some of them in a display list for processing at a later time. Rasterization produces a series of frame buffer addresses and associated values using a two-dimensional description of a point, line segment, or polygon. Each fragment so produced is fed into the last stage, per-fragment operations, which performs the final operations on the data before it's stored as pixels in the frame buffer. These operations include conditional updates to the frame buffer based on incoming and previously stored z-value s (for z-buffering) and blending of incoming pixel colors with stored colors, as well as masking and other logical operations on pixel values. All elements of OpenGL state, including the contents of the texture memory and even of the frame buffer, can be obtained by an OpenGL application.
5 Dept. of Computer Science & Engineering.
FLAG HOISTING
Implementation This program is implemented using various openGL functions which are shown below.
Various functions used in this program.
6 Dept. of Computer Science & Engineering.
FLAG HOISTING glutInit() : interaction between the windowing system and OPENGL is initiated glutInitDisplayMode() : used when double buffering is required and depth information is required glutCreateWindow() : this opens the OPENGL window and displays the title at top of the window glutInitWindowSize() : specifies the size of the window glutInitWindowPosition() : specifies the position of the window in screen co-ordinates glutKeyboardFunc() : handles normal ascii symbols glutSpecialFunc() : handles special keyboard keys glutReshapeFunc() : sets up the callback function for reshaping the window glutIdleFunc() : this handles the processing of the background glutDisplayFunc() : this handles redrawing of the window glutMainLoop() : this starts the main loop, it never returns glViewport() : used to set up the viewport 7 Dept. of Computer Science & Engineering.
FLAG HOISTING glVertex3fv() : used to set up the points or vertices in three dimensions glColor3fv() : used to render color to faces glFlush() : used to flush the pipeline glutPostRedisplay() : used to trigger an automatic redrawal of the object glMatrixMode() : used to set up the required mode of the matrix glLoadIdentity() : used to load or initialize to the identity matrix glTranslatef() : used to translate or move the rotation centre from one point to another in three dimensions glRotatef() : used to rotate an object through a specified rotation angle
Interaction with program
This program includes interaction through keyboard. In the beginning as program starts there is no motion, so there is S/s Initiate the program animation. ESC-> Quit
8 Dept. of Computer Science & Engineering.
FLAG HOISTING
Source Code #ifdef __APPLE__ #include #else #include #endif 9 Dept. of Computer Science & Engineering.
FLAG HOISTING #include #include #include
int i, j = 0; char st1[] = "Vande Mataram"; float w = 0.0, h = 0.0, x, y, z; void filcircle(float x, float y, float r) { float angle = 0; glBegin(GL_TRIANGLE_FAN); while (angle < 360) { glVertex2f(x + sin(angle) * r, y + cos(angle) * r); angle += 1.0; } glEnd();
}
10 Dept. of Computer Science & Engineering.
FLAG HOISTING
void curves2(float x1, float y1, float x2, float y2, float a1, float a2, float b1, float b2) { GLfloat cp[4][3] = { {x1,y1},{a1,a2},{b1,b2},{x2,y2} }; glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, *cp); glEnable(GL_MAP1_VERTEX_3); GLint k; float c = 0.3;
glLineWidth(2); glBegin(GL_LINE_STRIP); for (k = 0; k x) { plotpixels(h, k, x, y); if (d < 0) d += 2 * x + 3; else { d += 2 * (x - y) + 5; 14 Dept. of Computer Science & Engineering.
FLAG HOISTING --y; } ++x; } plotpixels(h, k, x, y); }
void init() { glClearColor(0.15, .3, .65, 1); glMatrixMode(GL_PROJECTION); glLoadIdentity();
}
void sun() {
15 Dept. of Computer Science & Engineering.
FLAG HOISTING //drawing a sun glColor3f(1, 1, 0); glLineWidth(2); glBegin(GL_LINES); glVertex2f(60, 63); glVertex2f(100, 63); glVertex2f(80, 50); glVertex2f(80, 80); glVertex2f(70, 77); glVertex2f(90, 50); glVertex2f(70, 50); glVertex2f(90, 77); glVertex2f(65, 70); glVertex2f(95, 55); glVertex2f(65, 55); glVertex2f(95, 70); glEnd(); float angle = 0; glColor3f(1, .7, 0); glBegin(GL_TRIANGLE_FAN); while (angle < 360) 16 Dept. of Computer Science & Engineering.
FLAG HOISTING { glVertex2f(80 + sin(angle) * 10, 65 + cos(angle) * 10); angle += 1.0; } glEnd();
}
void draw_flag() {
//steps glColor3f(1.5, 1.5, 1.5); drawrect(-100, -60, -75, -70); 17 Dept. of Computer Science & Engineering.
FLAG HOISTING drawrect(-95, -65, -70, -65);
//pole glColor3f(0.0, 0.0, 0.0); glLineWidth(8.0); drawline(-80, -65, -80, 55); //rope glColor3f(1.0, 1.0, 1.0); glLineWidth(0.2); curves2(-80, -40, -80, 55, -83, -30, -83, 40); //folded flag glColor3f(1.0, 1.0, 0.0); drawrect(-80, -75, -42, -38); //tierope glColor3f(1.0, 1.0, 1.0); glLineWidth(0.2); drawline(-80, -40, -75, -40);
//hook glColor3f(0.0, 0.0, 0.0); draw_pixels(-80, 55); 18 Dept. of Computer Science & Engineering.
FLAG HOISTING }
void draw_people() { int j = 0; float k = 0; for (int i = 0; i < 3; i++) {
//person head glColor3f(0.75, 0.75, 1); filcircle(40 + j, -30, 6);
//neck drawrect(38 + j, 42 + j, -40, -35); //eye glColor3f(0, 0, 0); draw_pixels(38 + j, -28); draw_pixels(42 + j, -28); 19 Dept. of Computer Science & Engineering.
FLAG HOISTING glLineWidth(2.0); drawline(38 + j, -32.5, 42 + j, -32.5); //body glColor3f(1 + k, 0.1 + k, 0.2 + k); drawrect(33 + j, 47 + j, -60, -40); //hands glColor3f(0 + k, 0.75 + k, 1 + k); drawrect(30 + j, 33 + j, -50, -40); drawrect(47 + j, 50 + j, -50, -40); glColor3f(0.75, 0.75, 1); drawrect(30 + j, 33 + j, -65, -50); drawrect(47 + j, 50 + j, -65, -50); //legs glColor3f(0 + k, .75 + k, 1 + k); drawrect(35 + j, 40 + j, -75, -60); drawrect(40 + j, 45 + j, -75, -60); glColor3f(0, 0, 0); drawline(40 + j, -75, 40 + j, -60); j = j + 25; k += .3; } 20 Dept. of Computer Science & Engineering.
FLAG HOISTING
}
void printc(int x, int y, char st[]) { char* p = st; float i = 0; while (*p != '\0') { glRasterPos2i(x + i, y); glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *p); i += 5; p++; } glFlush(); }
void reshape(int w, int h) 21 Dept. of Computer Science & Engineering.
FLAG HOISTING { glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w...