TEAPOTS | Diana Vargas

#include <windows.h>

#include <GL/glut.h>

float ang=0.1, rotar=0, rotar1=0, rotar2=0;

void iluminacion (int encendido){

    if(encendido==1){
        const GLfloat pos[4]={10, 10, 10};//poner afuera

        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);

        glLightfv(GL_LIGHT0, GL_POSITION, pos);

    }
    else{
        glDisable(GL_LIGHTING);
    }
}

void aplicarMaterial(int encendido){

    if(encendido==1) {
        GLfloat mat_red_ambient[] = {0.1745f, 0.01175f, 0.01175f, 0.55f};
        GLfloat mat_red_diffuse[] = {0.61424f, 0.04136f, 0.04136f, 0.55f};
        GLfloat mat_specular[] = {0.727811f, 0.626959f, 0.626959f, 0.55f};
        //GLfloat mat_emission[] = { 0.0,0.2,0.0,0};
        //float shine =76.8f ;
        GLfloat mat_shininess[] = {10};//Valor bajo refleja más luz, valor alto es más opaco

        glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
        glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
        glMaterialfv(GL_FRONT, GL_AMBIENT, mat_red_ambient);
        glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_red_diffuse);
        //glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);
    }
}


void transparencia (int encendido){

    if(encendido==1){
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glDisable(GL_DEPTH_TEST);
    }
    else{
        glDisable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
    }

}


void idle(void){

    glutPostRedisplay();

}

void animar(void){
    rotar = rotar + 0.1;
    rotar1 = rotar1 + 0.2;
    rotar2 = rotar2 - 0.2;
    glutPostRedisplay();
}

void display(void){

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    glRotatef(rotar,0,1,0);
    aplicarMaterial(1);
    iluminacion(1);
    transparencia(1);
    glutSolidTeapot(2);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(5,5,0);
    glRotatef(rotar1,1,1,1);
    aplicarMaterial(1);
    iluminacion(1);
    transparencia(1);
    glutSolidTeapot(-1);
    glPopMatrix();

    glPushMatrix();
    glTranslatef(-5,-5,0);
    glRotatef(rotar2,1,1,1);
    aplicarMaterial(1);
    iluminacion(1);
    transparencia(1);
    glutSolidTeapot(1);
    glPopMatrix();

    glPushMatrix();
    glRotatef(rotar1,1,1,1);
    glTranslatef(-3,5,4);
    aplicarMaterial(1);
    iluminacion(1);
    transparencia(1);
    glutSolidTeapot(3);
    glPopMatrix();

    glPushMatrix();
    glRotatef(rotar1,1,1,1);
    glTranslatef(3,-5,4);
    aplicarMaterial(1);
    iluminacion(1);
    transparencia(1);
    glutSolidTeapot(1);
    glPopMatrix();

    glFlush();
    glutSwapBuffers();
}

void init(void){

    glMatrixMode(GL_PROJECTION);
    gluPerspective(55.0, 1.0, 2.0, 24.0);
    glMatrixMode(GL_MODELVIEW);
    glTranslatef(0.0, 0.0, -15.0);
    glEnable(GL_DEPTH_TEST);

}


int main(int argc, char **argv){

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE| GLUT_DEPTH );
    glutInitWindowSize(800, 800);
    glutCreateWindow("MUCHAS TEAPOTS | Diana Vargas");

    init();

    glutDisplayFunc(display);
    glutIdleFunc(animar);
    glutMainLoop();
    return 0;

}



Comentarios

Entradas populares de este blog

Código Capitán América Diana Vargas

Reflejo | Diana Vargas

Cámara | Israel González de la Peña