#include <stdlib.h>
GLfloat ang = 1.0;
GLfloat ejex=0.5, ejey=0.5, escalar=1.0;
void reshape (int width,int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15,15,15,-15,15,-15)
glMatrixMode(GL_MODELVIEW);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glRotatef(ang, 2.0f, 0.0f, 0.0f);
glTranslatef(ejex,0.0f,0.0f);
glScalef(escalar, escalar, escalar);
//base
glColor3f(1,0,0);
glBegin(GL_POLYGON);
glVertex3f(0,0,4);
glVertex3f(0,6,4);
glVertex3f(4,6,0);
glVertex3f(4,0,4);
//glVertex3f(0,0,4);
glEnd();
//primer cara
glColor3f(0,1,0);
glBegin(GL_POLYGON);
glVertex3f(0,0,4);
glVertex3f(0,0,0);
glVertex3f(8,0,0);
glVertex3f(4,0,4);
glEnd();
//segunda cara
glColor3f(0,0,1);
glBegin(GL_POLYGON);
glVertex3f(0,6,4);
glVertex3f(0,10,0);
glVertex3f(8,10,0);
glVertex3f(4,6,0);
glEnd();
//tercer cara
glColor3f(1,0,1);
glBegin(GL_POLYGON);
glVertex3f(0,0,4);
glVertex3f(0,0,0);
glVertex3f(0,6,4);
glVertex3f(0,0,4);
glEnd();
//cuarta cara
glColor3f(1,1,0);
glBegin(GL_POLYGON);
glVertex3f(4,0,4);
glVertex3f(8,0,0);
glVertex3f(8,10,0);
glVertex3f(4,6,0);
glEnd();
glColor3f(1,0,0);
glBegin(GL_LINE_STRIP);
glVertex3f(0,5,3);
glVertex3f(0,4,3);
glVertex3f(3,5,0);
glVertex3f(3,4,0);
glEnd();
glColor3f(1,0,0);
glBegin(GL_LINE_STRIP);
glVertex3f(0,0,2);
glVertex3f(0,0,3);
glVertex3f(3,0,2);
glVertex3f(3,0,3);
glEnd();
glutSwapBuffers();
ang+=0.1f;
}
void piramide()
{
/* Idle callback, spin cube 2 degrees about selected axis */
ang += 2;
if( ang > 360 ) ang -= 360;
glutPostRedisplay();
}
void init()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0,0,0,0);
}
void idle()
{
display();
}
void ArrowKey(int key, int x, int y){
switch (key){
case GLUT_KEY_RIGHT:
if( ejex<8.0 ){ejex = ejex + 0.5;}//para moverse en la coordenada +x
if(ejex>0.1 && ejex<3){escalar = ejex;}
break;
case GLUT_KEY_LEFT:
if( ejex>-8.0 ){ejex = ejex - 0.5;}//para moverse en la coordenada -x
if(ejex>0.1 && ejex<3){escalar = ejex;}
break;
}
}
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;}
}
int main (int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_
glEnable(GL_DEPTH_TEST);
glutInitWindowPosition(50,50)
glutInitWindowSize(500,500);
glutCreateWindow("Hello");
glutIdleFunc(piramide);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutKeyboardFunc(keyboard);
glutSpecialFunc(ArrowKey);
glutMainLoop();
return 0;
}
No hay comentarios.:
Publicar un comentario