domingo, 30 de abril de 2017

Humanoide con materiales

Captura:


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

/** Descripcion: Humanoide con materiales
 *
 * Autores:
 *  Edgar Villa Miguel.
 * Fecha de creacion: 25/04/17
 * Revisiones: ---
 *  programa.
 * Fecha de ultima actualizacion: 30/04/17
 */

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

/* Prototipos de las funciones
    tipo-valor-retorno nombre-funcion ( lista-parametros )*/
void iluminacion (int encendido); // Establece el tipo de iluminación que se tendrá
void aplicarMaterialOro(int encendido); // Establece un material tipo oro para usarse
void aplicarMaterialLaton(int encendido); // Establece un material tipo latón para usarse
void display( void ); // Dibuja los elementos sobre la pantalla
void proy( unsigned char key, int x, int y); // Controla la interacción/respuesta entre el teclado y la ejecución del programa
void girar(int key, int x, int y); // Controla la interacción/respuesta entre el teclado y la ejecución del programa con teclas especiales


/**
 * Inicia la ejecución del programa
 */
int main(int argc, char **argv)
{
    glutInit(&argc, argv);

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

    /* 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);

    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();
    gluPerspective( 90, 0.5, 0.1, 100);

    glutDisplayFunc(display);
    glutKeyboardFunc(proy);
    glutSpecialFunc(girar);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glutMainLoop();
    return 0;
}

/**
 * Estable el tipo de iluminación a usar
 * @param encendido Para activar/desactivar la iluminación
 */
void iluminacion (int encendido)
{
    if( encendido == 1 )
    {
        const GLfloat pos[4] = { 10, 10, 10}; //poner afuera
        static GLfloat colorLuz[] = { 1, 1, 1, 1}; // El 1 es como iluminacion global, como el sol, si es 0 es como un foquito creo
        // Lo anterior es una luz blanca

        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glLightfv(GL_LIGHT0, GL_DIFFUSE, colorLuz); // La luz 0 va a ser difusa del color blanco, arriva
        glLightfv(GL_LIGHT0, GL_POSITION, pos);
    } else
    {
        glDisable(GL_LIGHTING);
    }
}

/**
 * Establece el tipo de material a usar, oro en este caso
 * @param encendido Para activar/desactivar el uso del material
 */
void aplicarMaterialOro(int encendido)
{
    if( encendido == 1 ) {
        GLfloat mat_green_ambient[] = { 0.24725,0.1995,0.0745,0.75};//ambiente y la ultima es alfa transaparencia
        GLfloat mat_green_diffuse[] = { 0.75164,0.60648,0.22648,0.75};//difuso
        GLfloat mat_specular[] = { 0.628281,0.555802,0.366065,0.5};//especular r,g,b y alfa
        GLfloat mat_shininess[] = { 0.4*128}; //128 mucho brillo y 0 poco brillo

        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); //se aplica solo en la cara frontal gl_front and back
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_green_ambient);
        glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_green_diffuse);
    }
}

/**
 * Establece el tipo de material a usar, latón en este caso
 * @param encendido Para activar/desactivar el uso del material
 */
void aplicarMaterialLaton(int encendido) //es color verde esmeralda
{
    if(encendido==1) {
            //estos primeros son los parametros
        GLfloat mat_green_ambient[] = { 0.329412, 0.223529, 0,027451, 0.75};//ambiente y la ultima es alfa transaparencia
        GLfloat mat_green_diffuse[] = { 0.780392, 0.568627, 0.113725, 0.75};//difuso
        GLfloat mat_specular[] = { 0.992157, 0.941176, 0.807843, 0.5};//especular r,g,b y alfa
        GLfloat mat_shininess[] = { 0.21794872*128}; //128 mucho brillo y 0 poco brillo

        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); //se aplica solo en la cara frontal gl_front and back
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_green_ambient);
        glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_green_diffuse);
    }
}

/**
 * Dibuja los elementos sobre la pantalla
 */
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);
    iluminacion(1);
    glPushMatrix();
        glTranslatef( 0, 0.5, -4);
        glRotatef( angx, 1, 0, 0);
        glRotatef( angy, 0, 1, 0);

        // Cabeza
        glPushMatrix();
            aplicarMaterialOro(1);
            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();
            aplicarMaterialLaton(1);
            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();
            aplicarMaterialOro(1);
            glTranslatef( 0.86, 0.32, 0);
            glutSolidSphere( 0.21, 28, 28 );
        glPopMatrix();

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

        // Mano derecha
        glPushMatrix();
            aplicarMaterialOro(1);
            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();
            aplicarMaterialLaton(1);
            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();
            aplicarMaterialOro(1);
            glTranslatef( -0.86, 0.32, 0);
            glutSolidSphere( 0.21, 28, 28 );
        glPopMatrix();

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

        // Mano izquierda
        glPushMatrix();
            aplicarMaterialOro(1);
            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();
            aplicarMaterialLaton(1);
            glTranslatef( -0.56, -1.6, 0);
            glRotatef( -6, 0, 0, 1);
            glScalef( 0.9, 3.2, 0.9);
            glutSolidCube( 0.32 );
        glPopMatrix();

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

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

        // Pie izquierdo
        glPushMatrix();
            aplicarMaterialOro(1);
            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();
            aplicarMaterialLaton(1);
            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();
            aplicarMaterialOro(1);
            glTranslatef( 0.62, -2.2, 0);
            glutSolidSphere( 0.23, 28, 28 );
        glPopMatrix();

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

        // Pie derecho
        glPushMatrix();
            aplicarMaterialOro(1);
            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();
}

/**
 * Controla la interacción/respuesta entre el teclado y la ejecución del programa
 * Parámetros necesarios y obligatorios
 * @param c Tecla que fue presionada del teclado, generada en código ASCII
 * @param x Coordenada x del mouse cuando fue presionada la tecla respectiva
 * @param y Coordenada y del mouse cuando fue presionada la tecla respectiva
 */
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':
            glOrtho( -2, 2, -4, 4, -2, 100);
            break;
    }

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

    glutPostRedisplay();
}

/**
 * Controla la interacción/respuesta entre el teclado y la ejecución del programa con teclas especiales
 * Parámetros necesarios y obligatorios
 * @param c Tecla que fue presionada del teclado, generada en código ASCII
 * @param x Coordenada x del mouse cuando fue presionada la tecla respectiva
 * @param y Coordenada y del mouse cuando fue presionada la tecla respectiva
 */
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();
}

martes, 25 de abril de 2017

Cronograma y Propuesta del Proyecto

PROPUESTA DE PROYECTO: RECORRIDO VIRTUAL DE UNA PARTE DE MÉXICO

CubeMap - Caja de texturas

Capturas:







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

int alto=256,ancho=256;//dim imagen
GLfloat angle = 0;
GLfloat angle2 = 0;
int moving, startx, starty;


unsigned char * textura1;
unsigned char * textura2;
unsigned char * textura3;
unsigned char * textura4;
unsigned char * textura5;
unsigned char * textura6;

int leerImagen1(){
    FILE *imagen;
    imagen = fopen("C:/Users/migue/Dropbox/8vo Semestre/Graficación/3D/MapCubeFig/cMap1.raw","r");
    textura1 = (unsigned char*)malloc( ancho*alto*3 );
    if( imagen == NULL ){
        printf("Error: No imagen");
        return 0;
    }
    fread( textura1, ancho*alto*3, 1, imagen);
    fclose(imagen);
    return 1;
}

int leerImagen2(){
    FILE *imagen;
    imagen = fopen("C:/Users/migue/Dropbox/8vo Semestre/Graficación/3D/MapCubeFig/cMap2.raw","r");
    textura2 = (unsigned char*)malloc( ancho*alto*3 );
    if( imagen == NULL ){
        printf("Error: No imagen");
        return 0;
    }
    fread( textura2, ancho*alto*3, 1, imagen);
    fclose(imagen);
    return 1;
}

int leerImagen3(){
    FILE *imagen;
    imagen = fopen("C:/Users/migue/Dropbox/8vo Semestre/Graficación/3D/MapCubeFig/cMap3.raw","r");
    textura3 = (unsigned char*)malloc( ancho*alto*3 );
    if( imagen == NULL ){
        printf("Error: No imagen");
        return 0;
    }
    fread( textura3, ancho*alto*3, 1, imagen);
    fclose(imagen);
    return 1;
}

int leerImagen4(){
    FILE *imagen;
    imagen = fopen("C:/Users/migue/Dropbox/8vo Semestre/Graficación/3D/MapCubeFig/cMap4.raw","r");
    textura4 = (unsigned char*)malloc( ancho*alto*3 );
    if( imagen == NULL ){
        printf("Error: No imagen");
        return 0;
    }
    fread( textura4, ancho*alto*3, 1, imagen);
    fclose(imagen);
    return 1;
}

int leerImagen5(){
    FILE *imagen;
    imagen = fopen("C:/Users/migue/Dropbox/8vo Semestre/Graficación/3D/MapCubeFig/cMap5.raw","r");
    textura5 = (unsigned char*)malloc( ancho*alto*3 );
    if( imagen == NULL ){
        printf("Error: No imagen");
        return 0;
    }
    fread( textura5, ancho*alto*3, 1, imagen);
    fclose(imagen);
    return 1;
}

int leerImagen6(){
    FILE *imagen;
    imagen = fopen("C:/Users/migue/Dropbox/8vo Semestre/Graficación/3D/MapCubeFig/cMap6.raw","r");
    textura6 = (unsigned char*)malloc( ancho*alto*3 );
    if( imagen == NULL ){
        printf("Error: No imagen");
        return 0;
    }
    fread( textura6, ancho*alto*3, 1, imagen);
    fclose(imagen);
    return 1;
}

void usarTextura1(void)
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ancho, alto, 0, GL_RGB, GL_UNSIGNED_BYTE, textura1);
}


void usarTextura2(void)
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ancho, alto, 0, GL_RGB, GL_UNSIGNED_BYTE, textura2);
}


void usarTextura3(void)
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ancho, alto, 0, GL_RGB, GL_UNSIGNED_BYTE, textura3);
}


void usarTextura4(void)
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ancho, alto, 0, GL_RGB, GL_UNSIGNED_BYTE, textura4);
}


void usarTexturaBase(void)
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ancho, alto, 0, GL_RGB, GL_UNSIGNED_BYTE, textura5);
}



void usarTexturaTapa(void)
{
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, ancho, alto, 0, GL_RGB, GL_UNSIGNED_BYTE, textura6);
}


// cubemap variables
int d1 = 10;
int d2 = 20;
static GLint verticesPiso[4][3] = {
    { -d1, 0,  -d1 },
    {  d1, 0,  -d1 },
    {  d1, 0, d1 },
    { -d1, 0, d1 },
};
static GLint pared1Vertices[4][3] = {
    { -d1,d2, d1},
    { -d1,0,  d1},
    {  d1,0,  d1},
    {  d1,d2, d1},
};
static GLint pared2Vertices[4][3] = {
    { d1,d2, d1},
    { d1,0,  d1},
    { d1,0, -d1},
    { d1,d2,-d1},
};
static GLint pared3Vertices[4][3] = {

    {  d1,d2,-d1 },
    { d1,0,-d1 },
    { -d1,0,-d1 },
    {  -d1,d2,-d1},
};
static GLint pared4Vertices[4][3] = {
    { -d1,d2,-d1},
    { -d1,0,-d1 },
    {  -d1,0,d1 },
    {  -d1,d2,d1},
};
static GLint techoVertices[4][3] = {
    { d1,d2,-d1},
    { -d1,d2,-d1 },
    {  -d1,d2,d1 },
    {  d1,d2,d1},
};


void dibujaBase(void)
{
    usarTexturaBase();
    glBegin(GL_QUADS);
    glTexCoord2f( 0.0, 0.0); // esta dibuja la textura sobre lo siguiente
    glVertex3iv(verticesPiso[0]);
    glTexCoord2f(0.0, 1);
    glVertex3iv(verticesPiso[1]);
    glTexCoord2f(1, 1);
    glVertex3iv(verticesPiso[2]);
    glTexCoord2f(1, 0.0);
    glVertex3iv(verticesPiso[3]);
    glEnd();
}
void dibujaPared1c(void)
{
    usarTextura1();
    glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0);
    glVertex3iv(pared1Vertices[0]);
    glTexCoord2f(0.0, 1.0);
    glVertex3iv(pared1Vertices[1]);
    glTexCoord2f(1.0, 1.0);
    glVertex3iv(pared1Vertices[2]);
    glTexCoord2f(1.0, 0.0);
    glVertex3iv(pared1Vertices[3]);
    glEnd();
}
void dibujaPared2c(void)
{
    usarTextura2();
    glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0);
    glVertex3iv(pared2Vertices[0]);
    glTexCoord2f(0.0, 1.0);
    glVertex3iv(pared2Vertices[1]);
    glTexCoord2f(1.0, 1.0);
    glVertex3iv(pared2Vertices[2]);
    glTexCoord2f(1.0, 0.0);
    glVertex3iv(pared2Vertices[3]);
    glEnd();
}

void dibujaPared3c(void)
{
    usarTextura3();
    glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0);
    glVertex3iv(pared3Vertices[0]);
    glTexCoord2f(0.0, 1.0);
    glVertex3iv(pared3Vertices[1]);
    glTexCoord2f(1.0, 1.0);
    glVertex3iv(pared3Vertices[2]);
    glTexCoord2f(1.0, 0.0);
    glVertex3iv(pared3Vertices[3]);
    glEnd();
}

void dibujaPared4c(void)
{
    usarTextura4();
    glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0);
    glVertex3iv(pared4Vertices[0]);
    glTexCoord2f(0.0, 1.0);
    glVertex3iv(pared4Vertices[1]);
    glTexCoord2f(1.0, 1.0);
    glVertex3iv(pared4Vertices[2]);
    glTexCoord2f(1.0, 0.0);
    glVertex3iv(pared4Vertices[3]);
    glEnd();
}

void dibujaTapac(void)
{
    usarTexturaTapa();
    glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0);
    glVertex3iv(techoVertices[0]);
    glTexCoord2f(0.0, 1.0);
    glVertex3iv(techoVertices[1]);
    glTexCoord2f(1.0, 1.0);
    glVertex3iv(techoVertices[2]);
    glTexCoord2f(1.0, 0.0);
    glVertex3iv(techoVertices[3]);
    glEnd();
}
//////////////////////////////////////////////////

void display(void)
{

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // El ultimo del buffer STENCIL

    glPushMatrix();
        glRotatef(angle2, 1.0, 0.0, 0.0); //move mouse
        glRotatef(angle, 0.0, 1.0, 0.0);

        glPushMatrix();
            glTranslatef(0,-10, 0); // El -10 es porque el cubo se hizo a patir desde la base
            dibujaBase();
            dibujaPared1c();
            dibujaPared2c();
            dibujaPared3c();
            dibujaPared4c();
            dibujaTapac();
        glPopMatrix();

    glPopMatrix();
glutSwapBuffers();
}

void mouse(int button, int state, int x, int y)
{
    if (button == GLUT_LEFT_BUTTON) {
        if (state == GLUT_DOWN) {
            moving = 1;
            startx = x;
            starty = y;
        }
        if (state == GLUT_UP) {
            moving = 0;
        }
    }
}

void mover(int x, int y)
{
    if (moving) {
        angle = angle + (x - startx);
        angle2 = angle2 + (y - starty);
        startx = x;
        starty = y;
        glutPostRedisplay();
    }
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL | GLUT_MULTISAMPLE);

    glutInitWindowSize( 480, 360);

    glutCreateWindow("CAJA TEXTURAS");

    leerImagen1();
    leerImagen2();
    leerImagen3();
    leerImagen4();
    leerImagen5();
    leerImagen6();

    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(mover);

    glEnable(GL_DEPTH_TEST);//////////HABILITAR
    glEnable(GL_TEXTURE_2D);

    gluPerspective(40.0,1.333,0.1,200.0); //16/10=1.6   5/4=1.25        1.333 porque la resolucion es de 640x480
    glMatrixMode(GL_MODELVIEW);

    /* El primero para posicionar la camara, el siguiente es para decir hacia donde ve la camara, el ultimo es para cambiar la posicion u orientacion de la camara  */
    gluLookAt(0.0, 0.0, 10.0,  /* camara en (0,20,60) */
              0,0,0,          /* mira a (x,y,z) */
              0, 1, 0);      /* altura en Y (0,1,0) o en x Y (1,0,0) */

    glutMainLoop();
    return 0;
}

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;
}