Working of Satellite CG Project Using OpenGL Report
Working of Satellite CG Project Using OpenGL Report
CONTENTS
Abstract
We have used font family for indicating the name of objects as we can
see in this project.
System specifications
SOFTWARE REQUIREMENTS :
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
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.
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.
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.
Implementation
This program is implemented using various openGL functions which are
shown below.
glutCreateWindow() : this opens the OPENGL window and displays the title
at top of the window
Q-> Quit
Source Code
#include <windows.h>
#include<string.h>
#include<stdarg.h>
#include<stdio.h>
#include <glut.h>
#include <math.h>
//control waves
void *font;
void *currentfont;
currentfont=font;
char *c;
glRasterPos3f(x,y,z);
for(c=string;*c!='\0';c++)
{ glColor3f(0.0,1.0,1.0);
glutBitmapCharacter(currentfont,*c);
void
va_list args;
12 Dept. of Computer Science & Engineering.
Working of a Satellite
va_start(args, format);
va_end(args);
glPushMatrix();
glTranslatef(-2.5, y, 0);
glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
glPopMatrix();
void satellite(){
glRotatef(60,1,0,0);
//body
glPushMatrix();
13 Dept. of Computer Science & Engineering.
Working of a Satellite
glColor3f(0.2,0.2,0.2);
glScaled(1,0.6,1);
glTranslatef(3.0,0,0.0);
glutSolidCube(0.4);
glPopMatrix();
//Solar Panels
glPushMatrix();
glColor3f(0.3,0.3,0.3);
glTranslatef(3,0,0.0);
//glRotatef(45,1,0,0);
glScaled(3.7,0.0,1);
glutSolidCube(0.4);
glPopMatrix();
glPushMatrix();
glColor3f(0.2,0.1,0.1);
glTranslatef(3.0,0,-0.4);
glScaled(0.5,0.5,0.5);
14 Dept. of Computer Science & Engineering.
Working of a Satellite
glutSolidSphere(0.3,50,50);
glPopMatrix();
glPushMatrix();
glColor3f(0.2,0.2,0.1);
glTranslatef(3.0,0,0.4);
glScaled(0.4,0.4,0.3);
glutSolidTorus(0.3,0.2,20,20);
glPopMatrix();
// Second Screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
glRotatef(ang,0.0f,1.0f,0.0f);
//earth
glPushMatrix();
glColor3f(0.3,0.6,1);
//glScaled(0.8,0.04,0.8);
//glTranslatef(0.0,0,0.0);
glutSolidSphere(2.0,50,50);
glPopMatrix();
satellite();
glFlush();
glutSwapBuffers();
//Main Structure
glPushMatrix();
glColor3f(0.5,0.5,0.5);
glTranslatef(x1,y1,z1);
glScaled(0.5,1.5,0.5);
glutSolidCube(2);
glPopMatrix();
//Dish on top
glPushMatrix();
glColor3f(1,1,0);
glTranslatef(x1,y1+1.8,z1);
glRotatef(60,1,0,0);
glScaled(0.5,1.5,0.5);
glutSolidCone(0.5,1,20,20);
glPopMatrix();
//windows
glPushMatrix();
glColor3f(0.1,0,0);
17 Dept. of Computer Science & Engineering.
Working of a Satellite
glTranslatef(x1-0.2,y1+0.7,z1);
glScaled(0.5,0.5,0.5);
//glutSolidCube(.3);
for(float j=-3;j<1.5;j+=.8)
for(float i=0;i<1;i+=0.8)
glPushMatrix();
glTranslatef(i,j,1);
glutSolidCube(0.4);
glPopMatrix();
glPopMatrix();
void waves(){
glPushMatrix();
glTranslatef(0,1,0);
glScaled(0.05,0.5,0.1);
glutSolidCube(0.5);
glPopMatrix();
glPushMatrix();
glRotatef(-8,0,0,1);
glTranslatef(0.01,1,0);
glScaled(0.05,0.5,0.1);
glutSolidCube(0.5);
glPopMatrix();
glPushMatrix();
glRotatef(8,0,0,1);
glTranslatef(-0.01,1,0);
glScaled(0.05,0.6,0.1);
glutSolidCube(0.5);
19 Dept. of Computer Science & Engineering.
Working of a Satellite
glPopMatrix();
void sat1(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
//glRotatef(x,0.0f,1.0f,0.0f);
//Moon
glPushMatrix();
glColor3f(1,1,1);
glTranslatef(-3.8,2.8,0);
glScaled(0.5,0.5,0.1);
glutSolidSphere(0.6,50,50);
glPopMatrix();
//Earth
glPushMatrix();
glColor3f(0.2,0.2,1);
glTranslatef(0,-12,0);
//glScaled(0.8,0.04,0.8);
glutSolidSphere(10.0,50,50);
glPopMatrix();
//Building Center
glPushMatrix();
glColor3f(0,1,1);
glRotatef(10,1,0,0);
building(1.2,-1.2,3.2);
glPopMatrix();
//Building left
glPushMatrix();
glColor3f(0,1,1);
glRotatef(5,0,0,1);
building(-3.8,-1.2,0);
21 Dept. of Computer Science & Engineering.
Working of a Satellite
glPopMatrix();
//signal
glPushMatrix();
glColor3f(0,0,1);
if(transmit){
glRotatef(-25,0,0,1);
glTranslatef(-1.25,-1.6+w1,0);
}else glTranslatef(1,20,3.3);
waves();
glPopMatrix();
//Main Dish
//Tower
glPushMatrix();
glColor3f(1,1,1);
22 Dept. of Computer Science & Engineering.
Working of a Satellite
glTranslatef(-1,-2,4);
glRotatef(270,1,0,0);
glScaled(1.0,1,2.0);
glutWireCone(0.5,1,4,10);
glPopMatrix();
//Dish
glPushMatrix();
glColor3f(1,1,1);
glTranslatef(-1.08,0.2,3);
glRotatef(60,1,0,0);
glScaled(0.7,1.3,0.7);
glutSolidCone(0.4,0.5,20,20);
glPopMatrix();
//Building right
glPushMatrix();
glColor3f(0,1,1);
glRotatef(-5,0,0,1);
building(3.8,-1.2,0);
23 Dept. of Computer Science & Engineering.
Working of a Satellite
glPopMatrix();
//Saltellite
glPushMatrix();
glTranslatef(-3,3.0,0);
satellite();
glPopMatrix();
glPushMatrix();
if(transmit){
glRotatef(50,0,0,1);
glTranslatef(2.8,3.2-w2,0);
}else glTranslatef(1,20,3.3);
waves();
glPopMatrix();
glPushMatrix();
if(transmit){
glRotatef(-50,0,0,1);
glTranslatef(-2.8,3.2-w2,0);
}else glTranslatef(1,20,3.3);
waves();
glPopMatrix();
glPushMatrix();
if(transmit){
glRotatef(23,0,0,1);
glTranslatef(1,3.2-w3,3.3);
else glTranslatef(1,20,3.3);
waves();
25 Dept. of Computer Science & Engineering.
Working of a Satellite
glPopMatrix();
//stars
glPointSize(5);
for(int j=0;j<100;j++)
for(int i=0;i<100;i++)
rx[j]=rand()/500;
ry[i]=rand()/500;
glBegin(GL_POINTS);
glColor3f(0,2,2);
glVertex3f(-6+rx[j],ry[i],-5);
glEnd();
}
26 Dept. of Computer Science & Engineering.
Working of a Satellite
glPushMatrix();
//glScaled(1.1,2.0,0.1);
glTranslatef(0.0,0.0,-2.0);
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(1,3.7,-1.0,"Satelitte");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-4.4,.5,-1.0,"Reciever");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,0);
drawstring(0,-2,7,"Reciever");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
glColor3f(1,1,1);
drawstring(-1.5,-1,-1.0,"Transmitter");
setFont(GLUT_BITMAP_TIMES_ROMAN_24);
27 Dept. of Computer Science & Engineering.
Working of a Satellite
glColor3f(1,1,1);
drawstring(3.2,1,3,"Reciever");
glPopMatrix();
glFlush();
glutSwapBuffers();
// Third Screen
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
glRotatef(ang,0.0f,1.0f,0.0f);
//earth
glPushMatrix();
glColor3f(0.3,0.6,1);
//glScaled(0.8,0.04,0.8);
//glTranslatef(0.0,0,0.0);
glutSolidSphere(2.0,50,50);
glPopMatrix();
satellite();
glFlush();
glutSwapBuffers();
void e()
x-=0.07;
sat2(x);
void s()
x-=0.07;
sat2(x);
void S()
x += .07;
if(transmit)
if(w1<=4.2)
30 Dept. of Computer Science & Engineering.
Working of a Satellite
w1+=0.01;
w2+=0.01;
w3+=0.01;
sat1();
void doInit()
glClearColor(0.0,0.0,0.0,0);
glViewport(0,0,640,480);
31 Dept. of Computer Science & Engineering.
Working of a Satellite
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(30.0f,(GLfloat)640/(GLfloat)480,0.1f,200.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearDepth(2.0f);
glEnable(GL_DEPTH_TEST);
glEnable( GL_COLOR_MATERIAL );
glDepthFunc(GL_LEQUAL);
void display()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-13.0f);
GLfloat mat_ambient[]={0.0f,1.0f,2.0f,1.0f};
GLfloat mat_diffuse[]={0.0f,1.5f,.5f,1.0f};
GLfloat mat_specular[]={5.0f,1.0f,1.0f,1.0f};
GLfloat mat_shininess[]={50.0f};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
GLfloat lightIntensity[]={1.7f,1.7f,1.7f,1.0f};
33 Dept. of Computer Science & Engineering.
Working of a Satellite
GLfloat light_position3[]={0.0f,8.0f,10.0f,0.0f};
glLightfv(GL_LIGHT0,GL_POSITION,light_position3);
glLightfv(GL_LIGHT0,GL_DIFFUSE,lightIntensity);
GLfloat lightIntensity1[]={1.7f,1.7f,1.7f,1.0f};
GLfloat light_position31[]={-2.0f,8.0f,10.0f,0.0f};
glLightfv(GL_LIGHT1,GL_POSITION,light_position31);
glLightfv(GL_LIGHT1,GL_DIFFUSE,lightIntensity1);
glEnable(GL_COLOR_MATERIAL);
glFlush();
glutSwapBuffers();
switch(id)
34 Dept. of Computer Science & Engineering.
Working of a Satellite
case 1:glutIdleFunc(S);
break;
case 2:glutIdleFunc(s);
break;
case 5:exit(0);
break;
glFlush();
glutSwapBuffers();
glutPostRedisplay();
if(key=='s')
glutIdleFunc(s);
35 Dept. of Computer Science & Engineering.
Working of a Satellite
if(key=='S')
glutIdleFunc(S);
if(key=='e')
glutIdleFunc(e);
if(key=='t')
{ transmit=!transmit;
if(!transmit)
w1=0;
w2=0;
36 Dept. of Computer Science & Engineering.
Working of a Satellite
w3=0;
glutIdleFunc(S);
if(key=='q'||key=='Q')
exit(0);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
37 Dept. of Computer Science & Engineering.
Working of a Satellite
glutInitWindowSize(1000,480);
glutInitWindowPosition(0,0);
glutCreateWindow("Working of a Satellite");
glutDisplayFunc(display);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glutKeyboardFunc(mykey);
glutCreateMenu(menu);
glutAddMenuEntry("Pyramid 's'",1);
glutAddMenuEntry("Quit 'q'",5);
glutAttachMenu(GLUT_RIGHT_BUTTON);
doInit();
glutMainLoop();
return 0;
}
38 Dept. of Computer Science & Engineering.
Working of a Satellite
Conclusions
Finally we conclude that this program clearly illustrate the working of a satellite
using OpenGL and has been completed successfully and is ready to be
demonstrated.
Bibliography
WE HAVE OBTAINED INFORMATION FROM MANY RESOURCES TO DESIGN AND
IMPLEMENT OUR PROJECT SUCCESSIVELY. WE HAVE ACQUIRED MOST OF THE
KNOWLEDGE FROM RELATED WEBSITES. THE FOLLOWING ARE SOME OF THE
RESOURCES :
TEXT BOOKS :
INTERACTIVE COMPUTER GRAPHICS A TOP-DOWN APPROACH
-By Edward Angel.
- Feiner hughes
WEB REFERENCES:
http://jerome.jouvie.free.fr/OpenGl/Lessons/Lesson3.php
http://google.com
http://opengl.org