/*
* GLUT Shapes Demo
*
* Written by Nigel Stewart November 2003
*
* This program is test harness for the sphere, cone
* and torus shapes in GLUT.
*
* Spinning wireframe and smooth shaded shapes are
* displayed until the ESC or q key is pressed. The
* number of geometry stacks and slices can be adjusted
* using the + and - keys.
*/
#include <windows.h>
#include <GL/glut.h>
#include <math.h> // needs to be included for cos and sin functions
using namespace std;
#define PI 3.1415926535898
void init(void)
{
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 150.0, 0.0, 150.0);
}
GLint circle_points= 100;
void MyCircle2f(GLfloat centerx, GLfloat centery, GLfloat radius){ //function to draw circle
GLint i; //declaring integer for the 'for' loop
GLdouble theta;
glBegin (GL_POLYGON); //begin drawing a polygon
glColor3f(1.0f, 1.0f, 1.0f); // set color for the circle to a shade of red
for(i=0; i<circle_points; i++){ //for loop to draw circle
theta = 2*PI*i/circle_points; //value for theta or angle in radians
glVertex2f(centerx+radius*cos(theta),centery+radius*sin(theta)); //draw vertices of circle
}
glEnd(); //signifying end of the polygon in this case circle
glFlush();
}
void Display(void)
{
//clear all pixels with the specified clear color
glClearColor (0.2, 0.2, 0.7, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
MyCircle2f(80.0, 85.0, 10.0); //calling the circle function and setting center to be point 80, 85 with radius of 10
// this is possible because all these functions are in the same project /class
//the eyes are black points
//set the point size to be 3.0 pixels
glBegin(GL_POINTS);
glColor3f(0.0,0.0,0.0); //setting color of eye to black
glVertex2f(77.0,88.0); //given that the center of the circle(head of human) is at point(80,85)
glVertex2f(83.0,88.0); // creating a point 3pixels each from the center positions of the circle will achieve the
//the expected results that is the eye
glEnd();
//polygonal body
glColor3f(0.8,0.0,0.9);//setting the color for the polygon
glBegin(GL_POLYGON);
glVertex2f(75.0, 75.0); //this vertex is carefully placed(calculated) so that it is tangential to the circle(head)
//such that is starts 5 pixels/points to the left from the center but 10pixels/points down the y coordinates from the center
//since the radius is 10pixels or points
glVertex2f(85.0, 75.0); //this is also calculated with similar explanation as above. notice the y coordinates are the same (75) this gives a horizontal line to for the polygon
glVertex2f(100.0, 30.0); //coordinate (100, 30) meaning it opens up to the right and comes down
glVertex2f(60.0,30.0); // coordinate (60, 30), meaning it opens up to the left and comes down at the same position as the y coordinate that is 30
//to form a horizontal line for the base of the polygon
glEnd();
//rectangular legs
glColor3f(1.0, 0.8, 0.1); //color for legs
glRectf(70.0, 5.0, 75.0, 30.0); //coordinates for rectangle
glRectf(85.0, 5.0, 90.0, 30.0); //coordinates for rectangle
//lines for hands
glBegin(GL_LINES);
glVertex2f(74.0, 70.0); //calculated and carefully placed
glVertex2f(50.0, 50.0);
glEnd();
glBegin(GL_LINES);
glVertex2f(88.0, 70.0); //calculated and carefully placed
glVertex2f(110.0, 50.0);
glEnd();
glFlush(); //flush OpenGL and call to display buffer
glutSwapBuffers();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(500, 500);
glutInitWindowPosition(0, 0);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("Stick Figure");
init();
glutDisplayFunc(Display); //function call to display stick figure
glutMainLoop();
return EXIT_SUCCESS;
}