Membuat Manusia Salju
Tampilan hasil :
Langsung saja source code nya ya... silahkan dipelajari sendiri ... ^_^
Langsung saja source code nya ya... silahkan dipelajari sendiri ... ^_^
#include#includeint 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 ringsvoid 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 bawahglColor3f (1, 1, 1);glTranslatef (0, -6, 0);glutSolidSphere (7, 36, 36);glPopMatrix ();glPushMatrix (); //badan tengahglColor3f (1, 1, 1);glTranslatef (0, 3, 0);glutSolidSphere (5, 36, 36);glPopMatrix ();glPushMatrix (); //tangan kananglTranslatef (3.7, -3, 0);glLineWidth (5);glBegin (GL_LINES );glColor3f (1, 0, 0);glVertex2d (5 , 0);glVertex2d (1, 7);glEnd ();glPopMatrix ();glPushMatrix (); //jari1 tangan kananglTranslatef (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 kananglTranslatef (2.8, -3, 0);glLineWidth (5);glBegin (GL_LINES );glColor3f (1, 0, 0);glVertex2d (6 , 0);glVertex2d (7, -1);glEnd ();glPopMatrix ();glPushMatrix (); //jari3 tangan kananglTranslatef (2.5, -2.8, 0);glLineWidth (5);glBegin (GL_LINES );glColor3f (1, 0, 0);glVertex2d (6 , 0);glVertex2d (5, -1);glEnd ();glPopMatrix ();glPushMatrix (); //tangan kiriglTranslatef (-3.7, -3, 0);glLineWidth (5);glBegin (GL_LINES );glColor3f (1, 0, 0);glVertex2d (-5 , 0);glVertex2d (-1, 7);glEnd ();glPopMatrix ();glPushMatrix (); //jari1 tangan kiriglTranslatef (-3.7, -3, 0);glLineWidth (5);glBegin (GL_LINES );glColor3f (1, 0, 0);glVertex2d (-5 , 0);glVertex2d (-6, -1);glEnd ();glPopMatrix ();glPushMatrix (); //jari2 tangan kiriglTranslatef (-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 kiriglTranslatef (-3.7, -3, 0);glLineWidth (5);glBegin (GL_LINES );glColor3f (1, 0, 0);glVertex2d (-5 , 0);glVertex2d (-6.5, 0);glEnd ();glPopMatrix ();glPushMatrix (); // kepalaglColor3f (1, 1, 1);glTranslatef (0 , 10, 0);glutSolidSphere (3 , 50, 50);glPopMatrix ();glPushMatrix (); //topiglTranslatef (0 , 11, 0);glRotatef (270, 1, 0, 0);glColor3f (1, 1, 0);glutSolidCone (3, 8, 36, 36);glPopMatrix ();glPushMatrix (); // mata kiriglColor3f (0 , 0, 0);glTranslatef (-1.5, 9.5, 3);glutWireSphere (0.4, 36, 36);glPopMatrix ();glPushMatrix (); // mata kananglColor3f (0 , 0, 0);glTranslatef (1.5, 9.5, 3);glutWireSphere (0.4, 36, 36);glPopMatrix ();glPushMatrix (); // hidungglColor3f (1 , 0, 0);glTranslatef (0, 9, 2);glutSolidCone (0.6, 3, 36, 36);glPopMatrix ();glPushMatrix (); // hiasan leherglColor3f (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
Posting Komentar
Mohon Berkomentar dengan bahasa yang sopan. Terimakasih ^^