#include "stdafx.h" #using using namespace System; // make a robot //********************************************************************** #include //********************************************************************** //A function to display scene void Display(void) { //clear the window with the current clearing color glClear(GL_COLOR_BUFFER_BIT); glColor3f(0.0f,0.0f,0.7f); //body glBegin(GL_QUADS); glVertex2f(100.0f, 100.0f); glVertex2f(100.0f, 200.0f); glVertex2f(200.0f, 200.0f); glVertex2f(200.0f, 100.0); glEnd(); //neck glBegin(GL_QUADS); glVertex2f(135.0f,200.0f); glVertex2f(135.0f,215.0f); glVertex2f(165.0f,215.0f); glVertex2f(165.0f,200.0f); glEnd(); //head glBegin(GL_QUADS); glVertex2f(125.0f, 215.0f); glVertex2f(125.0f, 250.0f); glVertex2f(175.0f, 250.0f); glVertex2f(175.0f, 215.0); glEnd(); //cap glBegin(GL_QUADS); glVertex2f(122.0f, 250.0f); glVertex2f(122.0f, 253.0f); glVertex2f(178.0f, 253.0f); glVertex2f(178.0f, 250.0); glEnd(); glBegin(GL_TRIANGLES); glVertex2f(122.0f,253.0f); glVertex2f(178.0f,253.0f); glVertex2f(150.0f,260.0f); glEnd(); //left ear glBegin(GL_QUADS); glVertex2f(122.0f, 230.0f); glVertex2f(122.0f, 240.0f); glVertex2f(125.0f, 240.0f); glVertex2f(125.0f, 230.0); glEnd(); //right ear glBegin(GL_QUADS); glVertex2f(175.0f, 230.0f); glVertex2f(175.0f, 240.0f); glVertex2f(178.0f, 240.0f); glVertex2f(178.0f, 230.0); glEnd(); //left leg glBegin(GL_QUADS); glVertex2f(115.0f, 25.0f); glVertex2f(115.0f, 100.0f); glVertex2f(145.0f, 100.0f); glVertex2f(145.0f, 25.0); glEnd(); //right leg glBegin(GL_QUADS); glVertex2f(155.0f, 25.0f); glVertex2f(155.0f, 100.0f); glVertex2f(185.0f, 100.0f); glVertex2f(185.0f, 25.0); glEnd(); //left foot glBegin(GL_TRIANGLES); glVertex2f(115.0f,15.0f); glVertex2f(130.0f,40.0f); glVertex2f(145.0f,15.0f); glEnd(); //right foot glBegin(GL_TRIANGLES); glVertex2f(155.0f,15.0f); glVertex2f(170.0f,40.0f); glVertex2f(185.0f,15.0f); glEnd(); //left shoulder glBegin(GL_QUADS); glVertex2f(90.0f, 175.0f); glVertex2f(90.0f, 202.0f); glVertex2f(105.0f, 202.0f); glVertex2f(105.0f, 175.0); glEnd(); //right shoulder glBegin(GL_QUADS); glVertex2f(195.0f, 175.0f); glVertex2f(195.0f, 202.0f); glVertex2f(210.0f, 202.0f); glVertex2f(210.0f, 175.0); glEnd(); //left hand glBegin(GL_QUADS); glVertex2f(80.0f, 95.0f); glVertex2f(80.0f, 200.0f); glVertex2f(95.0f, 200.0f); glVertex2f(95.0f, 95.0); glEnd(); //right hand glBegin(GL_QUADS); glVertex2f(205.0f, 95.0f); glVertex2f(205.0f, 200.0f); glVertex2f(220.0f, 200.0f); glVertex2f(220.0f, 95.0); glEnd(); //left palm glBegin(GL_TRIANGLES); glVertex2f(75.0f, 95.0f); glVertex2f(100.0f, 95.0f); glVertex2f(87.5f, 85.0); glEnd(); //right palm glBegin(GL_TRIANGLES); glVertex2f(200.0f, 95.0f); glVertex2f(225.0f, 95.0f); glVertex2f(212.5f, 85.0); glEnd(); glColor3f(0.0f,0.0f,0.0f); //left eye glBegin(GL_QUADS); glVertex2f(140.0f, 235.0f); glVertex2f(140.0f, 240.0f); glVertex2f(145.0f, 240.0f); glVertex2f(145.0f, 235.0); glEnd(); //right eye glBegin(GL_QUADS); glVertex2f(155.0f, 235.0f); glVertex2f(155.0f, 240.0f); glVertex2f(160.0f, 240.0f); glVertex2f(160.0f, 235.0); glEnd(); //mouth glBegin(GL_QUADS); glVertex2f(140.0f, 225.0f); glVertex2f(150.0f, 230.0f); glVertex2f(160.0f, 225.0f); glVertex2f(150.0f, 220.0); glEnd(); //flush drawing comands glutSwapBuffers(); } //********************************************************************** //set up the rendering state for OpenGL void Initialize() { //set the background color to blue glClearColor(0.0f,0.5f,0.0f,1.0f); } void ChangeSize(GLsizei w, GLsizei h) { //prevent division by zero if(h==0) h=1; //set viewport to window dimensions glViewport(0,0,w,h); //reset the coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); //Establish clipping volume ((left, right, bottom, top, near, far) glOrtho(0.0f,300.0f,0.0f,300.0f,1.0f,-1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void main(void) { //Initializes the display mode of the GLUT library OpenGL window glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); //create a window with this title glutCreateWindow("Introduction"); //set the function for GLUT to call when the window needs to be //partially or completely redrawn glutDisplayFunc(Display); //Set the function for GLUT to call when the window gets resized glutReshapeFunc(ChangeSize); Initialize(); //start the Glut main loop glutMainLoop(); }