Visveswaraiah Technological University: Belgaum, Karnataka - 590 014

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 16

VISVESWARAIAH TECHNOLOGICAL UNIVERSITY

BELGAUM, KARNATAKA -590 014

K.L.E. Societys

K. L. E INSTITUTE OF TECHNOLOGY HUBLI 580 030 (KARNATAKA)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


K. L. E Educational Association (Regd.)

B.E VI SEMESTER MINI PROJECT NATIONAL FLAG


Submitted by:

Under the guidance of Mr. Kiran .B. Malagi


B.E M.Tech

K.L.E. Societys

K. L. E INSTITUTE OF TECHNOLOGY
(Affiliated to VISVESVARAYA TECHNOLOGICAL UNIVERSITY)

HUBLI 580 030 (KARNATAKA)

CERTIFICATE

This is to certify that Miss and has satisfactorily completed the mini project work entitled NATIONAL FLAG and has submitted the report for the academic year 2010-2011.
.................... Staff in-charge
Principal Examination Centre: KLEIT, HUBLI.

..
HOD

..

Signature of the Examiners:

1 2 Date: Place:

|Page

ABSTRACT

NATIONAL FLAG WITH ROTATING ASHOKA CHAKRA(the wheel of law & progress):
TITLE:
The aim of the project is to create our national flag and set the ASHOKA CHAKRA into motion The tricolour flag is made up of saffron, white and green colours, each colour specifying a particular message thus making it special and respectable.. At the centre is the Ashoka Chakra (the wheel of law & progress) in navy blue colour The project aims at setting Ashoka Chakra wheel in motion, along with an interactive interface for changing background colours on just a click of mouse, thus making it eye catching

The project is implemented on Dev-C++ platform with the help of OpenGL and glut in-built functions.

|Page

INTRODUCTION OF OPEN-GL
HISTORY:OpenGL was developed by Silicon Graphics Inc (SGI) on 1992 and is popular in the gaming industry where it competes with the Direct3D in the Microsoft Windows platform. OpenGL is broadly used in CAD(Computer Aided Design),virtual reality, scientific visualization, information visualization, flight simulation and video games development. OpenGL is a standard specification that defines an API that is multi-language and multi-platform and that enables the codification of applications that output computerized graphics in 2D and 3D. The interface consists in more than 250 different functions, which can be used to draw complex tridimensional scenes with simple primitives. It consist of many functions that help to create an real world object and an particular existence for an object can be given.

CHARECTERISTICS:

OpenGL is a better documented API. OpenGL is also a cleaner API and much easier to learn and program. OpenGL has the best demonstrated 3D performance for any API. Microsoft's Direct3D group is already planning a major API change called Direct Primitive that will leave any existing investment in learning Direct3D immediate mode largely obsolete.

Definition The project NATIONAL FLAG WITH ROTATING ASHOKA CHAKRAis created to demonstrate OpenGLs concepts. It encompasses some of the skills learnt in our OpenGL classes such as pushmatrix(), rotate() ,popmatrix(), VisibilityFunc() function Acronyms & Abbreviations OpenGL provides a powerful but primitive set of rendering command, and all higher level design must be done in terms of these commands. OpenGL Utility Toolkit(GLUT):- windows-system-independent toolkit.

|Page

FUNCTIONAL OVERVIEW

The aim of our project is to study the effect of an

Using transformation functions.

o Using mouse function. o Using delay code


o

Using glut to manage windows and callbacks.

myinit(): This function initializes light source for ambient, diffuse and specular types. display(): This function creates and translates all the objects in a specified location in a particular order and also rotates the objects in different axes. glClear(GL_COLOR_BUFFER_BIT); glFlush(); MainLoop(): This functions execution will cause the program to begin an event processing loop.

PushMatrix():

Save the present values of attributes and matrices placing ,or pushing on the top of the stack.

PopMatrix(): We can recover them by removing them from stack;

glRotatef (); In rotate func the variables are the angle of the rotation and the 3

axes.

|Page

main(): The execution of the program starts from this function. It initializes the graphics system and includes many callback functions.

PostRedisplay():

It ensures that the display will be drawn only once each time the program goes through the event loop.

|Page

SNAP SHOTS

|Page

|Page

IMPLEMENTATION..

#ifndef WHEEL #define WHEEL void wheelInit(); void wheelDraw(); #endif

#include <stdlib.h> #include <math.h> #include <GL/glut.h> #define RIM_N 48 #define SPOKE_N 24 static double *spoke_pts = NULL; static double *rim_pts; static double* createCircumferencePoints(int n) { double *ret; int i; double theta; glPointSize(20); ret = (double*) malloc(2 * n * sizeof(double)); for(i = 0; i < n; i++) { theta = 2 * M_PI * i / n; ret[2 * i] } return ret; }
|Page 9

= cos(theta);

ret[2 * i + 1] = sin(theta);

// Initializes data necessary for drawing a wheel. void wheelInit() { glPointSize(20); if(spoke_pts == NULL) { spoke_pts = createCircumferencePoints(SPOKE_N); rim_pts = createCircumferencePoints(RIM_N); } }

// Draws wheel of radius 1, centered at origin. void flagDraw() { double x0=-5.5,y0=-3.4,y1=-1.2,y2=1.2,y3=3.4,x2=5.5; glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.5,0.5,0.5); glBegin(GL_POLYGON ); glVertex2d(-5.8,-5); glVertex2d(-5.8,y3); glVertex2d(x0,y3); glVertex2d(x0,-5); glEnd(); glColor3f(0,0,0); glBegin(GL_LINES); glVertex2d(x0,y3); glVertex2d(x0,y0); glEnd(); glBegin(GL_LINES); glVertex2d(x2,y3);
|Page 10

glVertex2d(x2,y0); glEnd(); glColor3f(1,0.6,0.1196); glBegin(GL_POLYGON ); glVertex2d(x0,y3); glVertex2d(x0,y2); glVertex2d(x2,y2); glVertex2d(x2,y3); glEnd();

glColor3f(0.074,0.5333,0.03); glBegin(GL_POLYGON ); glVertex2d(x0,y0); glVertex2d(x0,y1); glVertex2d(x2,y1); glVertex2d(x2,y0); glEnd(); glColor3f(1,1,1); glBegin(GL_POLYGON ); glVertex2d(x0,y1); glVertex2d(x0,y2); glVertex2d(x2,y2); glVertex2d(x2,y1); glEnd(); glFlush(); } static GLfloat alpha=0; void wheelDraw() {
|Page 11

glPushMatrix(); glRotatef(alpha,0.0,0.0,1.0); glColor3f(0.0,0.0,1.0); int i; glPointSize(20); glBegin(GL_LINES); for(i = 0; i < SPOKE_N; i++) { glVertex2f(0.0, 0.0); glVertex2f(spoke_pts[2 * i], spoke_pts[2 * i + 1]); } glEnd(); glBegin(GL_LINE_LOOP); for(i = 0; i < RIM_N; i++) { glVertex2f(rim_pts[2 * i], rim_pts[2 * i + 1]); } alpha+=1.0; if(alpha>=360) alpha-=360.0; glEnd(); glPopMatrix(); glFlush(); } float m=1,n=0,o=1; void mouse(int btn, int state, int x, int y) { if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN) {m=0.9,n=0.9,o=0.5;} if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) {m=0.6,n=0.4,o=0.93;} if(btn==GLUT_MIDDLE_BUTTON && state==GLUT_DOWN) {m=0.5,n=0.5,o=0.9;} } // Initializes information for drawing within OpenGL.
|Page 12

// Draw spokes.

// Draw rim.

void init() { glMatrixMode(GL_PROJECTION); glColor3f(0,0,1); glPointSize(55); gluOrtho2D(-6, 6, -6, 6); // Set viewable coordinates wheelInit(); } // Draws the picture. void draw() { glClearColor(m,n,o, 0.5); glClear(GL_COLOR_BUFFER_BIT); // Clear display window. // Set projection parameters.

glColor3f(0,0,1); glPointSize(20); flagDraw(); wheelDraw(); glFlush(); // Process all OpenGL routines as quickly as possible. } // Set line segment color to black.

void idle() { static int lastTime = 0; // time of last redraw int time = glutGet(GLUT_ELAPSED_TIME); // current time if(lastTime == 0 || time >= lastTime + 20) { lastTime = time; glutPostRedisplay(); } }

|Page

13

// When window becomes visible, we want the window to // continuously repaint itself. void visible(int vis) { glutIdleFunc(vis == GLUT_VISIBLE ? idle : NULL); }

int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(0, 0); glutInitWindowSize(520, 520); glutCreateWindow("NATIONAL FLAG"); glutVisibilityFunc(visible); glutMouseFunc(mouse); init(); glutDisplayFunc(draw); glutMainLoop(); return 0; } // Set up display window.

|Page

14

CONCLUSION
After the completion of this project we came to know how to work with Dev-C+ + platform and how we can implement a project using an Open source Open GL tool kit. By implementing a project using Open GL we came to know how to use The functions like rotation, delay, time functions and idle functions . With the completion of this project we have achieved a sense of happiness and we want to thank all those who helped us directly or indirectly to make this idea come true. Also since we are dealing with highly respected flag, we would like to apologize for any mistake we made unknowingly.

FUTURE ENHANCEMENTS:
Due to the time constraints, few things I wished to implement were left undone. If given a chance, I would like to introduce the waving function that would wave the flag and thus add to its glory.

|Page

15

REFERENCES
OpenGL Programming Guide (Addison-Wesley Publishing Company) The OpenGL Utility Toolkit (GLUT)Programming Interface -API Version 3 BY MARK J. KILGARD Interactive computer graphics -A top down approach by using Open GL by EDWARD ANGEL

|Page

16

You might also like