Facebook
From Insensitive Bushbaby, 1 Year ago, written in C++.
Embed
Download Paste or View Raw
Hits: 101
  1. #include<windows.h>
  2. #include<GL/gl.h>
  3. #include<GL/glu.h>
  4. #include<GL/glut.h>
  5. #include<math.h>
  6.  
  7. # define PI           3.14159265358979323846
  8.  
  9. void display();
  10. void reshape(int, int);
  11. void timer(int);
  12.  
  13. void init()
  14. {
  15.     glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
  16. }
  17.  
  18. int main(int argc, char**argv)
  19. {
  20.     glutInit(&argc ,argv);
  21.     glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
  22.  
  23.     glutInitWindowPosition(200,100);
  24.     glutInitWindowSize(900, 900);
  25.  
  26.     glutCreateWindow("Stickman");
  27.  
  28.     glutDisplayFunc(display);
  29.     glutReshapeFunc(reshape);
  30.     glutTimerFunc(0, timer, 0);
  31.     init();
  32.  
  33.     glutMainLoop();
  34. }
  35.  
  36. float x_position = -10.0;
  37. int state = 1;
  38.  
  39. void display()
  40. {
  41.     //glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
  42.     glClear(GL_COLOR_BUFFER_BIT);
  43.     glLoadIdentity();
  44.  
  45.     /*glBegin(GL_POLYGON);
  46.  
  47.     glVertex2f(x_position, 1.0);
  48.     glVertex2f(x_position, -1.0);
  49.     glVertex2f(x_position+2.0, -1.0);
  50.     glVertex2f(x_position+2.0, 1.0);
  51.  
  52.     glEnd();*/
  53.  
  54.     /////head
  55.  
  56.     int i;
  57.  
  58.         GLfloat x=0.0f; GLfloat y=3.0f; GLfloat radius =1.0f;
  59.         int triangleAmount = 100; //# of lines used to draw circle
  60.  
  61.         //GLfloat radius = 0.8f; //radius
  62.         GLfloat twicePi = 2.0f * PI;
  63.  
  64.         glColor3f(0.0f, 0.0f, 0.0f);
  65.         glBegin(GL_TRIANGLE_FAN);
  66.                 glVertex2f(x, y); // center of circle
  67.                 for(i = 0; i <= triangleAmount;i++) {
  68.                         glVertex2f( x + (radius * cos(i *  twicePi / triangleAmount)),
  69.                         y + (radius * sin(i * twicePi / triangleAmount)) );
  70.                 }
  71.         glEnd();
  72.  
  73.     /////Chest
  74.  
  75.     glBegin(GL_POLYGON);
  76.     glColor3f(0.0f, 0.0f, 0.0f);
  77.  
  78.     GLfloat cx1=0.0f ,cy1 = 2.0f;
  79.     GLfloat cx2=0.3f ,cy2 = 1.9f;
  80.     GLfloat cx3=0.3f ,cy3 = 1.0f;
  81.     GLfloat cx4=0.0f ,cy4 = 0.9f;
  82.     GLfloat cx5=-0.3f ,cy5 = 1.0f;
  83.     GLfloat cx6=-0.3f ,cy6 = 1.9f;
  84.  
  85.  
  86.     glVertex2f(cx1, cy1);
  87.     glVertex2f(cx2, cy2);
  88.     glVertex2f(cx3, cy3);
  89.     glVertex2f(cx4, cy4);
  90.     glVertex2f(cx5, cy5);
  91.     glVertex2f(cx6, cy6);
  92.  
  93.  
  94.     glEnd();
  95.  
  96.     /////Abdomen
  97.  
  98.     glBegin(GL_POLYGON);
  99.     glColor3f(0.0f, 0.0f, 0.0f);
  100.  
  101.     GLfloat ax1=0.0f ,ay1 = 0.9f;
  102.     GLfloat ax2=0.3f ,ay2 = 0.8f;
  103.     GLfloat ax3=0.3f ,ay3 = -0.5f;
  104.     GLfloat ax4=0.0f ,ay4 = -0.6f;
  105.     GLfloat ax5=-0.3f ,ay5 = -0.5f;
  106.     GLfloat ax6=-0.3f ,ay6 = 0.8f;
  107.  
  108.  
  109.     glVertex2f(ax1, ay1);
  110.     glVertex2f(ax2, ay2);
  111.     glVertex2f(ax3, ay3);
  112.     glVertex2f(ax4, ay4);
  113.     glVertex2f(ax5, ay5);
  114.     glVertex2f(ax6, ay6);
  115.  
  116.  
  117.     glEnd();
  118.  
  119.     /////Thigh 1
  120.  
  121.     glBegin(GL_POLYGON);
  122.     glColor3f(0.0f, 0.0f, 0.0f);
  123.  
  124.     GLfloat t1x1=0.0f ,t1y1 = -0.6f;
  125.     GLfloat t1x2=0.3f ,t1y2 = -0.7f;
  126.     GLfloat t1x3=0.3f ,t1y3 = -2.5f;
  127.     GLfloat t1x4=0.0f ,t1y4 = -2.6f;
  128.     GLfloat t1x5=-0.3f ,t1y5 = -2.5f;
  129.     GLfloat t1x6=-0.3f ,t1y6 = -0.7f;
  130.  
  131.  
  132.     glVertex2f(t1x1, t1y1);
  133.     glVertex2f(t1x2, t1y2);
  134.     glVertex2f(t1x3, t1y3);
  135.     glVertex2f(t1x4, t1y4);
  136.     glVertex2f(t1x5, t1y5);
  137.     glVertex2f(t1x6, t1y6);
  138.  
  139.  
  140.     glEnd();
  141.  
  142.     /////Thigh 2
  143.  
  144.     glBegin(GL_POLYGON);
  145.     glColor3f(0.0f, 0.0f, 0.0f);
  146.  
  147.     GLfloat t2x1=0.0f ,t2y1 = -0.6f;
  148.     GLfloat t2x2=0.3f ,t2y2 = -0.7f;
  149.     GLfloat t2x3=0.3f ,t2y3 = -2.5f;
  150.     GLfloat t2x4=0.0f ,t2y4 = -2.6f;
  151.     GLfloat t2x5=-0.3f ,t2y5 = -2.5f;
  152.     GLfloat t2x6=-0.3f ,t2y6 = -0.7f;
  153.  
  154.  
  155.     glVertex2f(t2x1, t2y1);
  156.     glVertex2f(t2x2, t2y2);
  157.     glVertex2f(t2x3, t2y3);
  158.     glVertex2f(t2x4, t2y4);
  159.     glVertex2f(t2x5, t2y5);
  160.     glVertex2f(t2x6, t2y6);
  161.  
  162.     glEnd();
  163.  
  164.     /////Leg 1
  165.  
  166.     glBegin(GL_POLYGON);
  167.     glColor3f(0.0f, 0.0f, 0.0f);
  168.  
  169.     GLfloat l1x1=0.0f ,l1y1 = -2.6f;
  170.     GLfloat l1x2=0.3f ,l1y2 = -2.7f;
  171.     GLfloat l1x3=0.3f ,l1y3 = -4.2f;
  172.     GLfloat l1x4=0.0f ,l1y4 = -4.3f;
  173.     GLfloat l1x5=-0.3f ,l1y5 = -4.2f;
  174.     GLfloat l1x6=-0.3f ,l1y6 = -2.7f;
  175.  
  176.  
  177.     glVertex2f(l1x1, l1y1);
  178.     glVertex2f(l1x2, l1y2);
  179.     glVertex2f(l1x3, l1y3);
  180.     glVertex2f(l1x4, l1y4);
  181.     glVertex2f(l1x5, l1y5);
  182.     glVertex2f(l1x6, l1y6);
  183.  
  184.  
  185.     glEnd();
  186.  
  187.     /////Leg 2
  188.  
  189.     glBegin(GL_POLYGON);
  190.     glColor3f(0.0f, 0.0f, 0.0f);
  191.  
  192.     GLfloat l2x1=0.0f ,l2y1 = -2.6f;
  193.     GLfloat l2x2=0.3f ,l2y2 = -2.7f;
  194.     GLfloat l2x3=0.3f ,l2y3 = -4.2f;
  195.     GLfloat l2x4=0.0f ,l2y4 = -4.3f;
  196.     GLfloat l2x5=-0.3f ,l2y5 = -4.2f;
  197.     GLfloat l2x6=-0.3f ,l2y6 = -2.7f;
  198.  
  199.  
  200.     glVertex2f(l2x1, l2y1);
  201.     glVertex2f(l2x2, l2y2);
  202.     glVertex2f(l2x3, l2y3);
  203.     glVertex2f(l2x4, l2y4);
  204.     glVertex2f(l2x5, l2y5);
  205.     glVertex2f(l2x6, l2y6);
  206.  
  207.  
  208.     glEnd();
  209.  
  210.     /////Biceps 1
  211.  
  212.     glBegin(GL_POLYGON);
  213.     glColor3f(1.0f, 0.0f, 0.0f);
  214.  
  215.     GLfloat b1x1=0.0f ,b1y1 = 2.0f;
  216.     GLfloat b1x2=0.3f ,b1y2 = 1.9f;
  217.     GLfloat b1x3=0.3f ,b1y3 = 0.1f;
  218.     GLfloat b1x4=0.0f ,b1y4 = 0.0f;
  219.     GLfloat b1x5=-0.3f ,b1y5 = 0.1f;
  220.     GLfloat b1x6=-0.3f ,b1y6 = 1.9f;
  221.  
  222.  
  223.     glVertex2f(b1x1, b1y1);
  224.     glVertex2f(b1x2, b1y2);
  225.     glVertex2f(b1x3, b1y3);
  226.     glVertex2f(b1x4, b1y4);
  227.     glVertex2f(b1x5, b1y5);
  228.     glVertex2f(b1x6, b1y6);
  229.  
  230.  
  231.     glEnd();
  232.  
  233.     /////Biceps 2
  234.  
  235.     glBegin(GL_POLYGON);
  236.     glColor3f(0.0f, 0.0f, 0.0f);
  237.  
  238.     GLfloat b2x1=0.0f ,b2y1 = 2.0f;
  239.     GLfloat b2x2=0.3f ,b2y2 = 1.9f;
  240.     GLfloat b2x3=0.3f ,b2y3 = 0.1f;
  241.     GLfloat b2x4=0.0f ,b2y4 = 0.0f;
  242.     GLfloat b2x5=-0.3f ,b2y5 = 0.1f;
  243.     GLfloat b2x6=-0.3f ,b2y6 = 1.9f;
  244.  
  245.  
  246.     glVertex2f(b2x1, b2y1);
  247.     glVertex2f(b2x2, b2y2);
  248.     glVertex2f(b2x3, b2y3);
  249.     glVertex2f(b2x4, b2y4);
  250.     glVertex2f(b2x5, b2y5);
  251.     glVertex2f(b2x6, b2y6);
  252.  
  253.  
  254.     glEnd();
  255.  
  256.     /////Arms 1
  257.  
  258.     glBegin(GL_POLYGON);
  259.     glColor3f(0.0f, 0.0f, 0.0f);
  260.  
  261.     GLfloat ar1x1=0.0f ,ar1y1 = 0.0f;
  262.     GLfloat ar1x2=0.3f ,ar1y2 = -0.1f;
  263.     GLfloat ar1x3=0.3f ,ar1y3 = -1.9f;
  264.     GLfloat ar1x4=0.0f ,ar1y4 = -2.0f;
  265.     GLfloat ar1x5=-0.3f ,ar1y5 = -1.9f;
  266.     GLfloat ar1x6=-0.3f ,ar1y6 = -0.1f;
  267.  
  268.  
  269.     glVertex2f(ar1x1, ar1y1);
  270.     glVertex2f(ar1x2, ar1y2);
  271.     glVertex2f(ar1x3, ar1y3);
  272.     glVertex2f(ar1x4, ar1y4);
  273.     glVertex2f(ar1x5, ar1y5);
  274.     glVertex2f(ar1x6, ar1y6);
  275.  
  276.  
  277.     glEnd();
  278.  
  279.     /////Arms 2
  280.  
  281.     glBegin(GL_POLYGON);
  282.     glColor3f(0.0f, 0.0f, 0.0f);
  283.  
  284.     GLfloat ar2x1=0.0f ,ar2y1 = 0.0f;
  285.     GLfloat ar2x2=0.3f ,ar2y2 = -0.1f;
  286.     GLfloat ar2x3=0.3f ,ar2y3 = -1.9f;
  287.     GLfloat ar2x4=0.0f ,ar2y4 = -2.0f;
  288.     GLfloat ar2x5=-0.3f ,ar2y5 = -1.9f;
  289.     GLfloat ar2x6=-0.3f ,ar2y6 = -0.1f;
  290.  
  291.  
  292.     glVertex2f(ar2x1, ar2y1);
  293.     glVertex2f(ar2x2, ar2y2);
  294.     glVertex2f(ar2x3, ar2y3);
  295.     glVertex2f(ar2x4, ar2y4);
  296.     glVertex2f(ar2x5, ar2y5);
  297.     glVertex2f(ar2x6, ar2y6);
  298.  
  299.  
  300.     glEnd();
  301.  
  302.     glutSwapBuffers();
  303. }
  304.  
  305. void reshape(int w, int h)
  306. {
  307.     glViewport(0,0,(GLsizei)w, (GLsizei)h);
  308.     glMatrixMode(GL_PROJECTION);
  309.     glLoadIdentity();
  310.     gluOrtho2D(-10,10,-10,10);
  311.     glMatrixMode(GL_MODELVIEW);
  312. }
  313.  
  314. void timer(int)
  315. {
  316.     glutPostRedisplay();
  317.     glutTimerFunc(1000.00/60.00, timer, 0);
  318.  
  319.     switch(state)
  320.     {
  321.     case 1:
  322.         if(x_position<8)
  323.             x_position+=0.15;
  324.         else
  325.             state = -1;
  326.         break;
  327.     case -1:
  328.         if(x_position>-10)
  329.             x_position-=0.15;
  330.         else
  331.             state=1;
  332.         break;
  333.     }
  334. }
  335.