#include "GL/glut.h" GLfloat z; void drawCasa() { glBegin( GL_POLYGON ); // poligono glVertex3f( 0, 0, 0 ); glVertex3f( 1, 0, 0 ); glVertex3f( 1, 1, 0 ); glVertex3f( 0.5, 1.5, 0 ); glVertex3f( 0, 1, 0 ); glEnd(); } void displayevent(void) { // limpa a cena (janela) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // verfica superficies visiveis glEnable( GL_DEPTH_TEST ); // inicializa a matriz de transformacao de coordenadas glLoadIdentity(); // traslada a cena no centro do espaço (Hortiz y Vert: 0,0) glTranslatef( -0.5, -0.5, z ); // construção de cena glColor3f(1,0,0); //Define se a cor vermelho (Vermelho, Verde, Azul) drawCasa(); // Figura original /* // Traslação glTranslatef( -1.5, 0, 0 ); // nova imagem glColor3f(0,1,0); drawCasa(); glTranslatef( 1.5, 0, 0 ); // voltamos a origem */ /* //Escalamento glTranslatef( 1.5, 0, 0 ); // nova imagem glScalef(2.f, 2.f, 2.f); glColor3f(0,0,1); drawCasa(); glTranslatef( -1.5, 0, 0 ); //voltamos a origem glScalef(.5f, .5f, .5f); // voltamos a escala original */ /* //Rotação glTranslatef( 2.5, -2, 0 ); // nova imagem glRotatef( 90, 0.f, 0.f, 1.f ); glColor3f(0,1,1); drawCasa(); */ // fornece o swap glutSwapBuffers(); } void specialkeyevent( int key, int Xx, int Yy ) { switch ( key ) { // zoom in e out pelo teclado case GLUT_KEY_UP: z += 0.1; break; case GLUT_KEY_DOWN: z -= 0.1; break; } glutPostRedisplay(); } void reshapeevent(GLsizei width, GLsizei height) { glViewport(0, 0, (GLsizei)width, (GLsizei)height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); } // reshape int main(int argc, char** argv) { // Inicializacao do GLUT glutInit( &argc, argv ); // inicializacao da janela glutInitWindowSize( 600, 600 ); glutInitWindowPosition( 100, 100 ); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA); glutCreateWindow( "" ); glutSetWindowTitle( "Transformacoes Opengl" ); // inicializacao de variaveis z = -10; // registro dos eventos glutReshapeFunc (reshapeevent); glutDisplayFunc( displayevent ); glutSpecialFunc( specialkeyevent ); // lazo de eventos glutMainLoop(); return 0; } // main