jueves, 18 de octubre de 2012

Práctica de luces y materiales.


// Practica5UII.cpp: archivo de proyecto principal.

#include "stdafx.h"
#include <glut.h>

void Inicializa();
void Dibuja();
int i;
void Anima();

float ambiental[4]={0, 0, 0, 1},
 difusa[4]={1, 1, 1, 1},
 especular[4]={1, 1, 1, 1},
 posicion[4]={5, 5, -5, 1};

void main(){
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800, 800);
glutInitWindowPosition(100, 50);
glutCreateWindow("Practica5U2 - Elena");
glutDisplayFunc(Dibuja);
Inicializa();
glutMainLoop();
}

void Inicializa(){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90, 1, 0.1, 40);
glMatrixMode(GL_MODELVIEW);
glClearColor(0, 0, 0, 0);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambiental);
glLightfv(GL_LIGHT0, GL_DIFFUSE, difusa);
glLightfv(GL_LIGHT0, GL_SPECULAR, especular);
glLightfv(GL_LIGHT0, GL_POSITION, posicion);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
//glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambiental);
glutIdleFunc(Anima);
}

void Anima(){
i++;
glutPostRedisplay();
}

void Dibuja(){
GLUquadricObj *ap;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ap = gluNewQuadric();
glLoadIdentity();
glTranslated(0, 0, -10);
glPushMatrix();
glTranslated(-6, 6, 0);
gluQuadricDrawStyle(ap, GLU_FILL);
gluQuadricNormals(ap, GLU_SMOOTH);
gluQuadricOrientation(ap, GLU_OUTSIDE);
//Esfera Verde
ambiental[0]=0.5;
ambiental[1]=1;
especular[0]=1;
especular[1]=1;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 30);
gluSphere(ap, 2, 30, 30);
//Cilindro
glPopMatrix();
glPushMatrix();
glTranslated(-1.5, 7, 0);
glRotated(60, 1, 0, 0);
ambiental[0]=1;
ambiental[2]=1;
especular[0]=0;
especular[1]=0;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 5);
gluCylinder(ap, 1, 1, 3.5, 20, 20);
//Disco
glPopMatrix();
glPushMatrix();
glTranslated(2.5, 6.5, 0);
glRotated(60, 0, 1, 1);
ambiental[2]=0;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
gluDisk(ap, 0.5, 2.5, 30, 10);
//Disco Parcial
glPopMatrix();
glPushMatrix();
glTranslated(6.5, 6.5, 0);
glRotated(50, 1, 0, 0);
ambiental[1]=0;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
gluPartialDisk(ap, 0.5, 2.5, 30, 10, 40, 180);
gluDeleteQuadric(ap);
//Cono
glPopMatrix();
glPushMatrix();
glTranslated(-6, 0, 0);
ambiental[1]=0.5;
especular[1]=1;
especular[2]=0;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 10);
glutSolidCone(2, 4, 10, 20);
//Cubo
glPopMatrix();
glPushMatrix();
glTranslated(-1.8, 0, 0);
glRotated(30, 1, 1, 0);
ambiental[0]=0;
ambiental[1]=0.5;
especular[1]=0;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 10);
glutSolidCube(3);
//Tetrahedro
glPopMatrix();
glPushMatrix();
glTranslated(2.5, 0, 0);
glRotated(10, 0, 1, 1);
glScaled(2.5, 2.5, 2.5);
ambiental[0]=0.5;
ambiental[1]=0.6;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 1);
glutSolidTetrahedron();
//Octahedro
glPopMatrix();
glPushMatrix();
glTranslated(6.5, 0, 0);
glRotated(50, 1, 1, 1);
glScaled(2.5, 2.5, 2.5);
ambiental[1]=0;
ambiental[2]=1;
especular[1]=1;
especular[2]=1;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 1);
glutSolidOctahedron();
//Dodecahedro
glPopMatrix();
glPushMatrix();
glTranslated(-7, -6, 0);
ambiental[1]=1;
especular[2]=0;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 10);
glutSolidDodecahedron();
//Icosahedro
glPopMatrix();
glPushMatrix();
glTranslated(-3, -5.5, 0);
glScaled(2.2, 2.2, 2.2);
ambiental[1]=0;
especular[2]=0.5;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 10);
glutSolidIcosahedron();
//Toroide
glPopMatrix();
glPushMatrix();
glTranslated(2, -5.5, 0);
ambiental[0]=0.8;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 5);
glutWireTorus(1, 1.5, 10, 10);
//Tetera
glPopMatrix();
glPushMatrix();
glTranslated(7, -5.5, 0);
glRotated(-10, 0, 1, 1);
ambiental[0]=0;
ambiental[2]=1;
especular[1]=1;
especular[2]=1;
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, ambiental);
glMaterialfv(GL_FRONT, GL_SPECULAR, especular);
glMaterialf(GL_FRONT, GL_SHININESS, 10);
glutWireTeapot(1.5);
glutSwapBuffers();
}

No hay comentarios:

Publicar un comentario