domingo, 9 de marzo de 2014

Figuras primitivas GLUT

En este código se muestran la figuras primitivas así como algunas funciones como glRotate (para girar la figura), glTranslate (cambiar de posición la figura) y glutWire y glutSolid que cambia la consistencia de las figuras

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glu.h>
#include <GL/gl.h>
#include <GL/glut.h>

#include <iostream>
#endif
using namespace std;


#include <stdlib.h>
void dibuja()
{
 


    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(-0.8,0.8,0.0);
    glRotatef(45,0,1,1);
    glutWireSphere(0.2,15,15);
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(-0.4,0.8,0.0);
    glRotatef(55,0,1,1);
    glutWireCone(0.2,0.2,15,15);
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.0,0.8,0.0);
    glRotatef(55,0,1,1);
    glutWireCube(0.2);
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.4,0.8,0.0);
    glScalef(0.1,0.1,0.1);
    glRotatef(55,0,1,1);
    glutWireDodecahedron();
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.8,0.8,0.0);
    glScalef(0.2,0.2,0.2);
    glRotatef(55,0,1,1);
    glutWireIcosahedron();
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(-0.8,0.4,0.0);
    glScalef(0.2,0.2,0.2);
    glRotatef(55,0,1,1);
    glutWireOctahedron();
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(-0.4,0.4,0.0);
    glutWireTeapot(0.15);
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.05,0.4,0.0);
    glScalef(0.2,0.2,0.2);
    glRotatef(55,0,1,1);
    glutWireTetrahedron();
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.4,0.4,0.0);
    glRotatef(55,0,1,1);
    glutWireTorus(0.1,0.1,15,15);
    glPopMatrix();
    glFlush();

    //SOLIDOS

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(-0.8,0.0,0.0);
    glRotatef(45,0,1,1);
    glutSolidSphere(0.2,15,15);
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(-0.4,0.0,0.0);
    glRotatef(55,0,1,1);
    glutSolidCone(0.2,0.2,15,15);
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.0,0.0,0.0);
    glRotatef(55,0,1,1);
    glutSolidCube(0.2);
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.4,0.0,0.0);
    glScalef(0.1,0.1,0.1);
    glRotatef(55,0,1,1);
    glutSolidDodecahedron();
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.8,0.0,0.0);
    glScalef(0.2,0.2,0.2);
    glRotatef(55,0,1,1);
    glutSolidIcosahedron();
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(-0.8,-0.4,0.0);
    glScalef(0.2,0.2,0.2);
    glRotatef(55,0,1,1);
    glutSolidOctahedron();
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(-0.4,-0.4,0.0);
    glutSolidTeapot(0.15);
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.05,-0.4,0.0);
    glScalef(0.2,0.2,0.2);
    glRotatef(55,0,1,1);
    glutSolidTetrahedron();
    glPopMatrix();
    glFlush();

    glColor3f(1.0,0.0,0.0);
    glPushMatrix();
    glTranslatef(0.4,-0.4,0.0);
    glRotatef(55,0,1,1);
    glutSolidTorus(0.1,0.1,15,15);
    glPopMatrix();
    glFlush();

}
int main()
{

    cerr << " main() \n";
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    glutInitWindowSize(550,550);
    glutCreateWindow("");
    glutDisplayFunc(dibuja);
    glutMainLoop();

}

No hay comentarios:

Publicar un comentario