The document describes code for drawing a robot using OpenGL lines and points functions. It includes code to initialize the display window and drawing colors. Most of the code consists of drawing the different body parts of the robot using line segments, including the head, neck, body, hands, legs, eyes, and a line between the eyes. The main function sets up the window and calls the initialization and display functions to render the robot graphics.
Introduction to OpenGL programming for robot creation using line functions, covering initialization, drawing body parts (head, neck, body, limbs, eyes), and display setup.
Make Robot UsingLine Function In OpenGL
#include "stdafx.h"
// Run by Visual C++ 6 with OpenGL
#include <GL/glut.h>
void init (void)
{
/* select clearing (background) color */
glClearColor (0.0, 0.0, 0.0, 0.0);
// (red, green, blue, alpha), used by glClear
/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
// (left, right, bottom, top, near, far)
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
2.
//head
glColor3f (1.0, 1.0,1.0);
glBegin(GL_LINES); // Center is at the mid of main window due to glOrtho()
glVertex2f (0.33, 0.75);
glVertex2f (0.18, 0.75);
glVertex2f (0.18, 0.55);
glVertex2f (0.33, 0.55);
glVertex2f (0.18, 0.75);
glVertex2f (0.18, 0.55);
glVertex2f (0.33, 0.75);
glVertex2f (0.33, 0.55);
glEnd();
//neck
glColor3f (1.0, 1.0, 1.0);
3.
glBegin(GL_LINES); // Centeris at the mid of main window due to glOrtho()
glVertex2f (0.28, 0.55);
glVertex2f (0.23, 0.55);
glVertex2f (0.23, 0.40);
glVertex2f (0.28, 0.40);
glVertex2f (0.23, 0.55);
glVertex2f (0.23, 0.40);
glVertex2f (0.28, 0.55);
glVertex2f (0.28, 0.40);
glEnd();
//body
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_LINES); // Center is at the mid of main window due to glOrtho()
glVertex2f (0.40, 0.40);
glVertex2f (0.10, 0.40);
glVertex2f (0.10, -0.10);
glVertex2f (0.40, -0.10);
4.
glVertex2f (0.10, 0.40);
glVertex2f(0.10, -0.10);
glVertex2f (0.40, 0.40);
glVertex2f (0.40, -0.10);
glEnd();
//right hand
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_LINES); // Center is at the mid of main window due to glOrtho()
glVertex2f (0.48, 0.20);
glVertex2f (0.40, 0.40);
glVertex2f (0.40, 0.28);
glVertex2f (0.48, 0.10);
glVertex2f (0.48, 0.20);
glVertex2f (0.48, 0.10);
glEnd();
5.
//left hand
glColor3f (1.0,1.0, 1.0);
glBegin(GL_LINES); // Center is at the mid of main window due to glOrtho()
glVertex2f (-0.00, 0.20);
glVertex2f (0.10, 0.40);
glVertex2f (0.10, 0.28);
glVertex2f (-0.00, 0.10);
glVertex2f (-0.00, 0.20);
glVertex2f (-0.00, 0.10);
glEnd();
//right leg
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_LINES); // Center is at the mid of main window due to glOrtho()
glVertex2f (0.40, -0.10);
glVertex2f (0.35, -0.10);
6.
glVertex2f (0.35, -0.40);
glVertex2f(0.40, -0.40);
glVertex2f (0.35, -0.10);
glVertex2f (0.35, -0.40);
glVertex2f (0.40, -0.10);
glVertex2f (0.40, -0.40);
glEnd();
//left leg
glColor3f (1.0, 1.0, 1.0);
glBegin(GL_LINES); // Center is at the mid of main window due to glOrtho()
glVertex2f (0.15, -0.10);
glVertex2f (0.10, -0.10);
glVertex2f (0.10, -0.40);
glVertex2f (0.15, -0.40);
7.
glVertex2f (0.10, -0.10);
glVertex2f(0.10, -0.40);
glVertex2f (0.15, -0.10);
glVertex2f (0.15, -0.40);
glEnd();
//right eye
glColor3f (0.0, 1.0, 1.0);
glBegin(GL_POINTS); // Center is at the mid of main window due to glOrtho()
glVertex2f (0.29, 0.67);
glEnd();
//left eye
glColor3f (0.0, 1.0, 1.0);
glBegin(GL_POINTS); // Center is at the mid of main window due to glOrtho()
glVertex2f (0.23, 0.67);
glEnd();
8.
//line
glColor3f (1.0, 1.0,1.0);
glBegin(GL_LINES); // Center is at the mid of main window due to glOrtho()
glVertex2f (0.29, 0.61);
glVertex2f (0.23, 0.61);
glEnd();
glFlush ();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize (600, 500);
glutInitWindowPosition (200, 100);
// Screen origin (0,0) is at Top Left
glutCreateWindow ("Hello Computer Graphics Students");
init();// calling init()
glutDisplayFunc(display); // glut call back function, calling display()
glutMainLoop();
return 0; // ANSI C requires main to return int.
}