martes, 4 de septiembre de 2007

Práctica 2

1.- Cargue, compile y ejecute el código que escribió en el previo.

#include
void dibuja() {
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLE_STRIP);
glColor3f(0.1, 0.9, 0.1);
glVertex3f(0, 2.3, 0);
glColor3f(0.1, 0.9, 0.1);
glVertex3f(-1.6, 0, 1.6);
glColor3f(0.1, 0.2, 0.1);
glVertex3f(1.6, -1, 3);
glColor3f(0.1, 0.2, 0.1);
glVertex3f(-3, -1, -1.6);
glColor3f(0.1, 0.1, 0.1);
glVertex3f(0, 2.3, 0);
glColor3f(0.1, 0.1, 0.1);
glVertex3f(-1.6, 0, 1.6);
glEnd();
glFlush();
}
glClearColor(0, 0, 0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-2, 2, -1.5, 1.5, 1, 40);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0,
-4);
glRotatef(45, 20, 0, 0);
glRotatef(45, 0, 20, 0);
}

int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(480, 30);
glutInitWindowSize(300, 300);
glutCreateWindow(
"Tetraedro");
glutDisplayFunc(dibuja);
inicio();
glutMainLoop();
}











2.- Busque la referencia en línea a la API de GLUT y escriba programas que le permita ver:

-un cubo (glutSolidCube)
#include void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2, -2, 2, 1, 10);
glMatrixMode(GL_MODELVIEW);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.3,.9);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f);
glRotatef(90, 1.0f, 0.0f, 0.0f);
glRotatef(90, 0.0f, 1.0f, 0.0f);
glutSolidCube(1.5);
glFlush();
}
void init(){
glClearColor(0,0,0,0);}
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 20);
glutInitWindowSize(250, 250);
glutCreateWindow("Cubo");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0; }

-un cono (glutCore)
#include void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2, -2, 2, 1, 10);
glMatrixMode(GL_MODELVIEW);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.3,.9);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f);
glRotatef(220, 1.0f, 0.0f, 0.0f);
glRotatef(0, 0.0f, 1.0f, 0.0f);
glutSolidCone(1,2,50,10);
glFlush();}
void init(){
glClearColor(0,0,0,0);}
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 20);
glutInitWindowSize(250, 250);
glutCreateWindow("Cono");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0; }

-un toro (glutTorus)
#include void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2, -2, 2, 1, 10);
glMatrixMode(GL_MODELVIEW);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.3,.9);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.0f);
glRotatef(220, 1.0f, 0.0f, 0.0f);
glRotatef(0, 0.0f, 1.0f, 0.0f);
glutSolidTorus(0.3,1.5,15,15);
glFlush();
}
void init(){
glClearColor(0,0,0,0);
}
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 20);
glutInitWindowSize(250, 250);
glutCreateWindow("Torus");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}




3.- A cada uno de estos objetos aplíqueles una composición de transformaciones, insertando el siguiente código:
glRotate (30.0,1.0,0.0,0.0);
glTranslate(0.5,0.5,-0.5);
glScale(2.0,0.5,1.0);


#include

void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2, -2, 2, 1, 10);
glMatrixMode(GL_MODELVIEW);
}

void display(){
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.3,0.3,.9);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -2.5f);
glRotatef(120, 1.0f, 0.0f, 0.0f);
glRotatef(120, 0.0f, 1.0f, 0.0f);
glScalef(2,0.5,1);
glutSolidCube(1.5);
glFlush();
}

void init(){
glClearColor(0,0,0,0);
}

int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 20);
glutInitWindowSize(250, 250);
glutCreateWindow("Cubo");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();

return 0;
}



#include

void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2, -2, 2, 1, 10);
glMatrixMode(GL_MODELVIEW);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.3,.9);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -3.5f);
glRotatef(210, 1.0f, 0.0f, 0.0f);
glRotatef(210, 0.0f, 1.0f, 0.0f);
glScalef(1,0.5,0.5);
glutSolidCone(2,4,50,10);
glFlush();
}

void init(){
glClearColor(0,0,0,0);
}

int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 20);
glutInitWindowSize(250, 250);
glutCreateWindow("Cono");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();

return 0;


#include void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-2,2, -2, 2, 1, 10);
glMatrixMode(GL_MODELVIEW);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.3,0.3,.9);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -4.5f);
glRotatef(120, 1.0f, 0.0f, 0.0f);
glRotatef(120, 0.0f, 1.0f, 0.0f);
glScalef(1,0.5,0.5);
glutSolidTorus(0.3,1.5,20,20);
glFlush();
}
void init(){
glClearColor(0,0,0,0);
}
int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(80, 20);
glutInitWindowSize(250, 250);
glutCreateWindow("Torus");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}

No hay comentarios: