Membuat Manusia Salju

Tampilan hasil :



Langsung saja source code nya ya... silahkan dipelajari sendiri ... ^_^


#include
#include

int w ; int h;
int x1=0 , y1 = 0, z1=0;
int sudut=0;
int r = 3;

//GLdouble radius, GLdouble slices, GLint stacks
//GLdouble base, GLdouble height, GLint slices, GLint stacks
// torus --> GLdouble innerRadius, GLdouble outterRadius, GLint nsides, GLint rings

void renderScene ()
{
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 //glClearColor(1,1,1,1);
 glLoadIdentity();
 glTranslatef(0,0,-50);
 glRotatef(sudut,x1,y1,z1);

  glPushMatrix ();                        // badan bawah
      glColor3f (1, 1, 1);
      glTranslatef (0, -6, 0);
      glutSolidSphere (7, 36, 36);
 glPopMatrix ();

 glPushMatrix ();                   //badan tengah
      glColor3f (1, 1, 1);
      glTranslatef (0, 3, 0);
      glutSolidSphere (5, 36, 36);
 glPopMatrix ();

 glPushMatrix ();                   //tangan kanan
      glTranslatef (3.7, -3, 0);
      glLineWidth (5);
      glBegin (GL_LINES );
            glColor3f (1, 0, 0);
            glVertex2d (5 , 0);
            glVertex2d (1, 7);
      glEnd ();
 glPopMatrix ();

 glPushMatrix ();                   //jari1 tangan kanan
      glTranslatef (2.8, -2.8, 0);
      glLineWidth (5);
      glBegin (GL_LINES );
            glColor3f (1, 0, 0);
            glVertex2d (6 , 0);
            glVertex2d (7, 0.5);
      glEnd ();
 glPopMatrix ();


 glPushMatrix ();                   //jari2 tangan kanan
      glTranslatef (2.8, -3, 0);
      glLineWidth (5);
      glBegin (GL_LINES );
            glColor3f (1, 0, 0);
            glVertex2d (6 , 0);
            glVertex2d (7, -1);
      glEnd ();
 glPopMatrix ();

 glPushMatrix ();                   //jari3 tangan kanan
      glTranslatef (2.5, -2.8, 0);
      glLineWidth (5);
      glBegin (GL_LINES );
            glColor3f (1, 0, 0);
            glVertex2d (6 , 0);
            glVertex2d (5, -1);
      glEnd ();
 glPopMatrix ();

 glPushMatrix ();                   //tangan kiri
      glTranslatef (-3.7, -3, 0);
      glLineWidth (5);
      glBegin (GL_LINES );
            glColor3f (1, 0, 0);
            glVertex2d (-5 , 0);
            glVertex2d (-1, 7);
      glEnd ();
 glPopMatrix ();

 glPushMatrix ();                   //jari1 tangan kiri
      glTranslatef (-3.7, -3, 0);
      glLineWidth (5);
      glBegin (GL_LINES );
            glColor3f (1, 0, 0);
            glVertex2d (-5 , 0);
            glVertex2d (-6, -1);
      glEnd ();
 glPopMatrix ();

 glPushMatrix ();                   //jari2 tangan kiri
      glTranslatef (-3.7, -3, 0);
      glLineWidth (5);
      glBegin (GL_LINES );
            glColor3f (1, 0, 0);
            glVertex2d (-5 , 0);
            glVertex2d (-4, -0.8);
      glEnd ();
 glPopMatrix ();

 glPushMatrix ();                   //jari3 tangan kiri
      glTranslatef (-3.7, -3, 0);
      glLineWidth (5);
      glBegin (GL_LINES );
            glColor3f (1, 0, 0);
            glVertex2d (-5 , 0);
            glVertex2d (-6.5, 0);
      glEnd ();
 glPopMatrix ();

  glPushMatrix ();                        // kepala
      glColor3f (1, 1, 1);
      glTranslatef (0 , 10, 0);
      glutSolidSphere  (3 , 50, 50);
 glPopMatrix ();

 glPushMatrix ();                   //topi
      glTranslatef (0 , 11,  0);
      glRotatef (270, 1, 0, 0);
      glColor3f (1, 1, 0);
      glutSolidCone (3, 8, 36, 36);
 glPopMatrix ();

  glPushMatrix ();                        // mata kiri
      glColor3f (0 , 0, 0);
      glTranslatef (-1.5, 9.5, 3);
      glutWireSphere (0.4, 36, 36);
 glPopMatrix ();

 glPushMatrix ();                   // mata kanan
      glColor3f (0 , 0, 0);
      glTranslatef (1.5, 9.5, 3);
      glutWireSphere (0.4, 36, 36);
 glPopMatrix ();

 glPushMatrix ();                         // hidung
      glColor3f (1 , 0, 0);
      glTranslatef (0, 9, 2);
      glutSolidCone (0.6, 3, 36, 36);
 glPopMatrix ();

 glPushMatrix ();                         // hiasan leher
      glColor3f (1, 0, 0);
      glTranslatef (0, 7, 0.3);
      glRotatef (270, 1, 0, 0);
      glutSolidTorus (0.4, 4 , 10, 10);
 glPopMatrix ();

 glutSwapBuffers();
}

void resize (int w1, int h1)
{
      glViewport (0, 0 , w1, h1);
      glMatrixMode (GL_PROJECTION );
      glLoadIdentity ();
      gluPerspective (45.0 , (float) w1/ (float) h1, 1.0, 300.0);
      glMatrixMode (GL_MODELVIEW );
      glLoadIdentity ();
}

void init ()
{
      glClearColor (0.0 , 0.0 , 0.0 , 1.0);
      glEnable (GL_DEPTH_TEST );
      glMatrixMode (GL_PROJECTION );
      glLoadIdentity ();
      gluPerspective (45. , (GLdouble ) w/ (GLdouble )h , 1. , 300. );
      glMatrixMode (GL_MODELVIEW );
}

void myKeyboard (unsigned char  key, int x, int y)
{
      switch (key)
      {
      case 'x' :
            x1 = 1;
            y1 = 0;
            z1 = 0;
            sudut += 5;
            break ;
      case 'y' :
            y1 = 1;
            x1 = 0;
            z1 = 0;
            sudut +=-5;
            break ;
      case 'z' :
            y1 = 0;
            x1 = 0;
            z1 = 1;
            sudut +=-5;
            break;
      }
}

void update(int value )
{
      glutPostRedisplay ();
      glutTimerFunc (50 , update , 0);
}

void main (int argc, char **argv)
{
      glutInit (&argc, argv);
      glutInitDisplayMode (GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA );
      glutInitWindowPosition (100, 100);
      glutInitWindowSize (600 ,600);
      glutCreateWindow ("manusia salju");

      gluOrtho2D (-50 , 50, -50, 50);

      glutReshapeFunc (resize );
      init ();
      glutDisplayFunc (renderScene );
      glutTimerFunc (50, update , 0);
      glutKeyboardFunc (myKeyboard );
      glutMainLoop ();
}













 

Komentar

Postingan populer dari blog ini

Kita Masih diperjalanan

Salah Tujuan