Exercicio de Computação Gráfica Câmera e Rotação
Por: Lidieisa • 21/4/2018 • 1.373 Palavras (6 Páginas) • 381 Visualizações
...
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
// Faz a geraçao da textura na memória
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Width, Height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
fclose (fp_arquivo);
free (image);
return 1;
}
void init(void)
{
glShadeModel(GL_SMOOTH);
// habilita luz e transparencia
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_DEPTH_TEST);
glClearColor(0.0, 0.0, 0.0, 0.0);
// gera um objeto de textura, para o vetor e carrega com a imagem
glEnable ( GL_TEXTURE_2D );
glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
glGenTextures ( 1, texture_id );
glBindTexture ( GL_TEXTURE_2D, texture_id[0] );
LoadBMP ("wood.bmp");
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glColor3d(1.0, 0.0, 0.0);
glLoadIdentity();
// Seta a camera
gluLookAt( x, 1.0f, z,
x+lx, 1.0f, z+lz,
0.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glPushMatrix () ; //define a luz
GLfloat light_position[] = { ix, iy, iz, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glPopMatrix();
glPushMatrix();
//chao
GLfloat verde[] = {0, 1, 0, 1};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, verde);
glBegin(GL_QUADS);
glVertex3f(-5, 0, -5);
glVertex3f(5, 0, -5);
glVertex3f(5, 0, 5);
glVertex3f(-5, 0, 5);
glEnd();
glPopMatrix();
//paredes
glPushMatrix();
GLfloat azul[] = {0, 0, 1, 1};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, azul);
glBegin(GL_QUADS);
glVertex3f(-5, 0, -5);
glVertex3f(-5, 5, -5);
glVertex3f(5, 5, -5);
glVertex3f(5, 0, -5);
glEnd();
glPopMatrix();
glPushMatrix();
GLfloat azul2[] = {0, 0, 0.8, 1};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, azul2);
glBegin(GL_QUADS);
glVertex3f(5, 0, 5);
glVertex3f(5, 5, 5);
glVertex3f(-5, 5, 5);
glVertex3f(-5, 0, 5);
glEnd();
glPopMatrix();
glPushMatrix();
GLfloat azul3[] = {0, 0.3, 0.8, 1};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, azul3);
glBegin(GL_QUADS);
glPushMatrix();
glVertex3f(-5, 0, -5);
glVertex3f(-5, 5, -5);
glVertex3f(-5, 5, 5);
glVertex3f(-5, 0, 5);
glEnd();
glPopMatrix();
//mesa
GLfloat branco[] = {1, 1, 1, 1};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, branco);
glPushMatrix();
glTranslatef(0,0.35,0);
glRotatef(-90, 1, 0, 0);
gluCylinder(gluNewQuadric(), 0, 1, 0.05, 10, 1);
glPopMatrix();
glPushMatrix();
glRotatef(-90, 1, 0, 0);
gluCylinder(gluNewQuadric(), 0.2, 0.2, 0.73, 6, 3);
glPopMatrix();
//cilindro- capa do abajur
GLfloat capaabj[] = {1, 1, 0.6, 0.6};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, capaabj);
glPushMatrix();
...