martes, 25 de abril de 2017

Humanoide

Captura:


Código:
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

int angx = 0, angy = 0; // Con estas se esta rotando sobre el eje x y sobre el eje y
GLUquadricObj *quadric;

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Aqui solo se le limpia el buffer de pixeles, ahora tambien se debe de hacer el buffer de profundidad que es siguiente

    glColor3f( 0, 1, 0);
    glPushMatrix();
        glTranslatef( 0, 0.5, -4);
        glRotatef( angx, 1, 0, 0);
        glRotatef( angy, 0, 1, 0);

        // Cabeza
        glPushMatrix();
            glTranslatef( 0, 2.1, 0);
            glScalef( 1, 1.2, 1 );
            glutSolidSphere( 0.6, 28, 28 );
        glPopMatrix();

        // Cuerpo
        glPushMatrix();
            glTranslatef( 0, 0.2, 0);
            glScalef( 1.2, 2.3, 0.8 );
            glutSolidSphere( 0.6, 28, 28 );
        glPopMatrix();

        // Hombro derecho
        glPushMatrix();
            glTranslatef( 0.55, 1.2, 0);
            glutSolidSphere( 0.21, 28, 28 );
        glPopMatrix();

        // Brazo derecho, vista usuario
        glPushMatrix();
            glTranslatef( 0.75, 0.73, 0);
            glRotatef( -75, 0, 0, 1 );
            glScalef( 4, 0.7, 0.7 );
            glutSolidCube( 0.28 );
        glPopMatrix();

        // Union con antebrazo derecho
        glPushMatrix();
            glTranslatef( 0.86, 0.32, 0);
            glutSolidSphere( 0.21, 28, 28 );
        glPopMatrix();

        // Antebrazo derecho
        glPushMatrix();
            glTranslatef( 0.86, 0.0, 0);
            glScalef( 0.65, 2.8, 0.65 );
            glutSolidCube( 0.28 );
        glPopMatrix();

        // Mano derecha
        glPushMatrix();
            glTranslatef( 0.86, -0.38, 0);
            glScalef( 1, 2, 1 );
            glutSolidSphere( 0.15, 28, 28 );
        glPopMatrix();

        // Hombro izquierdo ///////////////////////////
        glPushMatrix();
            glTranslatef( -0.55, 1.2, 0);
            glutSolidSphere( 0.21, 28, 28 );
        glPopMatrix();

        // Brazo izquierdo, vista usuario
        glPushMatrix();
            glTranslatef( -0.75, 0.73, 0);
            glRotatef( 75, 0, 0, 1 );
            glScalef( 4, 0.7, 0.7 );
            glutSolidCube( 0.28 );
        glPopMatrix();

        // Union con antebrazo izquierdo
        glPushMatrix();
            glTranslatef( -0.86, 0.32, 0);
            glutSolidSphere( 0.21, 28, 28 );
        glPopMatrix();

        // Antebrazo izquierdo
        glPushMatrix();
            glTranslatef( -0.86, 0.0, 0);
            glScalef( 0.65, 2.8, 0.65 );
            glutSolidCube( 0.28 );
        glPopMatrix();

        // Mano izquierda
        glPushMatrix();
            glTranslatef( -0.86, -0.38, 0);
            glScalef( 1, 2, 1 );
            glutSolidSphere( 0.15, 28, 28 );
        glPopMatrix();

        // Pierna izquierda /////////////////////////////
        glPushMatrix();
            glTranslatef( -0.45, -1, 0);
            glutSolidSphere( 0.26, 28, 28 );
        glPopMatrix();

        // Muslo izquierdo
        glPushMatrix();
            glTranslatef( -0.56, -1.6, 0);
            glRotatef( -6, 0, 0, 1);
            glScalef( 0.9, 3.2, 0.9);
            glutSolidCube( 0.32 );
        glPopMatrix();

        // Rodilla
        glPushMatrix();
            glTranslatef( -0.62, -2.2, 0);
            glutSolidSphere( 0.23, 28, 28 );
        glPopMatrix();

        // Pantorrilla izquierda
        glPushMatrix();
            glTranslatef( -0.62, -2.6, 0);
            glScalef( 0.9, 3, 0.9);
            glutSolidCube( 0.32 );
        glPopMatrix();

        // Pie izquierdo
        glPushMatrix();
            glTranslatef( -0.62, -3.35, 0);
            glRotatef( 90, 0, 1, 0 );
            glRotatef( -90, 1, 0, 0 );
            glutSolidCone( 0.32, 0.6, 28, 28 );
        glPopMatrix();


        // Pierna derecha /////////////////////////////
        glPushMatrix();
            glTranslatef( 0.45, -1, 0);
            glutSolidSphere( 0.26, 28, 28 );
        glPopMatrix();

        // Muslo derecho
        glPushMatrix();
            glTranslatef( 0.56, -1.6, 0);
            glRotatef( 6, 0, 0, 1);
            glScalef( 0.9, 3.2, 0.9);
            glutSolidCube( 0.32 );
        glPopMatrix();

        // Rodilla derecha
        glPushMatrix();
            glTranslatef( 0.62, -2.2, 0);
            glutSolidSphere( 0.23, 28, 28 );
        glPopMatrix();

        // Pantorrilla derecha
        glPushMatrix();
            glTranslatef( 0.62, -2.6, 0);
            glScalef( 0.9, 3, 0.9);
            glutSolidCube( 0.32 );
        glPopMatrix();

        // Pie derecho
        glPushMatrix();
            glTranslatef( 0.62, -3.35, 0);
            glRotatef( 90, 0, 1, 0 );
            glRotatef( -90, 1, 0, 0 );
            glutSolidCone( 0.32, 0.6, 28, 28 );
        glPopMatrix();

    glPopMatrix();
    glFlush();
}

void setOrtho( void )
{
    glOrtho( -2, 2, -4, 4, -2, 100);
}

void proy( unsigned char key, int x, int y)
{
    glMatrixMode(GL_PROJECTION); // Se apila una proyección, indica que se va a tener un tipo de proyección y abajo se indica en el caso p y o
    glLoadIdentity();

    switch (key){
        case 27:
            exit(0);
        case 'p':
            gluPerspective( 90, 0.5, 0.1, 100); // zNear es como desde donde se coloca la camara o mira de la persona, mientras que zFar es hasta donde verá y por tanto cuantos objetos se veran
            break;
        case 'o':
            setOrtho();
            break;
    }

    /* 2.- Se agrega una matriz para la presentacion de un modelo */
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glutPostRedisplay();
}


void girar(int key, int x, int y)
{
    switch(key){
        case GLUT_KEY_UP:
            angx=angx+3;
            break;
        case GLUT_KEY_DOWN:
            angx=angx-3;
            break;
        case GLUT_KEY_LEFT:
            angy=angy+3;
            break;
        case GLUT_KEY_RIGHT:
            angy=angy-3;
            break;
    }

    glutPostRedisplay();
}


int main(int argc, char **argv)
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH|GLUT_STENCIL);
    glutInitWindowSize( 400, 800);
    glutInitWindowPosition( 10, 10);
    glutCreateWindow ("Humanoide");

    /* 1.- La luz default es una luz direccional desde la camara */
    glEnable(GL_DEPTH_TEST); // Habilita un test de profundidad
    glEnable(GL_LIGHTING); // Habilitar iluminacion
    glEnable(GL_LIGHT0);

    glutDisplayFunc(display);
    glutKeyboardFunc(proy);
    glutSpecialFunc(girar);
    glutMainLoop();
    return 0;
}

martes, 14 de marzo de 2017

1er Avance Proyecto


Código para el escenario:
#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define PI 3.1415926535897932384626433832795

// colores R, G y B para el fondo de la ventana, de 0.0 a 255.0
#define CR_VENTANA 0
#define CG_VENTANA 0
#define CB_VENTANA 0
#define ANCHOAREA 500 // ancho para la ventana
#define ALTOAREA 530 // alto para la ventana
// color R, G y B para el fondo de la ventana de 0.0 a 255.0
#define CR_LINEAS 97
#define CG_LINEAS 98
#define CB_LINEAS 255

/** Descripcion: Proyecto 2D - Pac-Man con funciones reducidas
 *
 * Autores:
 *  Karina Miranda Ramirez
 *  Abigail Romero Gil
 *  Edgar Villa Miguel.
 * Fecha de creacion: 09/03/17
 * Revisiones: ---
 *  programa.
 * Fecha de ultima actualizacion: 14/03/17
 */

float dx,dy;

/**
 * Traza circulos acorde a los parámetros recibidos
 * @param cx Coordenada x donde se ubicará el centro del circulo
 * @param cy Coordenada y donde se ubicará el centro del circulo
 * @param radio Medida que tendrá de radio el circulor
 * @param r Color rojo de un RGB de 0.0 a 1.0
 * @param g Color verde de un RGB de 0.0 a 1.0lor
 * @param b Color azul de un RGB de 0.0 a 1.0
 * @param a1 Inicio del trazo del circulo en radianes
 * @param a2 Fin del trazo del circulo en radianes
 */
void circulo( float cx, float cy, float radio, float r,
    float g, float b, float a1, float a2 )
{
    // glEnable( GL_LINE_SMOOTH );
    glBegin( GL_POLYGON );
    glColor3f(r,g,b);
    glVertex2f(cx,cy);
    for( float i = a1; i<= a2; i+=0.01 )
    {
        dx = radio*cos(i) + cx;
        dy= radio*sin(i) + cy;
        glVertex2f(dx,dy);
    }
    glEnd();
}


void key(unsigned char c, int x, int y)
{
    int siAvanzo = 0; // verifica si se puede avanzar la G para entonces cambiar de color a G

    if ( c == 27 )
        exit(0);

    // mueve G una posición a la izquierda al presionar 'a' o 'A'
    if ( (c == 'a' || c == 'A') )
    {
//        // se mueve pacman
    }
    // mueva G una posición a la derecha al presionar 'd' o 'D'
    if ( (c =='d' || c == 'D') )
    {
        // se mueve pacman
    }

    // mueve G una posición hacia abajo al presionar 's' o'S'
    if ( (c =='s' || c == 'S') )
    {
        // se mueve pacman
    }
    // mueve G una posición hacia arriba al presionar 'w' o 'W'
    if ( (c =='w' || c == 'W') )
    {
        // se mueve pacman
    }

    glutPostRedisplay();
}

void glVertex2fp( double coordenadaX, double coordenadaY )
{
 glVertex2f( coordenadaX, (ALTOAREA) - coordenadaY );
}

void pacman(float a,float b){
    circulo( 12.5, 12.5, 12.5, 0.0, 0.0, 0.0, 0,6.3);
    circulo( 12.5, 12.5, 12.5, 1.0, 1.0, 0,  a,b);
}

void display(void){
    glClear( GL_COLOR_BUFFER_BIT ); // limpia, libera el buffer

    glLineWidth(3);

    glColor3f( CR_LINEAS/255.0, CG_LINEAS/255.0, CB_LINEAS/255.0 ); // establece el color

    /** ****************************************************************** */
    glBegin( GL_LINE_STRIP ); // establece el modo de trazo
    // limite superior
    glVertex2f( 3, 212 );
    glVertex2f( 94, 212 );
    glVertex2f( 98, 208 );
    glVertex2f( 98, 155 );
    glVertex2f( 93, 151 );
    glVertex2f( 8, 151 );
    glVertex2f( 8, 8 );
    glVertex2f( 236, 8 );
    glVertex2f( 239, 11 );
    glVertex2f( 239, 66 );
    glVertex2f( 243, 70 );
    glVertex2f( 256, 70 );
    glVertex2f( 260, 66 );
    glVertex2f( 260, 12 );
    glVertex2f( 263, 8 );
    glVertex2f( 491, 8 );
    glVertex2f( 491, 151 );
    glVertex2f( 405, 151 );
    glVertex2f( 401, 156 );
    glVertex2f( 401, 208 );
    glVertex2f( 405, 212 );
    glVertex2f( 496, 212 );
    glEnd();
    /** ****************************************************************** */

    /** ------------------------------------------------------------------ */
    // rectangulos superiores de izquierda a derecha
    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 46, 71 );
    glVertex2f( 94, 71 );
    glVertex2f( 98, 66 );
    glVertex2f( 98, 46 );
    glVertex2f( 93, 41 );
    glVertex2f( 46, 41 );
    glVertex2f( 41, 45 );
    glVertex2f( 41, 66 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 135, 71 );
    glVertex2f( 202, 71 );
    glVertex2f( 206, 66 );
    glVertex2f( 206, 46 );
    glVertex2f( 202, 41 );
    glVertex2f( 135, 41 );
    glVertex2f( 132, 45 );
    glVertex2f( 132, 66 );
    glEnd();

    glBegin( GL_LINE_LOOP );// establece el modo de trazo
    glVertex2f( 298, 71 );
    glVertex2f( 363, 71 );
    glVertex2f( 367, 66 );
    glVertex2f( 367, 46 );
    glVertex2f( 363, 41 );
    glVertex2f( 298, 41 );
    glVertex2f( 294, 45 );
    glVertex2f( 294, 66 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 405, 71 );
    glVertex2f( 453, 71 );
    glVertex2f( 458, 66 );
    glVertex2f( 458, 46 );
    glVertex2f( 453, 41 );
    glVertex2f( 406, 41 );
    glVertex2f( 401, 45 );
    glVertex2f( 401, 66 );
    glEnd();

    // Rectangulos pequeños
    /** +++++++++++++++++++++++++++++++++++++++++++++++++++ */
    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 46, 117 );
    glVertex2f( 94, 117 );
    glVertex2f( 98, 115 );
    glVertex2f( 98, 108 );
    glVertex2f( 93, 104 );
    glVertex2f( 46, 104 );
    glVertex2f( 41, 109 );
    glVertex2f( 41, 113 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 405, 117 );
    glVertex2f( 453, 117 );
    glVertex2f( 458, 115 );
    glVertex2f( 458, 108 );
    glVertex2f( 453, 104 );
    glVertex2f( 406, 104 );
    glVertex2f( 401, 109 );
    glVertex2f( 401, 113 );
    glEnd();
    /** +++++++++++++++++++++++++++++++++++++++++++++++++++ */

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 135, 212 );
    glVertex2f( 148, 212 );
    glVertex2f( 152, 208 );
    glVertex2f( 152, 169 );
    glVertex2f( 156, 165 );
    glVertex2f( 202, 165 );
    glVertex2f( 205, 161 );
    glVertex2f( 205, 155 );
    glVertex2f( 202, 151 );
    glVertex2f( 156, 151 );
    glVertex2f( 152, 148 );
    glVertex2f( 152, 108 );
    glVertex2f( 148, 104 );
    glVertex2f( 135, 104 );
    glVertex2f( 131, 108 );
    glVertex2f( 131, 208 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 243, 165 );
    glVertex2f( 256, 165 );
    glVertex2f( 259, 161 );
    glVertex2f( 259, 121 );
    glVertex2f( 263, 118 );
    glVertex2f( 310, 118 );
    glVertex2f( 313, 113 );
    glVertex2f( 313, 108 );
    glVertex2f( 310, 105 );
    glVertex2f( 189, 105 );
    glVertex2f( 185, 108 );
    glVertex2f( 185, 114 );
    glVertex2f( 189, 118 );
    glVertex2f( 234, 118 );
    glVertex2f( 239, 121 );
    glVertex2f( 239, 161 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 350, 212 );
    glVertex2f( 363, 212 );
    glVertex2f( 367, 208 );

    glVertex2f( 367, 108 );
    glVertex2f( 363, 104 );
    glVertex2f( 351, 104 );
    glVertex2f( 347, 108 );
    glVertex2f( 347, 148 );
    glVertex2f( 343, 151 );
    glVertex2f( 297, 151 );
    glVertex2f( 293, 155 );
    glVertex2f( 293, 161 );
    glVertex2f( 297, 165 );
    glVertex2f( 343, 165 );
    glVertex2f( 347, 169 );
    glVertex2f( 347, 208 );
    glEnd();


    /** ------------------------------------------------------------------ */

    // cuadro central
    /** $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */
    glLineWidth(5);
    glBegin( GL_LINE_STRIP ); // establece el modo de trazo
    glVertex2f( 233, 202 );
    glVertex2f( 188, 202 );
    glVertex2f( 188, 256 );
    glVertex2f( 310, 256 );
    glVertex2f( 310, 202 );
    glVertex2f( 268, 202 );
    glEnd();

    glColor3f( 255/255.0, 184/255.0, 255/255.0 ); // establece el color
    glLineWidth(2);
    glBegin( GL_LINES ); // establece el modo de trazo
    glVertex2f( 233, 201 );
    glVertex2f( 268, 201 );
    glEnd();
    /** $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ */

 
 // figuras inferiores
 glColor3f( CR_LINEAS/255.0, CG_LINEAS/255.0, CB_LINEAS/255.0 ); // establece el color
    glLineWidth(3);
    /** ****************************************************************** */
    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 135, 306 );
    glVertex2f( 148, 306 );
    glVertex2f( 151, 303 );
    glVertex2f( 151, 250 );
    glVertex2f( 148, 245 );
    glVertex2f( 135, 245 );
    glVertex2f( 131, 250 );
    glVertex2f( 131, 303 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 351, 306 );
    glVertex2f( 363, 306 );
    glVertex2f( 368, 303 );
    glVertex2f( 368, 250 );
    glVertex2f( 363, 245 );
    glVertex2f( 351, 245 );
    glVertex2f( 348, 250 );
    glVertex2f( 348, 303 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 135, 354 );
    glVertex2f( 201, 354 );
    glVertex2f( 206, 350 );
    glVertex2f( 206, 344 );
    glVertex2f( 202, 340 );
    glVertex2f( 136, 340 );
    glVertex2f( 132, 344 );
    glVertex2f( 132, 350 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 297, 354 );
    glVertex2f( 363, 354 );
    glVertex2f( 367, 350 );
    glVertex2f( 367, 344 );
    glVertex2f( 363, 340 );
    glVertex2f( 297, 340 );
    glVertex2f( 293, 344 );
    glVertex2f( 293, 350 );
    glEnd();


    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 243, 354 );
    glVertex2f( 256, 354 );
    glVertex2f( 259, 350 );
    glVertex2f( 259, 310 );
    glVertex2f( 263, 306 );
    glVertex2f( 310, 306 );
    glVertex2f( 313, 303 );
    glVertex2f( 313, 297 );
    glVertex2f( 310, 293 );
    glVertex2f( 189, 293 );
    glVertex2f( 185, 297 );
    glVertex2f( 185, 303 );
    glVertex2f( 189, 306 );
    glVertex2f( 234, 306 );
    glVertex2f( 239, 310 );
    glVertex2f( 239, 350 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 243, 448 );
    glVertex2f( 256, 448 );
    glVertex2f( 259, 444 );
    glVertex2f( 259, 405 );
    glVertex2f( 263, 400 );
    glVertex2f( 310, 400 );
    glVertex2f( 313, 397 );
    glVertex2f( 313, 391 );
    glVertex2f( 310, 387 );
    glVertex2f( 189, 387 );
    glVertex2f( 185, 391 );
    glVertex2f( 185, 397 );
    glVertex2f( 189, 400 );
    glVertex2f( 234, 400 );
    glVertex2f( 239, 405 );
    glVertex2f( 239, 444 );
    glEnd();


    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 81, 401 );
    glVertex2f( 93, 401 );
    glVertex2f( 98, 396 );
    glVertex2f( 98, 344 );
    glVertex2f( 93, 340 );
    glVertex2f( 46, 340 );
    glVertex2f( 42, 344 );
    glVertex2f( 42, 350 );
    glVertex2f( 46, 354 );
    glVertex2f( 74, 354 );
    glVertex2f( 78, 358 );
    glVertex2f( 78, 396 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 405, 401 );
    glVertex2f( 418, 401 );
    glVertex2f( 421, 396 );
    glVertex2f( 421, 358 );
    glVertex2f( 425, 354 );
    glVertex2f( 453, 354 );
    glVertex2f( 457, 349 );
    glVertex2f( 457, 344 );
    glVertex2f( 452, 340 );
    glVertex2f( 405, 340 );
    glVertex2f( 401, 345 );
    glVertex2f( 401, 396 );
    glEnd();



    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 46, 448 );
    glVertex2f( 202, 448 );
    glVertex2f( 206, 444 );
    glVertex2f( 206, 438 );
    glVertex2f( 202, 435 );
    glVertex2f( 156, 435 );
    glVertex2f( 152, 430 );
    glVertex2f( 152, 392 );
    glVertex2f( 148, 388 );
    glVertex2f( 135, 388 );
    glVertex2f( 132, 392 );
    glVertex2f( 132, 430 );
    glVertex2f( 127, 435 );
    glVertex2f( 46, 435 );
    glVertex2f( 42, 439 );
    glVertex2f( 42, 445 );
    glEnd();

    glBegin( GL_LINE_LOOP ); // establece el modo de trazo
    glVertex2f( 297, 448 );
    glVertex2f( 453, 448 );
    glVertex2f( 457, 444 );
    glVertex2f( 457, 438 );
    glVertex2f( 453, 435 );
    glVertex2f( 371, 435 );
    glVertex2f( 367, 430 );
    glVertex2f( 367, 392 );
    glVertex2f( 363, 388 );
    glVertex2f( 351, 388 );
    glVertex2f( 347, 392 );
    glVertex2f( 347, 430 );
    glVertex2f( 343, 435 );
    glVertex2f( 297, 435 );
    glVertex2f( 293, 439 );
    glVertex2f( 293, 445 );
    glEnd();

    /** ****************************************************************** */


    /** ------------------------------------------------------------------ */
    glBegin( GL_LINE_STRIP ); // establece el modo de trazo
    // limite inferior
    glVertex2f( 3, 246 );
    glVertex2f( 94, 246 );
    glVertex2f( 98, 251 );
    glVertex2f( 98, 303 );
    glVertex2f( 93, 307 );
    glVertex2f( 8, 307 );
    glVertex2f( 8, 383 );
    glVertex2f( 12, 387 );
    glVertex2f( 40, 387 );
    glVertex2f( 44, 391 );
    glVertex2f( 44, 396 );
    glVertex2f( 40, 401 );
    glVertex2f( 12, 401 );
    glVertex2f( 8, 405 );
    glVertex2f( 8, 482 );
    glVertex2f( 491, 482 );
    glVertex2f( 491, 405 );
    glVertex2f( 488, 401 );
    glVertex2f( 460, 401 );
    glVertex2f( 455, 398 );
    glVertex2f( 455, 391 );
    glVertex2f( 459, 387 );
    glVertex2f( 488, 387 );
    glVertex2f( 490, 383 );
    glVertex2f( 490, 306 );
    glVertex2f( 406, 306 );
    glVertex2f( 401, 303 );
    glVertex2f( 401, 250 );
    glVertex2f( 406, 245 );
    glVertex2f( 496, 245 );
    glEnd();
    /** ------------------------------------------------------------------ */

    glFlush(); // libera memoria

    glFlush(); // libera memoria
}

void relacionDeAspecto(int ancho, int alto)
{

    float aspectratio;
    aspectratio = 1;
    if (1>(ancho/alto))
    {
    // glViewport recibe 4 parametros, uno el origen en x, y y otro el ancho y otro el alto
        glViewport(0, 0, ancho,  ancho/aspectratio);
    }
    else
    {
        glViewport(0, 0, alto*aspectratio,alto);
    }

}

int main(int argc, char** argv){
    glutInit(&argc, argv); // Inicializa la libreria GLUT
    // glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
    glutInitWindowSize( ANCHOAREA, ALTOAREA - 30 ); // Inicializa el tamaño de la ventana
    glutInitWindowPosition(10,50); // posicion de la ventana
    glutCreateWindow("PAC-MAN"); // crea la ventana

    glClearColor( CR_VENTANA/255.0, CG_VENTANA/255.0, CB_VENTANA/255.0, 0); // establece el color de fondo de la ventana
    gluOrtho2D( 0, ANCHOAREA, ALTOAREA, 0  );

    glutDisplayFunc(display);

    glutReshapeFunc(relacionDeAspecto); // permite redimensionar la ventana de manera apropiada
    glutKeyboardFunc(key);
    glutMainLoop();
    return 0;
}





Código para los fantasmas y pac-man:


#include <windows.h>
#include <C:\GLUT\include\GL\glut.h>
#include <stdlib.h>
#include <math.h>


float dx,dy;//variables del circulo
float x,y,z; //colores de los fantasmas
float a,b; //boca del pacman

void circulo( float cx, float cy, float radio, float r,
    float g, float b, float a1, float a2 )
{
    // glEnable( GL_LINE_SMOOTH );
    glBegin( GL_POLYGON );
    glColor3f(r,g,b);
    glVertex2f(cx,cy);
    for( float i = a1; i<= a2; i += 0.01 )
    {
        dx = radio*cos(i) + cx;
        dy= radio*sin(i) + cy;
        glVertex2f(dx,dy);
    }
    glEnd();
}

void fantasma (float x,float y,float z){
    glClear( GL_COLOR_BUFFER_BIT );
     //cabeza del fantasma
    circulo( 12.5, 12.5, 12.5, x, y, z,  3.14159,6.28319);//fantasma rojo

    //rectangulo del fantasma
    glBegin( GL_POLYGON );
    glColor3f(x,y,z);
    glVertex2i(0,11);
    glVertex2i(25,11);
    glVertex2i(25,21);
    glVertex2i(0,21);
    glEnd();

    //puntas del fantasma

    //PUNTA 1
    glBegin( GL_POLYGON );
    glColor3f(x,y,z);
    glVertex2i(0,21);
    glVertex2i(8,21);
    glVertex2i(7,25);
    glVertex2i(1,25);
    glEnd();
    //PUNTA 2
    glBegin( GL_POLYGON );
    glColor3f(x,y,z);
    glVertex2i(8,21);
    glVertex2i(17,21);
    glVertex2i(16,25);
    glVertex2i(9,25);
    glEnd();

    //PUNTA 3
    glBegin( GL_POLYGON );
    glColor3f(x,y,z);
    glVertex2i(17,21);
    glVertex2i(25,21);
    glVertex2i(24,25);
    glVertex2i(19,25);
    glEnd();

    //Ojos del fantasma blanco
    circulo( 6, 10, 4, 1.0, 1.0, 1.0,  0,6.28319);
    circulo( 17, 10, 4, 1.0, 1.0, 1.0, 0,6.28319);
    //ojos del fantasma negro
    circulo( 6, 8, 2, 0.0, 0.0, 0.0,  0,6.28319);
    circulo( 17, 8, 2, 0.0, 0.0, 0.0, 0,6.28319);
    glFlush();
}

void pacman(float a,float b){
    circulo( 12.5, 12.5, 12.5, 0.0, 0.0, 0.0, 0,6.3);
    circulo( 12.5, 12.5, 12.5, 1.0, 1.0, 0,  a,b);
}

void display(void){
    glClear( GL_COLOR_BUFFER_BIT );
    fantasma(1.0,0.0,1.0);
    // pacman(0,5.4);
    glFlush();
}

int main(int argc, char** argv){
    glutInit(&argc, argv);
    glutInitWindowSize(510,540);
    glutInitWindowPosition(10,50);
    glutCreateWindow("PACMAN");
    glClearColor( 0.0, 0.0, 0.0, 0);
    gluOrtho2D( 0, 30, 30, 0);
    glutDisplayFunc(display);
    glutMainLoop();

    return 0;
}