Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Source Code

jk

Uploaded by

1ep21cs041.cse
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Source Code

jk

Uploaded by

1ep21cs041.cse
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

#include<windows.

h>

#include<GL/glut.h>

#include<GL/glu.h>

#include<stdio.h>

#include<stdlib.h>

#include<stdarg.h>

#include<math.h>

#define TIMER 33

float quad;

void *font = GLUT_STROKE_ROMAN;

void *fonts[] =

GLUT_STROKE_ROMAN, GLUT_STROKE_MONO_ROMAN};

static float xrot;

int value=15,val=5,valu,v=1;

void polygon();

int theObject = -1;

char* objectNames[10] ={"minion","winku","snowman"};

void output(GLfloat x, GLfloat y, char *format,...)

va_list args;

char buffer[200], *p;

if(theObject>=0)

va_start(args, format);
vsprintf(buffer, format, args);

va_end(args);

glPushMatrix();

glTranslatef(x, y, 0);

for (p = buffer; *p; p++)

glutStrokeCharacter(font, *p);

glPopMatrix();

void text()

glColor3f(1.0,0.0,0.0);

glMatrixMode(GL_PROJECTION);

glPushMatrix();

glLoadIdentity();

gluOrtho2D(0, 3000, 0, 3000);

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

glLoadIdentity();

glColor3f(1.0,1.0,1.0);

output(1800,2800, "%s",objectNames[theObject]);

glPopMatrix();

glMatrixMode(GL_PROJECTION);

glPopMatrix();

glMatrixMode(GL_MODELVIEW);

glPopAttrib();
}

void drawScene (GLenum order)

GLfloat pos[4] = {-2.5, 5., 2.2, 1.};

glLightfv (GL_LIGHT1, GL_POSITION, pos);

glPushMatrix();

glEnable (GL_CULL_FACE);

glCullFace (GL_BACK);

glFrontFace(order);

text();

/* Draw the walls */

glColor3f(1.0,0.9,1.0);

glBegin(GL_QUADS);

glNormal3f (1., 0., 0.);

glVertex3f (-3., 3., 4.);

glVertex3f (-3., -3., 4.);

glVertex3f (-3., -3., -3.);

glVertex3f (-3., 3., -3.);

glNormal3f (0., 0., 1.);

glVertex3f (-3., 3., -3.);

glVertex3f (-3., -3., -3.);

glVertex3f (3., -3., -3.);

glVertex3f (3., 3., -3.);

glNormal3f (-1., 0., 0.);

glVertex3f (3., 3., -3.);


glVertex3f (3., -3., -3.);

glVertex3f (3., -3., 3.);

glVertex3f (3., 3., 3.);

glEnd();

glDisable (GL_CULL_FACE);

/* Draw the polygon */

glPushMatrix ();

glPopMatrix ();

polygon();

glPopMatrix();

void minion()

theObject=0;

glRotatef(xrot,0.0,1.0,0.0);

glPushMatrix();

//BODY OF MINION//

glPushMatrix();

glTranslatef(0,.2,0);

glScalef(0.5,0.5,0.5);

glColor3f(1.0,1.0,0.0);

glRotatef(90.0,1,0,0);

gluCylinder(gluNewQuadric(),.6,.6,1.4,100,100);

glPopMatrix();

glPushMatrix();
glTranslatef(0,0.18,0);

glScalef(.9 ,.9,.9 );

glColor3f(1.0,1.0,0.0);

glutSolidSphere(0.333,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(0,-0.45,0);

glScalef(.9 ,.7,.9 );

glColor3f(0.0,0.0,1.0);

glutSolidSphere(0.333,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(.0,0.1,.29); //Specify the coordinates for the right eye

glRotatef(-45,0,0,1);

glScalef(.95,.95,.95); //Specify the size of the right eye

glColor3f(0.0,0.0,0.0); //Specify the color of the eye

glutSolidSphere(0.05,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(0,0.1,0.3); //eye spectacle

glScalef(.15,.15,.19);

glColor3f(1.0,0.0,0.0);

glRotatef(0.0,1,0,0);

glutSolidTorus(.09,0.7,20,20);
glPopMatrix();

glPushMatrix();

glTranslatef(0,0.1,-0.007); //belt

glScalef(.84,1.0,.84);

glColor3f(0.0,0.0,0.0);

glRotatef(90.0,1,0,0);

glutSolidTorus(.02,0.35,20,20);

glPopMatrix();

glPushMatrix();

glTranslatef(0,-0.22,0); //minion shorts

glScalef(0.5,0.2,0.5);

glColor3f(0.0,0.0,1.0);

glRotatef(90.0,1,0,0);

gluCylinder(gluNewQuadric(),.62,.62,1.4,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(-.5,-0.4,.1);

glColor3f(1.0,1.0,0.0); //Specify the position for the left arm

glRotatef(90,0,1,0);

glRotatef(-50,1,0,0);

gluCylinder(gluNewQuadric(),.02,.05,.48,30,6);

glPopMatrix();

glPushMatrix();
glTranslatef(0.5,-0.4,.1); //Specify the position for the right arm

glRotatef(90,0,1,0);

glRotatef(-130,1,0,0);

gluCylinder(gluNewQuadric(),.02,.05,.48,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(-0.5,-0.4,.1); //Specify the position for the left hand

glScalef(.19,.14,.14);

gluSphere(gluNewQuadric(),.3,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(0.5,-0.4,.1); //Specify the position for the right hand

glScalef(.19,.14,.14);

gluSphere(gluNewQuadric(),.3,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(.05,-.9,0); //Specify the position for the left leg

glRotatef(-90.0,1,0,0);

glColor3f(0.0,0.0,1.0);

glScalef(.9,.3,.9);

gluCylinder(gluNewQuadric(),.03,.05,.4,30,6);

glPopMatrix();

glPushMatrix();
glTranslatef(-.05,-.9,0); //Specify the position for the right leg

glRotatef(-90.0,1,0,0);

glColor3f(0.0,0.0,1.0);

glScalef(.9,.3,.9);

gluCylinder(gluNewQuadric(),.03,.05,.4,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(.06,-.89,0); //shoes

glScalef(0.9,.7,1.5);

glColor3f(0.0,0.0,0.0);

gluSphere(gluNewQuadric(),.06,100,200);

glPopMatrix();

glPushMatrix();

glTranslatef(-.06,-.89,0);

glScalef(0.9,.7,1.5);

glColor3f(0.0,0.0,0.0);

gluSphere(gluNewQuadric(),.06,100,200);

glPopMatrix();

glPopMatrix();

void winku()

theObject=1;
glRotatef(xrot,0.0,1.0,0.0);

glPushMatrix();

glPushMatrix();

glTranslatef(0,0.3,0); //head

glScalef(.9 ,.9,.9 );

glColor3f(1.0,0.8,0.6);

glutSolidSphere(0.38,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(-0.002,0.41,0); //hat

glScalef(.98,.98,.98);

glColor3f(0.0,0.0,1.0);

glutSolidSphere(0.33,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(0,0.43,0); //outline hat

glScalef(.84,.84,.84);

glColor3f(1.0,0.0,0.0);

glRotatef(90.0,1,0,0);

glutSolidTorus(.03,0.4,20,20);

glPopMatrix();

glPushMatrix();

glTranslatef(0,.08,0);
glScalef(0.75,.7,0.75);

glColor3f(0.5,0.5,0.0);

glRotatef(90.0,1,0,0);

gluCylinder( gluNewQuadric(),.3,.45,0.5,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(0,-0.11,.29);

glRotatef(-17.0,1,0,0);

glScalef(.05,.33,.03);

glColor3f(0.0,0.0,0.0);

glutSolidCube(1);

glPopMatrix();

glPushMatrix();

glTranslatef(0,0.05,0.02);

glScalef(.84,.84,.84);

glColor3f(1.0,0.0,0.0);

glRotatef(90.0,1,0,0);

glutSolidTorus(.04,0.32,20,20);

glPopMatrix();

glPushMatrix();

glTranslatef(.17,0.3,.27); //Specify the coordinates for the right eye

glRotatef(-45,0,0,1);

glScalef(.9,.9,.9); //Specify the size of the right eye

glColor3f(0.0,0.0,0.0); //Specify the color of the eye


glutSolidSphere(0.05,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(-.17,0.3,.29); //Specify the position for the left eye

glRotatef(45,0,0,1);

glScalef(.9,.9,.9);

glColor3f(0.0,0.0,0.0);

glutSolidSphere(0.05,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(0.01,.22,.33);

glScalef(.6,.4,.1);

glColor3f(1.0,0.0,0.0);

glutSolidSphere(0.1,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(.13,-.5,0); //Specify the position for the left leg

glRotatef(-90.0,1,0,0);

glScalef(.8,.8,.8);

gluCylinder(gluNewQuadric(),.19,.19,.5,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(-.13,-.5,0); //Specify the position for the right leg


glRotatef(-90.0,1,0,0);

glScalef(.8,.8,.8);

gluCylinder(gluNewQuadric(),.19,.19,.5,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(.13,-.49,0); //shoes

glScalef(1.6,.4,1.5);

glColor3f(0.0,0.0,0.0);

gluSphere(gluNewQuadric(),.11,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(-.13,-.49,0);

glScalef(1.6,.4,1.5);

glColor3f(0.0,0.0,0.0);

gluSphere(gluNewQuadric(),.11,100,100);

glPopMatrix();

glPopMatrix();

void snowman()

theObject = 2;

glTranslatef(0.0,0.0,0.6);

glPushMatrix();
glRotatef(xrot,0.0,1.0,0.0);

glColor3f(1.0,1.0,1.0);

glTranslatef(0.0,0.0,0.0);

glutSolidSphere(0.4,16,16); //upper body

glColor3f(1.0,1.0,1.0);

glTranslatef(0.0,0.55,0.0);

glutSolidSphere(0.2,16,16); //head

glColor3f(0.0,0.0,0.0);

glTranslatef(0.1,0.1,0.13);

glutSolidSphere(0.02,16,16); //eye

glTranslatef(-0.1,0.0,0.05);

glutSolidSphere(0.02,16,16); //eye

glTranslatef(0.05,-0.1,-0.3);

glColor3f(1.0,0.0,0.0);

glutSolidCone(0.06,0.5,50,50); //nose

glTranslatef(-0.05,0.15,0.1);

glRotated(270,1.0,0.0,0.0);

glColor3f(0.0,0.0,0.0);

glutSolidCone(0.15,0.5,50,50); //hat

glColor3f(1.0,1.0,1.0);

glTranslatef(0.0,0.0,-1.5);

glutSolidSphere(0.6,50,50); //lower body

glPopMatrix();

glPushMatrix();

glRotatef(xrot,0.0,1.0,0.0);

glScalef(1,0.05,0.05);
glColor3f(0.0,0.0,1.0);

glTranslatef(0.5,2.0,2.0);

glRotatef(12,1,0,0);

glutSolidCube(1.0); //hand

glTranslatef(-1.0,-0.6,-2.0);

glutSolidCube(1.0); //hand

glPopMatrix();

void polygon()

if(value==14)

minion();

if(value==15)

winku();

if(value==16)

snowman();

void pol(int p)

value=p;

void main_menu(int valu)

{
value=valu;

if (value == 0)

exit(0);

static void display( void )

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity ();

gluLookAt (1., 1., 4.,-1., 0., 0.,0., 1., 0.);

/* Draw reflected scene first */

glPushMatrix ();

/* Mirrors lies in YZ plane, we can scale mirror in all three axes */

glScalef (-1., 1., 1.);

/* Mirror is 2.0 units from origin, so translate by 4.0 */

glTranslatef (4, 0., 0.);

//glTranslatef (-4, 0., 0.);

drawScene(GL_CW);

glPopMatrix ();

glPushMatrix ();

glScalef (-1.0, 1.0, 1.0);

glTranslatef (-1, 0., -4.);

drawScene(GL_CW);

glPopMatrix ();
glPushMatrix ();

glScalef (-1.0, 1.0, 1.0);

glTranslatef (0, -4., -3.);

drawScene(GL_CW);

glPopMatrix ();

/* draw mirror */

glClear (GL_DEPTH_BUFFER_BIT);

glPushAttrib (0xffffffff);

glDisable (GL_LIGHTING);

/* Create imperfect reflector effect by blending a black

mirror over the reflected scene with alpha of 0.05 */

glEnable (GL_BLEND);

glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glPointSize(6);

glColor3f(1.0,0.0,0.0);

glBegin (GL_LINE_LOOP);

glVertex3f (-2.,1.5, 2.2);

glVertex3f (-2., -1.5, 2.5);

glVertex3f (-2., -1.5, -2.5);

glVertex3f (-2., 1.5, -2.5);

glEnd ();

glColor4f (0., 0., 0., 0.05);

glBegin (GL_QUADS);

glVertex3f (-2.,1.5, 2.2);

glVertex3f (-2., -1.5, 2.5);

glVertex3f (-2., -1.5, -2.5);

glVertex3f (-2., 1.5, -2.5);


glEnd();

glPushMatrix();

glRotated(90,0,0,1);

glColor3f(1.0,0.0,0.0);

glBegin (GL_LINE_LOOP);

glVertex3f (-2.,1.5, 2.2);

glVertex3f (-2., -2, 2.5);

glVertex3f (-2., -2, -2.5);

glVertex3f (-2., 1.5, -2.5);

glEnd ();

glPopMatrix();

glPushMatrix();

glRotated(90,0,0,1);

glColor4f (0., 0., 0., 0.05);

glBegin (GL_QUADS);

glVertex3f (-2.,1.5, 2.2);

glVertex3f (-2., -2, 2.5);

glVertex3f (-2., -2, -2.5);

glVertex3f (-2., 1.5, -2.5);

glEnd();

glPopMatrix();

glColor3f(1.0,0.0,0.0);

glBegin (GL_LINE_LOOP);

glVertex3f (-1.,1.4, -1.5);


glVertex3f (-1., -1.4, -1.5);

glVertex3f (2.2, -1., -1.5);

glVertex3f (2.1, 1.4, -1.5);

glEnd();

glColor4f (0., 0., 0., 0.05);

glBegin(GL_QUADS);

glVertex3f (-1.,1.4, -1.5);

glVertex3f (-1., -1.4, -1.5);

glVertex3f (2.2, -1., -1.5);

glVertex3f (2.1, 1.4, -1.5);

glEnd ();

glPopAttrib();

/* Draw the real scene */

drawScene(GL_CCW);

glutSwapBuffers();

void selectFont(int newfont) #include<windows.h>

#include<GL/glut.h>

#include<GL/glu.h>

#include<stdio.h>

#include<stdlib.h>

#include<stdarg.h>

#include<math.h>

#define TIMER 33

float quad;
void *font = GLUT_STROKE_ROMAN;

void *fonts[] =

GLUT_STROKE_ROMAN, GLUT_STROKE_MONO_ROMAN};

static float xrot;

int value=15,val=5,valu,v=1;

void polygon();

int theObject = -1;

char* objectNames[10] ={"minion","winku","snowman"};

void output(GLfloat x, GLfloat y, char *format,...)

va_list args;

char buffer[200], *p;

if(theObject>=0)

va_start(args, format);

vsprintf(buffer, format, args);

va_end(args);

glPushMatrix();

glTranslatef(x, y, 0);

for (p = buffer; *p; p++)

glutStrokeCharacter(font, *p);

glPopMatrix();

}
void text()

glColor3f(1.0,0.0,0.0);

glMatrixMode(GL_PROJECTION);

glPushMatrix();

glLoadIdentity();

gluOrtho2D(0, 3000, 0, 3000);

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

glLoadIdentity();

glColor3f(1.0,1.0,1.0);

output(1800,2800, "%s",objectNames[theObject]);

glPopMatrix();

glMatrixMode(GL_PROJECTION);

glPopMatrix();

glMatrixMode(GL_MODELVIEW);

glPopAttrib();

void drawScene (GLenum order)

GLfloat pos[4] = {-2.5, 5., 2.2, 1.};

glLightfv (GL_LIGHT1, GL_POSITION, pos);

glPushMatrix();

glEnable (GL_CULL_FACE);

glCullFace (GL_BACK);
glFrontFace(order);

text();

/* Draw the walls */

glColor3f(1.0,0.9,1.0);

glBegin(GL_QUADS);

glNormal3f (1., 0., 0.);

glVertex3f (-3., 3., 4.);

glVertex3f (-3., -3., 4.);

glVertex3f (-3., -3., -3.);

glVertex3f (-3., 3., -3.);

glNormal3f (0., 0., 1.);

glVertex3f (-3., 3., -3.);

glVertex3f (-3., -3., -3.);

glVertex3f (3., -3., -3.);

glVertex3f (3., 3., -3.);

glNormal3f (-1., 0., 0.);

glVertex3f (3., 3., -3.);

glVertex3f (3., -3., -3.);

glVertex3f (3., -3., 3.);

glVertex3f (3., 3., 3.);

glEnd();

glDisable (GL_CULL_FACE);

/* Draw the polygon */

glPushMatrix ();

glPopMatrix ();

polygon();
glPopMatrix();

void minion()

theObject=0;

glRotatef(xrot,0.0,1.0,0.0);

glPushMatrix();

//BODY OF MINION//

glPushMatrix();

glTranslatef(0,.2,0);

glScalef(0.5,0.5,0.5);

glColor3f(1.0,1.0,0.0);

glRotatef(90.0,1,0,0);

gluCylinder(gluNewQuadric(),.6,.6,1.4,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(0,0.18,0);

glScalef(.9 ,.9,.9 );

glColor3f(1.0,1.0,0.0);

glutSolidSphere(0.333,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(0,-0.45,0);

glScalef(.9 ,.7,.9 );
glColor3f(0.0,0.0,1.0);

glutSolidSphere(0.333,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(.0,0.1,.29); //Specify the coordinates for the right eye

glRotatef(-45,0,0,1);

glScalef(.95,.95,.95); //Specify the size of the right eye

glColor3f(0.0,0.0,0.0); //Specify the color of the eye

glutSolidSphere(0.05,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(0,0.1,0.3); //eye spectacle

glScalef(.15,.15,.19);

glColor3f(1.0,0.0,0.0);

glRotatef(0.0,1,0,0);

glutSolidTorus(.09,0.7,20,20);

glPopMatrix();

glPushMatrix();

glTranslatef(0,0.1,-0.007); //belt

glScalef(.84,1.0,.84);

glColor3f(0.0,0.0,0.0);

glRotatef(90.0,1,0,0);

glutSolidTorus(.02,0.35,20,20);

glPopMatrix();
glPushMatrix();

glTranslatef(0,-0.22,0); //minion shorts

glScalef(0.5,0.2,0.5);

glColor3f(0.0,0.0,1.0);

glRotatef(90.0,1,0,0);

gluCylinder(gluNewQuadric(),.62,.62,1.4,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(-.5,-0.4,.1);

glColor3f(1.0,1.0,0.0); //Specify the position for the left arm

glRotatef(90,0,1,0);

glRotatef(-50,1,0,0);

gluCylinder(gluNewQuadric(),.02,.05,.48,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(0.5,-0.4,.1); //Specify the position for the right arm

glRotatef(90,0,1,0);

glRotatef(-130,1,0,0);

gluCylinder(gluNewQuadric(),.02,.05,.48,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(-0.5,-0.4,.1); //Specify the position for the left hand

glScalef(.19,.14,.14);
gluSphere(gluNewQuadric(),.3,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(0.5,-0.4,.1); //Specify the position for the right hand

glScalef(.19,.14,.14);

gluSphere(gluNewQuadric(),.3,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(.05,-.9,0); //Specify the position for the left leg

glRotatef(-90.0,1,0,0);

glColor3f(0.0,0.0,1.0);

glScalef(.9,.3,.9);

gluCylinder(gluNewQuadric(),.03,.05,.4,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(-.05,-.9,0); //Specify the position for the right leg

glRotatef(-90.0,1,0,0);

glColor3f(0.0,0.0,1.0);

glScalef(.9,.3,.9);

gluCylinder(gluNewQuadric(),.03,.05,.4,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(.06,-.89,0); //shoes
glScalef(0.9,.7,1.5);

glColor3f(0.0,0.0,0.0);

gluSphere(gluNewQuadric(),.06,100,200);

glPopMatrix();

glPushMatrix();

glTranslatef(-.06,-.89,0);

glScalef(0.9,.7,1.5);

glColor3f(0.0,0.0,0.0);

gluSphere(gluNewQuadric(),.06,100,200);

glPopMatrix();

glPopMatrix();

void winku()

theObject=1;

glRotatef(xrot,0.0,1.0,0.0);

glPushMatrix();

glPushMatrix();

glTranslatef(0,0.3,0); //head

glScalef(.9 ,.9,.9 );

glColor3f(1.0,0.8,0.6);

glutSolidSphere(0.38,25,16);

glPopMatrix();
glPushMatrix();

glTranslatef(-0.002,0.41,0); //hat

glScalef(.98,.98,.98);

glColor3f(0.0,0.0,1.0);

glutSolidSphere(0.33,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(0,0.43,0); //outline hat

glScalef(.84,.84,.84);

glColor3f(1.0,0.0,0.0);

glRotatef(90.0,1,0,0);

glutSolidTorus(.03,0.4,20,20);

glPopMatrix();

glPushMatrix();

glTranslatef(0,.08,0);

glScalef(0.75,.7,0.75);

glColor3f(0.5,0.5,0.0);

glRotatef(90.0,1,0,0);

gluCylinder( gluNewQuadric(),.3,.45,0.5,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(0,-0.11,.29);

glRotatef(-17.0,1,0,0);
glScalef(.05,.33,.03);

glColor3f(0.0,0.0,0.0);

glutSolidCube(1);

glPopMatrix();

glPushMatrix();

glTranslatef(0,0.05,0.02);

glScalef(.84,.84,.84);

glColor3f(1.0,0.0,0.0);

glRotatef(90.0,1,0,0);

glutSolidTorus(.04,0.32,20,20);

glPopMatrix();

glPushMatrix();

glTranslatef(.17,0.3,.27); //Specify the coordinates for the right eye

glRotatef(-45,0,0,1);

glScalef(.9,.9,.9); //Specify the size of the right eye

glColor3f(0.0,0.0,0.0); //Specify the color of the eye

glutSolidSphere(0.05,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(-.17,0.3,.29); //Specify the position for the left eye

glRotatef(45,0,0,1);

glScalef(.9,.9,.9);

glColor3f(0.0,0.0,0.0);

glutSolidSphere(0.05,25,16);
glPopMatrix();

glPushMatrix();

glTranslatef(0.01,.22,.33);

glScalef(.6,.4,.1);

glColor3f(1.0,0.0,0.0);

glutSolidSphere(0.1,25,16);

glPopMatrix();

glPushMatrix();

glTranslatef(.13,-.5,0); //Specify the position for the left leg

glRotatef(-90.0,1,0,0);

glScalef(.8,.8,.8);

gluCylinder(gluNewQuadric(),.19,.19,.5,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(-.13,-.5,0); //Specify the position for the right leg

glRotatef(-90.0,1,0,0);

glScalef(.8,.8,.8);

gluCylinder(gluNewQuadric(),.19,.19,.5,30,6);

glPopMatrix();

glPushMatrix();

glTranslatef(.13,-.49,0); //shoes

glScalef(1.6,.4,1.5);
glColor3f(0.0,0.0,0.0);

gluSphere(gluNewQuadric(),.11,100,100);

glPopMatrix();

glPushMatrix();

glTranslatef(-.13,-.49,0);

glScalef(1.6,.4,1.5);

glColor3f(0.0,0.0,0.0);

gluSphere(gluNewQuadric(),.11,100,100);

glPopMatrix();

glPopMatrix();

void snowman()

theObject = 2;

glTranslatef(0.0,0.0,0.6);

glPushMatrix();

glRotatef(xrot,0.0,1.0,0.0);

glColor3f(1.0,1.0,1.0);

glTranslatef(0.0,0.0,0.0);

glutSolidSphere(0.4,16,16); //upper body

glColor3f(1.0,1.0,1.0);

glTranslatef(0.0,0.55,0.0);

glutSolidSphere(0.2,16,16); //head

glColor3f(0.0,0.0,0.0);
glTranslatef(0.1,0.1,0.13);

glutSolidSphere(0.02,16,16); //eye

glTranslatef(-0.1,0.0,0.05);

glutSolidSphere(0.02,16,16); //eye

glTranslatef(0.05,-0.1,-0.3);

glColor3f(1.0,0.0,0.0);

glutSolidCone(0.06,0.5,50,50); //nose

glTranslatef(-0.05,0.15,0.1);

glRotated(270,1.0,0.0,0.0);

glColor3f(0.0,0.0,0.0);

glutSolidCone(0.15,0.5,50,50); //hat

glColor3f(1.0,1.0,1.0);

glTranslatef(0.0,0.0,-1.5);

glutSolidSphere(0.6,50,50); //lower body

glPopMatrix();

glPushMatrix();

glRotatef(xrot,0.0,1.0,0.0);

glScalef(1,0.05,0.05);

glColor3f(0.0,0.0,1.0);

glTranslatef(0.5,2.0,2.0);

glRotatef(12,1,0,0);

glutSolidCube(1.0); //hand

glTranslatef(-1.0,-0.6,-2.0);

glutSolidCube(1.0); //hand

glPopMatrix();

}
void polygon()

if(value==14)

minion();

if(value==15)

winku();

if(value==16)

snowman();

void pol(int p)

value=p;

void main_menu(int valu)

value=valu;

if (value == 0)

exit(0);

static void display( void )

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity ();

gluLookAt (1., 1., 4.,-1., 0., 0.,0., 1., 0.);

/* Draw reflected scene first */

glPushMatrix ();

/* Mirrors lies in YZ plane, we can scale mirror in all three axes */

glScalef (-1., 1., 1.);

/* Mirror is 2.0 units from origin, so translate by 4.0 */

glTranslatef (4, 0., 0.);

//glTranslatef (-4, 0., 0.);

drawScene(GL_CW);

glPopMatrix ();

glPushMatrix ();

glScalef (-1.0, 1.0, 1.0);

glTranslatef (-1, 0., -4.);

drawScene(GL_CW);

glPopMatrix ();

glPushMatrix ();

glScalef (-1.0, 1.0, 1.0);

glTranslatef (0, -4., -3.);

drawScene(GL_CW);

glPopMatrix ();

/* draw mirror */

glClear (GL_DEPTH_BUFFER_BIT);

glPushAttrib (0xffffffff);

glDisable (GL_LIGHTING);
/* Create imperfect reflector effect by blending a black

mirror over the reflected scene with alpha of 0.05 */

glEnable (GL_BLEND);

glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glPointSize(6);

glColor3f(1.0,0.0,0.0);

glBegin (GL_LINE_LOOP);

glVertex3f (-2.,1.5, 2.2);

glVertex3f (-2., -1.5, 2.5);

glVertex3f (-2., -1.5, -2.5);

glVertex3f (-2., 1.5, -2.5);

glEnd ();

glColor4f (0., 0., 0., 0.05);

glBegin (GL_QUADS);

glVertex3f (-2.,1.5, 2.2);

glVertex3f (-2., -1.5, 2.5);

glVertex3f (-2., -1.5, -2.5);

glVertex3f (-2., 1.5, -2.5);

glEnd();

glPushMatrix();

glRotated(90,0,0,1);

glColor3f(1.0,0.0,0.0);

glBegin (GL_LINE_LOOP);

glVertex3f (-2.,1.5, 2.2);

glVertex3f (-2., -2, 2.5);

glVertex3f (-2., -2, -2.5);


glVertex3f (-2., 1.5, -2.5);

glEnd ();

glPopMatrix();

glPushMatrix();

glRotated(90,0,0,1);

glColor4f (0., 0., 0., 0.05);

glBegin (GL_QUADS);

glVertex3f (-2.,1.5, 2.2);

glVertex3f (-2., -2, 2.5);

glVertex3f (-2., -2, -2.5);

glVertex3f (-2., 1.5, -2.5);

glEnd();

glPopMatrix();

glColor3f(1.0,0.0,0.0);

glBegin (GL_LINE_LOOP);

glVertex3f (-1.,1.4, -1.5);

glVertex3f (-1., -1.4, -1.5);

glVertex3f (2.2, -1., -1.5);

glVertex3f (2.1, 1.4, -1.5);

glEnd();

glColor4f (0., 0., 0., 0.05);

glBegin(GL_QUADS);

glVertex3f (-1.,1.4, -1.5);

glVertex3f (-1., -1.4, -1.5);


glVertex3f (2.2, -1., -1.5);

glVertex3f (2.1, 1.4, -1.5);

glEnd ();

glPopAttrib();

/* Draw the real scene */

drawScene(GL_CCW);

glutSwapBuffers();

void selectFont(int newfont)

font = fonts[newfont];

glutPostRedisplay();

void reshape(int w, int h)

glViewport (0, 0, w, h);

glMatrixMode (GL_PROJECTION);

glLoadIdentity ();

gluPerspective (50., (float)w/(float)h, 1., 20.);

void kb(unsigned char key, int x, int y)

int nv=value,cv=val;

if(key=='n' &&nv>=14 &&nv<=17)

value++;
if(key=='n' &&nv==17)

value=14;

if(key=='c' && cv>=3 && cv<=7)

val++;

if(key=='c' && cv==7)

val=3;

if(key=='i' && v<16)

v++;

if(key=='d' &&v>=1)

v--;

static void timer (int value)

xrot +=v;

if (xrot> 360.f) xrot -= 360.f;

glutPostRedisplay ();

glutTimerFunc (TIMER, timer, 0);

static void init ()

int s1,s2,s3;

xrot = 1.;

glEnable (GL_DEPTH_TEST);

GLfloat white[4] = {1., 1., 1., 1.};


GLfloat black[4] = {0., 0., 0., 0.};

/* Set up light1 */

glEnable (GL_LIGHTING);

glEnable (GL_LIGHT1);

glLightfv (GL_LIGHT1, GL_DIFFUSE, white);

glLightfv (GL_LIGHT1, GL_SPECULAR, white);

/* ambient and diffuse will track glColor */

glEnable (GL_COLOR_MATERIAL);

glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

glMaterialfv (GL_FRONT, GL_SPECULAR, white);

glMaterialf (GL_FRONT, GL_SHININESS, 20.);

glutDisplayFunc (display);

glutReshapeFunc (reshape);

glutTimerFunc (TIMER, timer, 0);

s1=glutCreateMenu(pol);

glutAddMenuEntry("minion", 14);

glutAddMenuEntry("winku", 15);

glutAddMenuEntry("snowman",16);

s2=glutCreateMenu(selectFont);

glutAddMenuEntry("Roman",0);

glutAddMenuEntry("Mono Roman",1);

glutCreateMenu(main_menu);

glutAddSubMenu("Object",s1);

glutAddSubMenu("texts",s2);

glutAddMenuEntry("Quit", 0);

glutAttachMenu(GLUT_RIGHT_BUTTON);
}

int main(int argc, char** argv)

glutInit (&argc,argv);

glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);

glutInitWindowSize (300,300);

glutInitWindowPosition (0,0);

glutCreateWindow ("THE REFLECTION");

glutKeyboardFunc(kb);

init ();

glutMainLoop ();

font = fonts[newfont];

glutPostRedisplay();

void reshape(int w, int h)

glViewport (0, 0, w, h);

glMatrixMode (GL_PROJECTION);

glLoadIdentity ();

gluPerspective (50., (float)w/(float)h, 1., 20.);

void kb(unsigned char key, int x, int y)

{
int nv=value,cv=val;

if(key=='n' &&nv>=14 &&nv<=17)

value++;

if(key=='n' &&nv==17)

value=14;

if(key=='c' && cv>=3 && cv<=7)

val++;

if(key=='c' && cv==7)

val=3;

if(key=='i' && v<16)

v++;

if(key=='d' &&v>=1)

v--;

static void timer (int value)

xrot +=v;

if (xrot> 360.f) xrot -= 360.f;

glutPostRedisplay ();

glutTimerFunc (TIMER, timer, 0);

static void init ()

int s1,s2,s3;

xrot = 1.;
glEnable (GL_DEPTH_TEST);

GLfloat white[4] = {1., 1., 1., 1.};

GLfloat black[4] = {0., 0., 0., 0.};

/* Set up light1 */

glEnable (GL_LIGHTING);

glEnable (GL_LIGHT1);

glLightfv (GL_LIGHT1, GL_DIFFUSE, white);

glLightfv (GL_LIGHT1, GL_SPECULAR, white);

/* ambient and diffuse will track glColor */

glEnable (GL_COLOR_MATERIAL);

glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE);

glMaterialfv (GL_FRONT, GL_SPECULAR, white);

glMaterialf (GL_FRONT, GL_SHININESS, 20.);

glutDisplayFunc (display);

glutReshapeFunc (reshape);

glutTimerFunc (TIMER, timer, 0);

s1=glutCreateMenu(pol);

glutAddMenuEntry("minion", 14);

glutAddMenuEntry("winku", 15);

glutAddMenuEntry("snowman",16);

s2=glutCreateMenu(selectFont);

glutAddMenuEntry("Roman",0);

glutAddMenuEntry("Mono Roman",1);

glutCreateMenu(main_menu);

glutAddSubMenu("Object",s1);
glutAddSubMenu("texts",s2);

glutAddMenuEntry("Quit", 0);

glutAttachMenu(GLUT_RIGHT_BUTTON);

int main(int argc, char** argv)

glutInit (&argc,argv);

glutInitDisplayMode (GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);

glutInitWindowSize (300,300);

glutInitWindowPosition (0,0);

glutCreateWindow ("THE REFLECTION");

glutKeyboardFunc(kb);

init ();

glutMainLoop ();

You might also like