#include <GLglut.h>
GLfloat anguloCuboY;
void drawCube(void)
{
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS); //cara frontal
glVertex3f( 0.0f, 0.0f,0.0f); //0
glVertex3f(100.0f, 0.0f,0.0f); //1
glVertex3f(100.0f,100.0f,0.0f); //2
glVertex3f( 0.0f,100.0f,0.0f); //3
glEnd();
glColor3f(0.0f, 1.0f, 0.0f);
glBegin(GL_QUADS); //cara trasera
glVertex3f( 0.0f,100.0f,-100.0f); //6
glVertex3f(100.0f,100.0f,-100.0f); //5
glVertex3f(100.0f, 0.0f,-100.0f); //4
glVertex3f( 0.0f, 0.0f,-100.0f); //7
glEnd();
glColor3f(0.0f, 0.0f, 1.0f);
glBegin(GL_QUADS); //cara lateral izq
glVertex3f(100.0f, 0.0f, 0.0f); //1
glVertex3f(100.0f, 0.0f,-100.0f); //4
glVertex3f(100.0f,100.0f,-100.0f); //5
glVertex3f(100.0f,100.0f, 0.0f); //2
glEnd();
glColor3f(1.0f, 1.0f, 0.0f);
glBegin(GL_QUADS); //cara lateral dcha
glVertex3f(0.0f,100.0f, 0.0f); //3
glVertex3f(0.0f,100.0f,-100.0f); //6
glVertex3f(0.0f, 0.0f,-100.0f); //7
glVertex3f(0.0f, 0.0f, 0.0f); //0
glEnd();
glColor3f(0.0f,1.0f, 1.0f);
glBegin(GL_QUADS); //cara arriba
glVertex3f(100.0f,100.0f,-100.0f); //5
glVertex3f( 0.0f,100.0f,-100.0f); //6
glVertex3f( 0.0f,100.0f, 0.0f); //3
glVertex3f(100.0f,100.0f, 0.0f); //2
glEnd();
glColor3f(1.0f, 0.0f, 1.0f);
glBegin(GL_QUADS); //cara abajo
glVertex3f( 0.0f,0.0f,-100.0f); //7
glVertex3f(100.0f,0.0f,-100.0f); //4
glVertex3f(100.0f,0.0f, 0.0f); //1
glVertex3f( 0.0f,0.0f, 0.0f); //0
glEnd();
}
void myinit(void)
{
/* attributes */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-150,150,-150,150,1,500.0);
glMatrixMode(GL_MODELVIEW);
}
void init()
{
glClearColor(0,0,0,0);
glEnable(GL_DEPTH_TEST);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-150.0f);
glRotatef(45,0.0f,0.0f,1.0f);
glRotatef(anguloCuboY, 1.0f,1.0f,0.0f);
drawCube();
glFlush();
anguloCuboY+=0.1f;
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(650, 650);
glutCreateWindow("Cubo 3D");
init();
glutDisplayFunc(display);
myinit();
glutIdleFunc(display);
glutMainLoop();
return 0;
}
No hay comentarios:
Publicar un comentario