#include<windows.h>
#include<GL/gl.h>
#include<GL/glu.h>
#include<GL/glut.h>
#include<math.h>
# define PI 3.14159265358979323846
void display();
void reshape(int, int);
void timer(int);
void init()
{
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
}
int main(int argc, char**argv)
{
glutInit(&argc ,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowPosition(200,100);
glutInitWindowSize(900, 900);
glutCreateWindow("Stickman");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutTimerFunc(0, timer, 0);
init();
glutMainLoop();
}
float x_position = -10.0;
int state = 1;
void display()
{
//glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
/*glBegin(GL_POLYGON);
glVertex2f(x_position, 1.0);
glVertex2f(x_position, -1.0);
glVertex2f(x_position+2.0, -1.0);
glVertex2f(x_position+2.0, 1.0);
glEnd();*/
/////head
int i;
GLfloat x=0.0f; GLfloat y=3.0f; GLfloat radius =1.0f;
int triangleAmount = 100; //# of lines used to draw circle
//GLfloat radius = 0.8f; //radius
GLfloat twicePi = 2.0f * PI;
glColor3f(0.0f, 0.0f, 0.0f);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(x, y); // center of circle
for(i = 0; i <= triangleAmount;i++) {
glVertex2f( x + (radius * cos(i * twicePi / triangleAmount)),
y + (radius * sin(i * twicePi / triangleAmount)) );
}
glEnd();
/////Chest
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
GLfloat cx1=0.0f ,cy1 = 2.0f;
GLfloat cx2=0.3f ,cy2 = 1.9f;
GLfloat cx3=0.3f ,cy3 = 1.0f;
GLfloat cx4=0.0f ,cy4 = 0.9f;
GLfloat cx5=-0.3f ,cy5 = 1.0f;
GLfloat cx6=-0.3f ,cy6 = 1.9f;
glVertex2f(cx1, cy1);
glVertex2f(cx2, cy2);
glVertex2f(cx3, cy3);
glVertex2f(cx4, cy4);
glVertex2f(cx5, cy5);
glVertex2f(cx6, cy6);
glEnd();
/////Abdomen
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
GLfloat ax1=0.0f ,ay1 = 0.9f;
GLfloat ax2=0.3f ,ay2 = 0.8f;
GLfloat ax3=0.3f ,ay3 = -0.5f;
GLfloat ax4=0.0f ,ay4 = -0.6f;
GLfloat ax5=-0.3f ,ay5 = -0.5f;
GLfloat ax6=-0.3f ,ay6 = 0.8f;
glVertex2f(ax1, ay1);
glVertex2f(ax2, ay2);
glVertex2f(ax3, ay3);
glVertex2f(ax4, ay4);
glVertex2f(ax5, ay5);
glVertex2f(ax6, ay6);
glEnd();
/////Thigh 1
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
GLfloat t1x1=0.0f ,t1y1 = -0.6f;
GLfloat t1x2=0.3f ,t1y2 = -0.7f;
GLfloat t1x3=0.3f ,t1y3 = -2.5f;
GLfloat t1x4=0.0f ,t1y4 = -2.6f;
GLfloat t1x5=-0.3f ,t1y5 = -2.5f;
GLfloat t1x6=-0.3f ,t1y6 = -0.7f;
glVertex2f(t1x1, t1y1);
glVertex2f(t1x2, t1y2);
glVertex2f(t1x3, t1y3);
glVertex2f(t1x4, t1y4);
glVertex2f(t1x5, t1y5);
glVertex2f(t1x6, t1y6);
glEnd();
/////Thigh 2
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
GLfloat t2x1=0.0f ,t2y1 = -0.6f;
GLfloat t2x2=0.3f ,t2y2 = -0.7f;
GLfloat t2x3=0.3f ,t2y3 = -2.5f;
GLfloat t2x4=0.0f ,t2y4 = -2.6f;
GLfloat t2x5=-0.3f ,t2y5 = -2.5f;
GLfloat t2x6=-0.3f ,t2y6 = -0.7f;
glVertex2f(t2x1, t2y1);
glVertex2f(t2x2, t2y2);
glVertex2f(t2x3, t2y3);
glVertex2f(t2x4, t2y4);
glVertex2f(t2x5, t2y5);
glVertex2f(t2x6, t2y6);
glEnd();
/////Leg 1
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
GLfloat l1x1=0.0f ,l1y1 = -2.6f;
GLfloat l1x2=0.3f ,l1y2 = -2.7f;
GLfloat l1x3=0.3f ,l1y3 = -4.2f;
GLfloat l1x4=0.0f ,l1y4 = -4.3f;
GLfloat l1x5=-0.3f ,l1y5 = -4.2f;
GLfloat l1x6=-0.3f ,l1y6 = -2.7f;
glVertex2f(l1x1, l1y1);
glVertex2f(l1x2, l1y2);
glVertex2f(l1x3, l1y3);
glVertex2f(l1x4, l1y4);
glVertex2f(l1x5, l1y5);
glVertex2f(l1x6, l1y6);
glEnd();
/////Leg 2
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
GLfloat l2x1=0.0f ,l2y1 = -2.6f;
GLfloat l2x2=0.3f ,l2y2 = -2.7f;
GLfloat l2x3=0.3f ,l2y3 = -4.2f;
GLfloat l2x4=0.0f ,l2y4 = -4.3f;
GLfloat l2x5=-0.3f ,l2y5 = -4.2f;
GLfloat l2x6=-0.3f ,l2y6 = -2.7f;
glVertex2f(l2x1, l2y1);
glVertex2f(l2x2, l2y2);
glVertex2f(l2x3, l2y3);
glVertex2f(l2x4, l2y4);
glVertex2f(l2x5, l2y5);
glVertex2f(l2x6, l2y6);
glEnd();
/////Biceps 1
glBegin(GL_POLYGON);
glColor3f(1.0f, 0.0f, 0.0f);
GLfloat b1x1=0.0f ,b1y1 = 2.0f;
GLfloat b1x2=0.3f ,b1y2 = 1.9f;
GLfloat b1x3=0.3f ,b1y3 = 0.1f;
GLfloat b1x4=0.0f ,b1y4 = 0.0f;
GLfloat b1x5=-0.3f ,b1y5 = 0.1f;
GLfloat b1x6=-0.3f ,b1y6 = 1.9f;
glVertex2f(b1x1, b1y1);
glVertex2f(b1x2, b1y2);
glVertex2f(b1x3, b1y3);
glVertex2f(b1x4, b1y4);
glVertex2f(b1x5, b1y5);
glVertex2f(b1x6, b1y6);
glEnd();
/////Biceps 2
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
GLfloat b2x1=0.0f ,b2y1 = 2.0f;
GLfloat b2x2=0.3f ,b2y2 = 1.9f;
GLfloat b2x3=0.3f ,b2y3 = 0.1f;
GLfloat b2x4=0.0f ,b2y4 = 0.0f;
GLfloat b2x5=-0.3f ,b2y5 = 0.1f;
GLfloat b2x6=-0.3f ,b2y6 = 1.9f;
glVertex2f(b2x1, b2y1);
glVertex2f(b2x2, b2y2);
glVertex2f(b2x3, b2y3);
glVertex2f(b2x4, b2y4);
glVertex2f(b2x5, b2y5);
glVertex2f(b2x6, b2y6);
glEnd();
/////Arms 1
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
GLfloat ar1x1=0.0f ,ar1y1 = 0.0f;
GLfloat ar1x2=0.3f ,ar1y2 = -0.1f;
GLfloat ar1x3=0.3f ,ar1y3 = -1.9f;
GLfloat ar1x4=0.0f ,ar1y4 = -2.0f;
GLfloat ar1x5=-0.3f ,ar1y5 = -1.9f;
GLfloat ar1x6=-0.3f ,ar1y6 = -0.1f;
glVertex2f(ar1x1, ar1y1);
glVertex2f(ar1x2, ar1y2);
glVertex2f(ar1x3, ar1y3);
glVertex2f(ar1x4, ar1y4);
glVertex2f(ar1x5, ar1y5);
glVertex2f(ar1x6, ar1y6);
glEnd();
/////Arms 2
glBegin(GL_POLYGON);
glColor3f(0.0f, 0.0f, 0.0f);
GLfloat ar2x1=0.0f ,ar2y1 = 0.0f;
GLfloat ar2x2=0.3f ,ar2y2 = -0.1f;
GLfloat ar2x3=0.3f ,ar2y3 = -1.9f;
GLfloat ar2x4=0.0f ,ar2y4 = -2.0f;
GLfloat ar2x5=-0.3f ,ar2y5 = -1.9f;
GLfloat ar2x6=-0.3f ,ar2y6 = -0.1f;
glVertex2f(ar2x1, ar2y1);
glVertex2f(ar2x2, ar2y2);
glVertex2f(ar2x3, ar2y3);
glVertex2f(ar2x4, ar2y4);
glVertex2f(ar2x5, ar2y5);
glVertex2f(ar2x6, ar2y6);
glEnd();
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0,0,(GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW);
}
void timer(int)
{
glutPostRedisplay();
glutTimerFunc(1000.00/60.00, timer, 0);
switch(state)
{
case 1:
if(x_position<8)
x_position+=0.15;
else
state = -1;
break;
case -1:
if(x_position>-10)
x_position-=0.15;
else
state=1;
break;
}
}